dsh-ustc-quota 1.1.21 → 1.1.23

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 +3 -4
  2. package/client.js +168 -59
  3. package/index.js +1 -1
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -107,10 +107,9 @@ key-c 8.7/30 29% 8.7/70 12% 11.1/100 11%
107
107
 
108
108
  ## 面板位置
109
109
 
110
- - 卡片默认在左侧边栏底部。点卡片标题栏的 `⇥` 可把它移到对话区右侧,点 `⇤` 移回左侧;选择会记住,重启后保持。
111
- - 右侧位置放在**对话列**的右上角,自上而下排列插件卡片;对话列变窄(例如打开右侧边栏)时卡片跟着移动,不会固定贴在窗口最右侧。
112
- - 只移动卡片位置,不改卡片内容与刷新/更新行为。
113
-
110
+ - 卡片默认在左侧边栏底部。**鼠标移到卡片上时,标题左边的品牌图标会变成方向图标**(`→` 移到右侧、`←` 移回左侧),点一下即可换边;移开鼠标图标复原。选择会记住,重启后保持。
111
+ - 右侧位置停在**对话列里、聊天内容与轮次导航条之间的空白**:左右各留 24px,宽度随空白自适应,不遮挡右侧原生按钮,也不侵入轮次导航条。上沿从「对话 / 轨迹 / 看板」选项卡下的分隔线以下开始,不会压住分隔线。拖动对话边界或开关任一侧边栏时,卡片跟着走。
112
+ - 换边不重新加载:两处卡片共用同一份已取到的数据,切换时直接显示,之后在后台刷新。
114
113
  ## 更新
115
114
 
116
115
  - 标题「USTC 词元额度」右侧显示灰色小字版本号;点击版本号可手动检查更新;
package/client.js CHANGED
@@ -11,14 +11,12 @@ 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.21';
14
+ const CLIENT_VERSION = '1.1.23';
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`;
18
18
  const HOST_VERSION_KEY = `${NS}:host-version-reload`;
19
19
  const POSITION_KEY = `${NS}:position`;
20
- const RIGHT_DOCK_WIDTH = 300;
21
- const RIGHT_DOCK_GAP = 12;
22
20
 
23
21
  function readDshVersion() {
24
22
  try {
@@ -383,6 +381,19 @@ window.__ModuleLoader__.load({
383
381
  letterSpacing: '-0.01em',
384
382
  whiteSpace: 'nowrap',
385
383
  },
384
+ brandButton: {
385
+ display: 'inline-flex',
386
+ alignItems: 'center',
387
+ justifyContent: 'center',
388
+ margin: 0,
389
+ padding: 0,
390
+ border: 0,
391
+ background: 'transparent',
392
+ color: 'var(--dsw-alias-label-primary)',
393
+ cursor: 'pointer',
394
+ lineHeight: 0,
395
+ flex: '0 0 auto',
396
+ },
386
397
  brandMark: {
387
398
  display: 'inline-flex',
388
399
  alignItems: 'center',
@@ -1013,9 +1024,12 @@ window.__ModuleLoader__.load({
1013
1024
  return provider;
1014
1025
  }
1015
1026
 
1016
- function TokenWorksMark() {
1017
- // Redrawn from the TokenWorks brand mark (five rounded tiles forming a T),
1018
- // as a 24-viewBox monochrome line icon so it inherits currentColor.
1027
+ // Resting state: the TokenWorks brand mark (five rounded tiles forming a T),
1028
+ // redrawn as a 24-viewBox monochrome line icon. Hovering the card swaps it for
1029
+ // the dock switch glyph so the header keeps a single 13 px seat.
1030
+ function TokenWorksMark(props) {
1031
+ const showSwitch = props && props.showSwitch === true;
1032
+ const targetRight = !props || props.target !== 'left';
1019
1033
  const tile = (x, y) => h('rect', {
1020
1034
  key: x + '-' + y,
1021
1035
  x,
@@ -1026,14 +1040,50 @@ window.__ModuleLoader__.load({
1026
1040
  stroke: 'currentColor',
1027
1041
  strokeWidth: 1.6,
1028
1042
  });
1043
+ const frame = (children) => h('svg', {
1044
+ width: 13,
1045
+ height: 13,
1046
+ viewBox: '0 0 24 24',
1047
+ fill: 'none',
1048
+ style: { display: 'block' },
1049
+ 'data-ustc-mark-glyph': showSwitch ? 'switch' : 'brand',
1050
+ }, children);
1051
+ // A layout glyph, not an arrow: a panel frame whose narrow band marks where
1052
+ // the card is about to sit. Reads as "dock to this side" at 13 px.
1053
+ const panelBand = targetRight ? 15.4 : 8.6;
1054
+ const pillX = targetRight ? 17.1 : 3.9;
1055
+ const switchGlyph = [
1056
+ h('rect', {
1057
+ key: 'frame',
1058
+ x: 2.6,
1059
+ y: 4.4,
1060
+ width: 18.8,
1061
+ height: 15.2,
1062
+ rx: 3,
1063
+ stroke: 'currentColor',
1064
+ strokeWidth: 1.5,
1065
+ }),
1066
+ h('path', {
1067
+ key: 'split',
1068
+ d: 'M' + panelBand + ' 4.4V19.6',
1069
+ stroke: 'currentColor',
1070
+ strokeWidth: 1.5,
1071
+ strokeLinecap: 'round',
1072
+ }),
1073
+ h('rect', {
1074
+ key: 'band',
1075
+ x: pillX,
1076
+ y: 9.4,
1077
+ width: 2.9,
1078
+ height: 5.2,
1079
+ rx: 1.45,
1080
+ fill: 'currentColor',
1081
+ }),
1082
+ ];
1029
1083
  return h('span', { style: STYLE.brandMark, 'aria-hidden': true, 'data-ustc-mark': '' },
1030
- h('svg', { width: 13, height: 13, viewBox: '0 0 24 24', fill: 'none', style: { display: 'block' } },
1031
- tile(2.25, 3.5),
1032
- tile(9.25, 3.5),
1033
- tile(16.25, 3.5),
1034
- tile(9.25, 10.5),
1035
- tile(9.25, 17.5)
1036
- )
1084
+ frame(showSwitch
1085
+ ? switchGlyph
1086
+ : [tile(2.25, 3.5), tile(9.25, 3.5), tile(16.25, 3.5), tile(9.25, 10.5), tile(9.25, 17.5)])
1037
1087
  );
1038
1088
  }
1039
1089
 
@@ -1065,91 +1115,136 @@ window.__ModuleLoader__.load({
1065
1115
  return React.useSyncExternalStore(subscribePanelPosition, readPanelPosition, readPanelPosition);
1066
1116
  }
1067
1117
 
1068
- // The sidebar seat renders the card only while the left position is chosen.
1118
+ // Both seats stay mounted so switching dock position keeps the fetched data:
1119
+ // the hidden seat only stops polling, it never unmounts.
1069
1120
  function LeftDock(props) {
1070
1121
  const position = usePanelPosition();
1071
- if (position !== 'left') return null;
1072
- return h(QuotaStrip, Object.assign({}, props, { placement: 'left' }));
1122
+ const active = position === 'left';
1123
+ // No wrapper element: DSH's footer layout normalisation rewrites display on
1124
+ // ancestors, which would unhide a wrapper we hid ourselves. The card stays
1125
+ // mounted (state preserved) and returns null while the other seat is active.
1126
+ return h(QuotaStrip, Object.assign({}, props, { placement: 'left', active, visible: active }));
1073
1127
  }
1074
1128
 
1075
1129
  // DSH exposes no plugin seat for the conversation's right column: 'rightbar'
1076
1130
  // is a single seat owned by the shipped right sidebar. The dock therefore
1077
- // measures the conversation column and pins itself to that column's right
1078
- // edge, so it follows the conversation when the sidebar opens or closes.
1131
+ // measures the conversation column and pins itself into the blank strip
1132
+ // between the chat content and the turn navigator, so it follows the
1133
+ // conversation when either side is dragged or toggled.
1134
+ const DOCK_GAP = 24;
1135
+ const DOCK_MIN_WIDTH = 220;
1136
+ const DOCK_MAX_WIDTH = 420;
1137
+
1138
+ function measureRightDock() {
1139
+ const holder = document.querySelector('[data-slot="main.conversation"]');
1140
+ const column = holder ? (holder.firstElementChild || holder) : null;
1141
+ if (!column) return null;
1142
+ const columnRect = column.getBoundingClientRect();
1143
+ if (columnRect.width < 240 || columnRect.height < 160) return null;
1144
+
1145
+ const flowHolder = document.querySelector('[data-slot="conversation.chat.flow"]');
1146
+ const flow = flowHolder ? (flowHolder.firstElementChild || flowHolder) : null;
1147
+ const flowRect = flow ? flow.getBoundingClientRect() : null;
1148
+
1149
+ // The turn navigator is a rail of per-turn buttons at the column's right edge.
1150
+ let navLeft = null;
1151
+ for (const button of document.querySelectorAll('button[aria-label]')) {
1152
+ const label = button.getAttribute('aria-label') || '';
1153
+ if (!/turnNavigation|轮次|跳转/i.test(label)) continue;
1154
+ const rect = button.getBoundingClientRect();
1155
+ if (rect.width > 0 && rect.height > 0) navLeft = navLeft === null ? rect.left : Math.min(navLeft, rect.left);
1156
+ }
1157
+ if (navLeft === null) navLeft = columnRect.right - 26;
1158
+
1159
+ let width = DOCK_MAX_WIDTH;
1160
+ if (flowRect && flowRect.width > 0 && flowRect.right < navLeft) {
1161
+ const available = navLeft - flowRect.right - DOCK_GAP * 2;
1162
+ width = Math.min(DOCK_MAX_WIDTH, Math.max(DOCK_MIN_WIDTH, Math.round(available)));
1163
+ }
1164
+ width = Math.max(DOCK_MIN_WIDTH, Math.min(width, Math.round(columnRect.width - DOCK_GAP * 2)));
1165
+
1166
+ // Vertical bound: the dock may never cross or touch the separator under the
1167
+ // conversation tab strip (对话 / 轨迹 / 看板 / Codex).
1168
+ let contentTop = Math.round(columnRect.top) + 16;
1169
+ const tabStrip = document.querySelector('[data-conversation-tabs]');
1170
+ if (tabStrip) {
1171
+ const row = tabStrip.parentElement || tabStrip;
1172
+ const rowRect = row.getBoundingClientRect();
1173
+ if (rowRect.height > 0 && rowRect.bottom > columnRect.top && rowRect.bottom < columnRect.bottom) {
1174
+ contentTop = Math.max(contentTop, Math.round(rowRect.bottom) + DOCK_GAP);
1175
+ }
1176
+ }
1177
+ const bottomEdge = Math.round(columnRect.bottom);
1178
+
1179
+ return {
1180
+ top: contentTop,
1181
+ right: Math.max(8, Math.round(window.innerWidth - navLeft) + DOCK_GAP),
1182
+ width,
1183
+ maxHeight: Math.max(120, bottomEdge - contentTop - DOCK_GAP / 2),
1184
+ };
1185
+ }
1186
+
1079
1187
  function RightDock(props) {
1080
1188
  const position = usePanelPosition();
1189
+ const active = position === 'right';
1081
1190
  const [box, setBox] = React.useState(null);
1082
1191
  React.useEffect(() => {
1083
- if (position !== 'right') {
1084
- setBox(null);
1085
- return undefined;
1086
- }
1087
1192
  let frame = 0;
1088
1193
  let observer = null;
1089
1194
  let observed = null;
1090
1195
  const measure = () => {
1091
1196
  frame = 0;
1092
- // The slot wrapper renders with display: contents, so it has no box of
1093
- // its own; the column is its first element child.
1094
1197
  const holder = document.querySelector('[data-slot="main.conversation"]');
1095
1198
  const column = holder ? (holder.firstElementChild || holder) : null;
1096
- if (!column) {
1097
- setBox(null);
1098
- return;
1099
- }
1100
- if (observed !== column && typeof ResizeObserver === 'function') {
1199
+ if (column && column !== observed && typeof ResizeObserver === 'function') {
1101
1200
  if (observer) observer.disconnect();
1102
1201
  observed = column;
1103
1202
  observer = new ResizeObserver(schedule);
1104
1203
  observer.observe(column);
1105
1204
  }
1106
- const rect = column.getBoundingClientRect();
1107
- if (rect.width < 200 || rect.height < 120) {
1108
- setBox(null);
1109
- return;
1110
- }
1111
- setBox({
1112
- top: Math.max(8, Math.round(rect.top) + RIGHT_DOCK_GAP),
1113
- right: Math.max(8, Math.round(window.innerWidth - rect.right) + RIGHT_DOCK_GAP),
1114
- maxHeight: Math.max(160, Math.round(rect.height) - RIGHT_DOCK_GAP * 2),
1115
- });
1205
+ setBox(measureRightDock());
1116
1206
  };
1117
1207
  function schedule() {
1118
1208
  if (!frame) frame = window.requestAnimationFrame(measure);
1119
1209
  }
1120
1210
  measure();
1121
- const retry = window.setInterval(measure, 2000);
1211
+ const timer = window.setInterval(measure, 2000);
1122
1212
  window.addEventListener('resize', schedule);
1123
1213
  return () => {
1124
1214
  window.removeEventListener('resize', schedule);
1125
- window.clearInterval(retry);
1215
+ window.clearInterval(timer);
1126
1216
  if (observer) observer.disconnect();
1127
1217
  if (frame) window.cancelAnimationFrame(frame);
1128
1218
  };
1129
- }, [position]);
1130
- if (position !== 'right' || !box) return null;
1219
+ }, []);
1220
+ const shown = active && box !== null;
1131
1221
  return h('div', {
1132
1222
  'data-ustc-quota-dock': 'right',
1133
1223
  style: {
1134
1224
  position: 'fixed',
1135
- top: box.top,
1136
- right: box.right,
1137
- width: RIGHT_DOCK_WIDTH,
1138
- maxHeight: box.maxHeight,
1225
+ top: box ? box.top : 0,
1226
+ right: box ? box.right : 0,
1227
+ width: box ? box.width : DOCK_MAX_WIDTH,
1228
+ maxHeight: box ? box.maxHeight : 0,
1139
1229
  overflowY: 'auto',
1140
- display: 'flex',
1230
+ display: shown ? 'flex' : 'none',
1141
1231
  flexDirection: 'column',
1142
1232
  gap: 6,
1143
1233
  pointerEvents: 'auto',
1144
1234
  zIndex: 5,
1145
1235
  },
1146
- }, h(QuotaStrip, Object.assign({}, props, { placement: 'right', wide: true })));
1236
+ }, h(QuotaStrip, Object.assign({}, props, { placement: 'right', wide: true, active, visible: active })));
1147
1237
  }
1148
1238
 
1149
1239
  function QuotaStrip(props) {
1150
1240
  const t = typeof props.t === 'function' ? props.t : fallbackT;
1151
1241
  const placement = props.placement === 'right' ? 'right' : 'left';
1152
1242
  const position = usePanelPosition();
1243
+ const active = props.active !== false;
1244
+ const [cardHovered, setCardHovered] = React.useState(false);
1245
+ const [markHovered, setMarkHovered] = React.useState(false);
1246
+ const activeRef = React.useRef(active);
1247
+ activeRef.current = active;
1153
1248
  const [snapshot, setSnapshot] = React.useState(null);
1154
1249
  const [error, setError] = React.useState(null);
1155
1250
  const [loading, setLoading] = React.useState(true);
@@ -1290,6 +1385,12 @@ window.__ModuleLoader__.load({
1290
1385
  }
1291
1386
 
1292
1387
  async function run() {
1388
+ if (!activeRef.current) {
1389
+ // The card is mounted in the other seat right now: keep the last data,
1390
+ // skip the request, and try again on the next tick.
1391
+ schedule(15000);
1392
+ return;
1393
+ }
1293
1394
  const body = await load(false);
1294
1395
  if (disposed) return;
1295
1396
  schedule(body && Number.isFinite(body.pollAfterMs) ? body.pollAfterMs : 15000);
@@ -1331,7 +1432,7 @@ window.__ModuleLoader__.load({
1331
1432
  if (!root) return undefined;
1332
1433
  // The right dock is not inside DSH's footer row; rewriting ancestors there
1333
1434
  // would fight the dock container instead of the sidebar layout.
1334
- if (placement === 'right') return undefined;
1435
+ if (placement === 'right' || props.visible === false) return undefined;
1335
1436
  return installFooterLayout(root);
1336
1437
  }, [props.wide, placement]);
1337
1438
 
@@ -1342,6 +1443,8 @@ window.__ModuleLoader__.load({
1342
1443
  const tokenworksNotReady = warnings.includes('tokenworks-not-ready');
1343
1444
 
1344
1445
  if (props.wide === false) return null;
1446
+ // Hidden seat: keep the component (and its data) mounted, render no DOM.
1447
+ if (props.visible === false) return null;
1345
1448
 
1346
1449
  function handleVersionClick() {
1347
1450
  if (updateInfo && updateInfo.updateAvailable) {
@@ -1666,7 +1769,18 @@ window.__ModuleLoader__.load({
1666
1769
  ? t('updateChecking')
1667
1770
  : t('versionCheck');
1668
1771
  const header = h('div', { style: STYLE.header },
1669
- h(TokenWorksMark),
1772
+ h('button', {
1773
+ type: 'button',
1774
+ 'data-ustc-position-toggle': '',
1775
+ 'aria-label': position === 'right' ? t('moveToLeft') : t('moveToRight'),
1776
+ title: position === 'right' ? t('moveToLeft') : t('moveToRight'),
1777
+ onClick: () => { writePanelPosition(position === 'right' ? 'left' : 'right'); },
1778
+ onMouseEnter: () => { setMarkHovered(true); },
1779
+ onMouseLeave: () => { setMarkHovered(false); },
1780
+ onFocus: () => { setMarkHovered(true); },
1781
+ onBlur: () => { setMarkHovered(false); },
1782
+ style: STYLE.brandButton,
1783
+ }, h(TokenWorksMark, { showSwitch: markHovered || cardHovered, target: position === 'right' ? 'left' : 'right' })),
1670
1784
  h('span', { style: STYLE.title, 'data-ustc-title': '' }, t('title')),
1671
1785
  h('button', {
1672
1786
  type: 'button',
@@ -1687,14 +1801,7 @@ window.__ModuleLoader__.load({
1687
1801
  : null,
1688
1802
  error && snapshot ? h('span', { style: STYLE.warn, title: error }, '!') : null,
1689
1803
  h('span', { style: STYLE.meta }, updated ? `${t('updatedLabel')} ${updated}` : ''),
1690
- h('button', {
1691
- type: 'button',
1692
- 'data-ustc-position-toggle': '',
1693
- 'aria-label': position === 'right' ? t('moveToLeft') : t('moveToRight'),
1694
- title: position === 'right' ? t('moveToLeft') : t('moveToRight'),
1695
- onClick: () => { writePanelPosition(position === 'right' ? 'left' : 'right'); },
1696
- style: STYLE.refresh,
1697
- }, position === 'right' ? '⇤' : '⇥'),
1804
+
1698
1805
  h('button', {
1699
1806
  type: 'button',
1700
1807
  'aria-label': t('refresh'),
@@ -1836,6 +1943,8 @@ window.__ModuleLoader__.load({
1836
1943
  role: 'group',
1837
1944
  'aria-label': t('title'),
1838
1945
  'data-ustc-quota-root': '',
1946
+ onMouseEnter: () => { setCardHovered(true); },
1947
+ onMouseLeave: () => { setCardHovered(false); setMarkHovered(false); },
1839
1948
  },
1840
1949
  header,
1841
1950
  restartBanner,
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.21';
25
+ const PLUGIN_VERSION = '1.1.23';
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.21",
3
+ "version": "1.1.23",
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).",