papersearch 0.4.8 → 0.4.10
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.en.md +50 -62
- package/README.md +50 -62
- package/assets/overview.en.png +0 -0
- package/assets/overview.png +0 -0
- package/assets/progress-capsule.en.png +0 -0
- package/assets/progress-capsule.png +0 -0
- package/carsi/README.md +5 -6
- package/carsi/paper_search_carsi/adapters/elsevier/__init__.py +1 -1
- package/carsi/paper_search_carsi/adapters/ieee/__init__.py +1 -1
- package/carsi/paper_search_carsi/adapters/jama/__init__.py +3 -1
- package/carsi/paper_search_carsi/adapters/karger/__init__.py +2 -1
- package/carsi/paper_search_carsi/adapters/lww/ovid.py +2 -2
- package/carsi/paper_search_carsi/adapters/oup/__init__.py +3 -4
- package/carsi/paper_search_carsi/adapters/world_scientific/__init__.py +5 -4
- package/carsi/paper_search_carsi/assets/capsule.html +199 -24
- package/carsi/paper_search_carsi/browser/backend.py +270 -227
- package/carsi/paper_search_carsi/browser/batch_session.py +42 -0
- package/carsi/paper_search_carsi/browser/challenge_interaction.py +79 -43
- package/carsi/paper_search_carsi/browser/cookies.py +8 -8
- package/carsi/paper_search_carsi/browser/driver.py +29 -0
- package/carsi/paper_search_carsi/browser/engine.py +17 -23
- package/carsi/paper_search_carsi/browser/foreground.py +21 -15
- package/carsi/paper_search_carsi/browser/login.py +12 -18
- package/carsi/paper_search_carsi/browser/preview.py +31 -12
- package/carsi/paper_search_carsi/browser/profiles.py +16 -23
- package/carsi/paper_search_carsi/browser/watchdog.py +61 -55
- package/carsi/paper_search_carsi/capsule_placement.py +266 -0
- package/carsi/paper_search_carsi/cli.py +22 -7
- package/carsi/paper_search_carsi/cold_start.py +65 -51
- package/carsi/paper_search_carsi/config.py +6 -4
- package/carsi/paper_search_carsi/engine/batch.py +9 -5
- package/carsi/paper_search_carsi/engine/batch_access.py +2 -4
- package/carsi/paper_search_carsi/engine/batch_capture.py +56 -20
- package/carsi/paper_search_carsi/engine/batch_common.py +56 -16
- package/carsi/paper_search_carsi/engine/batch_diagnostics.py +4 -2
- package/carsi/paper_search_carsi/engine/batch_institution.py +146 -17
- package/carsi/paper_search_carsi/engine/batch_login.py +79 -26
- package/carsi/paper_search_carsi/engine/batch_user.py +1 -1
- package/carsi/paper_search_carsi/engine/batch_waits.py +92 -37
- package/carsi/paper_search_carsi/engine/bridge.py +23 -13
- package/carsi/paper_search_carsi/engine/login_wait.py +1 -1
- package/carsi/paper_search_carsi/engine/page_activity.py +15 -15
- package/carsi/paper_search_carsi/mcp_progress.py +13 -5
- package/carsi/paper_search_carsi/network.py +1 -1
- package/carsi/paper_search_carsi/progress_capsule.py +233 -93
- package/carsi/paper_search_carsi/progress_reporter.py +88 -7
- package/carsi/paper_search_carsi/progress_view.py +61 -0
- package/carsi/paper_search_carsi/server.py +47 -10
- package/carsi/paper_search_carsi/session_broker.py +1 -1
- package/carsi/paper_search_carsi/user_settings.py +1 -1
- package/carsi/pyproject.toml +7 -7
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js +6 -0
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js.map +1 -1
- package/dist/capabilities/pdf-discovery/batch.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/batch.js +15 -5
- package/dist/capabilities/pdf-discovery/batch.js.map +1 -1
- package/dist/capabilities/pdf-discovery/batchSummary.d.ts +22 -0
- package/dist/capabilities/pdf-discovery/batchSummary.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/batchSummary.js +131 -0
- package/dist/capabilities/pdf-discovery/batchSummary.js.map +1 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.d.ts +1 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js +52 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.d.ts +8 -4
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js +89 -30
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.d.ts +4 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.js +10 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiReadiness.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.d.ts +2 -2
- package/dist/capabilities/pdf-discovery/carsi/index.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.js +1 -1
- package/dist/capabilities/pdf-discovery/carsi/index.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/types.d.ts +36 -0
- package/dist/capabilities/pdf-discovery/carsi/types.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/handler.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/handler.js +11 -6
- package/dist/capabilities/pdf-discovery/handler.js.map +1 -1
- package/dist/capabilities/pdf-discovery/types.d.ts +3 -0
- package/dist/capabilities/pdf-discovery/types.d.ts.map +1 -1
- package/dist/cli.js +13 -9
- package/dist/cli.js.map +1 -1
- package/dist/management/carsi/installer.d.ts +26 -14
- package/dist/management/carsi/installer.d.ts.map +1 -1
- package/dist/management/carsi/installer.js +113 -69
- package/dist/management/carsi/installer.js.map +1 -1
- package/dist/management/carsi/runtime.d.ts +12 -1
- package/dist/management/carsi/runtime.d.ts.map +1 -1
- package/dist/management/carsi/runtime.js +30 -1
- package/dist/management/carsi/runtime.js.map +1 -1
- package/package.json +1 -1
- package/skills/paper-search/SKILL.md +4 -4
- package/skills/paper-search/references/browser-download.md +3 -3
- package/skills/paper-search/references/carsi-setup.md +7 -6
- package/skills/paper-search/references/cli-contract.md +4 -4
- package/skills/paper-search/references/management-layer.md +2 -2
- package/carsi/paper_search_carsi/assets/quiet-browser/api.js +0 -142
- package/carsi/paper_search_carsi/assets/quiet-browser/manifest.json +0 -24
- package/carsi/paper_search_carsi/assets/quiet-browser/schema.json +0 -1
- package/carsi/paper_search_carsi/browser/background.py +0 -68
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
(``platforms/atypon``): its pages carry Literatum's markers and cookies
|
|
3
3
|
(2026-11-03; no public announcement found).
|
|
4
4
|
|
|
5
|
-
Its
|
|
6
|
-
|
|
7
|
-
address without it is a redirect that stalled.
|
|
5
|
+
Its chooser at ``/action/ssostart`` shows either the institution search or
|
|
6
|
+
lists for the federation and the institution.
|
|
8
7
|
"""
|
|
9
8
|
from __future__ import annotations
|
|
10
9
|
|
|
@@ -22,6 +21,8 @@ class WorldScientificAdapter(AtyponAdapter):
|
|
|
22
21
|
def chooser_block_reason(self, page: Any, url: str, text: str) -> str | None:
|
|
23
22
|
if "worldscientific.com/action/ssostart" not in url:
|
|
24
23
|
return None
|
|
25
|
-
if "find your institution"
|
|
24
|
+
if any(label in text for label in ("find your institution", "type the name of your institution",
|
|
25
|
+
"select your federation", "select your institution",
|
|
26
|
+
"china cernet federation (carsi)")):
|
|
26
27
|
return ""
|
|
27
28
|
return "sso_redirect_stalled"
|
|
@@ -40,18 +40,28 @@ body:not(.mac) #root { border-radius: 8px; border: none; }
|
|
|
40
40
|
box-shadow: inset 0 0 0 2px var(--warn-dot), inset 0 0 16px rgba(217, 119, 6, 0.2);
|
|
41
41
|
opacity: 0.2; animation: breathe 3.6s ease-in-out infinite;
|
|
42
42
|
}
|
|
43
|
-
.surface { position: relative; z-index: 1; transform-origin:
|
|
43
|
+
.surface { position: relative; z-index: 1; transform-origin: var(--origin-x, right) var(--origin-y, top); }
|
|
44
|
+
body.grow-right { --origin-x: left; }
|
|
45
|
+
body.grow-left { --origin-x: right; }
|
|
46
|
+
body.grow-down { --origin-y: top; }
|
|
47
|
+
body.grow-up { --origin-y: bottom; }
|
|
48
|
+
#root.animating > .surface { position: absolute; top: 0; left: 0; }
|
|
49
|
+
body.grow-left #root.animating > .surface { left: auto; right: 0; }
|
|
50
|
+
body.grow-up #root.animating > .surface { top: auto; bottom: 0; }
|
|
51
|
+
#root.card > .surface { overflow-y: auto; max-height: var(--content-max-height, none); }
|
|
44
52
|
.fade .surface { animation: fade .22s ease-out; }
|
|
45
53
|
.folder-setting { margin: 12px 0; }
|
|
46
54
|
.folder-setting .folder-row { display:flex; gap:8px; margin-top:6px; }
|
|
47
55
|
.folder-setting input { width:0; min-width:0; flex:1; text-align:left; }
|
|
48
56
|
.folder-setting .hint { margin-top:5px; font-size:11px; color:var(--dim); }
|
|
49
57
|
@media (prefers-reduced-motion: reduce) { .fade .surface, #root.warn::after { animation:none; } }
|
|
50
|
-
@keyframes fade { from { opacity: 0;
|
|
58
|
+
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
|
|
51
59
|
@keyframes breathe { 0%, 100% { opacity: 0.2; } 50% { opacity: 0.85; } }
|
|
52
60
|
|
|
53
61
|
.attention-target { appearance: none; box-sizing: content-box; padding: 0; border: none; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
|
|
54
62
|
.pill-prompt { display: inline-flex; align-items: center; gap: 8px; }
|
|
63
|
+
.attention-countdown { font-variant-numeric: tabular-nums; }
|
|
64
|
+
.attention-countdown:empty { display: none; }
|
|
55
65
|
.attention-target:focus-visible { outline: 2px solid var(--warn-dot); outline-offset: -2px; border-radius: 8px; }
|
|
56
66
|
.pillrow { display: flex; align-items: center; gap: 8px; padding: 5px 14px 5px 6px; white-space: nowrap; height: 28px; }
|
|
57
67
|
.pillrow.icon-first { padding-left: 12px; }
|
|
@@ -128,6 +138,32 @@ svg.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-widt
|
|
|
128
138
|
.attention-head { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; color: var(--fg); }
|
|
129
139
|
.attention-head b { flex: 1; font-size: 12px; }
|
|
130
140
|
#root.card.warn { background: var(--bg); }
|
|
141
|
+
|
|
142
|
+
/* The finished card: totals, failures by reason, what was saved. No text wraps. */
|
|
143
|
+
.done-stats { margin-top: 12px; }
|
|
144
|
+
.sec { margin-top: 14px; }
|
|
145
|
+
.sec-h { display: flex; align-items: baseline; gap: 6px; font-size: 12px; color: var(--dim); margin-bottom: 4px; }
|
|
146
|
+
.sec-h b { color: var(--fg); font-weight: 600; font-size: 13px; }
|
|
147
|
+
.saved-line { font-size: 12px; color: var(--dim); line-height: 1.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
148
|
+
.grp { border-top: 0.5px solid var(--line); padding: 8px 0; }
|
|
149
|
+
.grp:last-child { border-bottom: 0.5px solid var(--line); }
|
|
150
|
+
.grp .row { display: flex; align-items: center; gap: 6px; width: 100%; padding: 0; border: none; background: none;
|
|
151
|
+
font: inherit; color: inherit; text-align: left; white-space: nowrap; cursor: pointer; }
|
|
152
|
+
.grp .row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
|
|
153
|
+
.grp .row .reason { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
154
|
+
.grp .row .n { font-weight: 600; }
|
|
155
|
+
.grp .row svg.i { width: 14px; height: 14px; color: var(--faint); }
|
|
156
|
+
.grp .m { font-size: 12px; color: var(--faint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
157
|
+
.paper-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 196px; overflow-y: auto; }
|
|
158
|
+
.paper-list.scroll { -webkit-mask-image: linear-gradient(to bottom, #000 80%, transparent); mask-image: linear-gradient(to bottom, #000 80%, transparent); }
|
|
159
|
+
.paper-list li { font-size: 12px; padding: 3px 0; }
|
|
160
|
+
.paper-list .t, .paper-list .w { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
161
|
+
.paper-list .w, .paper-list .more { color: var(--faint); }
|
|
162
|
+
.tag { display: inline-block; font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 5px; flex: none; }
|
|
163
|
+
.tag.no_access, .tag.other { background: var(--hover); color: var(--fg); }
|
|
164
|
+
.tag.user_or_external { background: var(--warn-bg); color: var(--warn); }
|
|
165
|
+
.tag.unsupported { background: rgba(37, 99, 235, 0.12); color: var(--accent); }
|
|
166
|
+
.tag.unexplained { background: rgba(220, 38, 38, 0.12); color: var(--bad); }
|
|
131
167
|
</style>
|
|
132
168
|
</head>
|
|
133
169
|
<body>
|
|
@@ -147,6 +183,7 @@ const ICONS = {
|
|
|
147
183
|
dots: '<circle cx="6" cy="12" r="1"/><circle cx="12" cy="12" r="1"/><circle cx="18" cy="12" r="1"/>',
|
|
148
184
|
left: '<path d="M15 6l-6 6 6 6"/>',
|
|
149
185
|
right: '<path d="M9 6l6 6-6 6"/>',
|
|
186
|
+
down: '<path d="M6 9l6 6 6-6"/>',
|
|
150
187
|
gear: gearPath(),
|
|
151
188
|
};
|
|
152
189
|
function gearPath() {
|
|
@@ -185,7 +222,7 @@ function pill() {
|
|
|
185
222
|
const a = v.attention;
|
|
186
223
|
return '<div class="pillrow icon-first capsule-drag-region">' + icon(a.login ? "lock" : "shield")
|
|
187
224
|
+ '<button type="button" class="pill-prompt attention-target" data-act="show_browser" title="点击切到下载浏览器" aria-label="打开下载浏览器">'
|
|
188
|
-
+
|
|
225
|
+
+ '<b>' + esc(a.short) + '</b><span class="attention-countdown"></span></button></div>';
|
|
189
226
|
}
|
|
190
227
|
if (v.mode === "done") {
|
|
191
228
|
// "完成 38/40 2 篇失败": papers saved out of all; a check unless nothing was saved.
|
|
@@ -267,12 +304,10 @@ function runningCard() {
|
|
|
267
304
|
function attentionCard() {
|
|
268
305
|
const a = V.attention;
|
|
269
306
|
const title = a.short;
|
|
270
|
-
const detail = [a.message, a.remaining ? "剩 " + a.remaining : "",
|
|
271
|
-
a.more ? "另有 " + a.more + " 项" : ""].filter(Boolean).join(" · ");
|
|
272
307
|
let html = '<div class="card-body"><div class="attention-head capsule-drag-region"><b>PaperSearch</b>'
|
|
273
308
|
+ '<button class="iconbtn" data-act="minimize" aria-label="最小化">' + icon("minimize") + '</button>'
|
|
274
309
|
+ '<button class="iconbtn" data-act="close" aria-label="关闭">' + icon("close") + '</button></div>'
|
|
275
|
-
+ '<button type="button" class="prompt attention-target" data-act="show_browser"
|
|
310
|
+
+ '<button type="button" class="prompt attention-target" data-act="show_browser" aria-label="打开下载浏览器">' + icon(a.login ? "lock" : "alert")
|
|
276
311
|
+ '<div class="attention-copy"><div class="t">' + esc(title) + '</div><div class="s">点击打开浏览器,查看并继续</div></div><span class="attention-arrow" aria-hidden="true">›</span></button>';
|
|
277
312
|
if (panel === "confirm") return html + actionsBlock() + "</div>";
|
|
278
313
|
html += '<div class="actions"><button class="iconbtn" data-act="settings" aria-label="设置">' + icon("gear")
|
|
@@ -284,12 +319,45 @@ function attentionCard() {
|
|
|
284
319
|
return html + "</div></div>";
|
|
285
320
|
}
|
|
286
321
|
|
|
322
|
+
const CLASS_TAGS = { no_access: "没权限", user_or_external: "外部原因", unsupported: "暂不支持", unexplained: "原因不明", other: "其他" };
|
|
323
|
+
let openGroups = null, groupsRun = ""; // null: each reason row as the view opens it
|
|
324
|
+
function groupOpen(i) {
|
|
325
|
+
if (groupsRun !== V.run_id) { openGroups = null; groupsRun = V.run_id; }
|
|
326
|
+
return openGroups ? openGroups.has(i) : !!V.summary.groups[i].open;
|
|
327
|
+
}
|
|
328
|
+
function toggleGroup(i) {
|
|
329
|
+
const opened = !groupOpen(i);
|
|
330
|
+
openGroups = new Set(opened ? [i] : []); // one reason open at a time
|
|
331
|
+
render(true);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function reasonRow(g, i) {
|
|
335
|
+
const opened = groupOpen(i);
|
|
336
|
+
let html = '<div class="grp"><button type="button" class="row" data-act="group" data-group="' + i + '" aria-expanded="' + opened + '">'
|
|
337
|
+
+ '<span class="tag ' + esc(g.cls) + '">' + esc(CLASS_TAGS[g.cls] || "") + '</span><span class="reason">' + esc(g.reason) + "</span>"
|
|
338
|
+
+ '<span class="n">' + g.count + " 篇</span>" + icon(opened ? "down" : "right") + "</button>";
|
|
339
|
+
if (!opened) return html + (g.where ? '<div class="m">' + esc(g.where) + "</div>" : "") + "</div>";
|
|
340
|
+
return html + '<ul class="paper-list' + (g.papers.length > 5 ? " scroll" : "") + '">'
|
|
341
|
+
+ g.papers.map((p) => '<li><div class="t">' + esc(p.title) + "</div>" + (p.where ? '<div class="w">' + esc(p.where) + "</div>" : "") + "</li>").join("")
|
|
342
|
+
+ (g.more ? '<li class="more">另有 ' + g.more + " 篇未列出</li>" : "") + "</ul></div>";
|
|
343
|
+
}
|
|
344
|
+
|
|
287
345
|
function doneCard() {
|
|
288
|
-
const v = V;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
+ (v.
|
|
292
|
-
+
|
|
346
|
+
const v = V, s = v.summary;
|
|
347
|
+
let html = '<div class="card-body">' + header(v.headline, v.total ? "共 " + v.total + " 篇" : "", true)
|
|
348
|
+
+ '<div class="stats done-stats"><div><b style="color:var(--ok)">' + v.ok + "</b><span>成功</span></div>"
|
|
349
|
+
+ '<div><b' + (v.bad ? ' style="color:var(--bad)"' : "") + ">" + v.bad + "</b><span>失败</span></div>"
|
|
350
|
+
+ "<div><b>" + esc(v.elapsed || "—") + "</b><span>用时</span></div></div>";
|
|
351
|
+
if (s && s.groups.length) {
|
|
352
|
+
html += '<div class="sec"><div class="sec-h"><b>未完成 ' + v.bad + " 篇</b><span>按原因</span></div>"
|
|
353
|
+
+ s.groups.map(reasonRow).join("") + "</div>";
|
|
354
|
+
}
|
|
355
|
+
if (s && v.ok) {
|
|
356
|
+
html += '<div class="sec"><div class="sec-h"><b>已完成 ' + v.ok + " 篇</b></div>"
|
|
357
|
+
+ s.saved.map((line) => '<div class="saved-line">' + esc(line) + "</div>").join("") + "</div>";
|
|
358
|
+
}
|
|
359
|
+
if (v.completion_detail) html += '<div class="line">' + esc(v.completion_detail) + "</div>";
|
|
360
|
+
return html + (v.folder ? '<div class="actions"><button class="btn link" data-act="folder">' + icon("folder") + "打开文件夹</button></div>" : "")
|
|
293
361
|
+ "</div>";
|
|
294
362
|
}
|
|
295
363
|
|
|
@@ -321,6 +389,19 @@ function settingsCard() {
|
|
|
321
389
|
|
|
322
390
|
let lastCls = "", hovering = false, closing = false, dragging = false, endingDrag = false;
|
|
323
391
|
let dragReady = Promise.resolve();
|
|
392
|
+
let attentionPointer = null;
|
|
393
|
+
let renderedAttention = null;
|
|
394
|
+
|
|
395
|
+
function updateAttentionCountdown() {
|
|
396
|
+
const a = V.attention;
|
|
397
|
+
const card = root.querySelector(".prompt.attention-target");
|
|
398
|
+
if (card) card.title = [a.message, a.remaining ? "剩 " + a.remaining : "",
|
|
399
|
+
a.more ? "另有 " + a.more + " 项" : ""].filter(Boolean).join(" · ");
|
|
400
|
+
const countdown = root.querySelector(".attention-countdown");
|
|
401
|
+
if (!countdown || countdown.textContent === (a.remaining || "")) return false;
|
|
402
|
+
countdown.textContent = a.remaining || "";
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
324
405
|
|
|
325
406
|
function render(force) {
|
|
326
407
|
if (closing || dragging) return;
|
|
@@ -333,24 +414,64 @@ function render(force) {
|
|
|
333
414
|
else if (V.mode === "done") html = doneCard();
|
|
334
415
|
else html = idleCard();
|
|
335
416
|
const cls = shape + (V.mode === "attention" && panel !== "settings" ? " warn" : "");
|
|
336
|
-
|
|
417
|
+
const attention = V.mode === "attention" && panel !== "settings";
|
|
418
|
+
const sameTask = !attention || (renderedAttention?.current === V.current
|
|
419
|
+
&& renderedAttention?.run_id === V.run_id);
|
|
420
|
+
const unchanged = !force && sameTask && html === lastHtml && cls === lastCls;
|
|
421
|
+
// Keep the real button (and its pointer/focus target) through countdown ticks.
|
|
422
|
+
if (unchanged && (!attention || !updateAttentionCountdown())) return;
|
|
337
423
|
const previous = root.getBoundingClientRect();
|
|
338
424
|
root.style.width = ""; root.style.height = "";
|
|
339
|
-
root.
|
|
340
|
-
|
|
425
|
+
root.style.removeProperty("--content-max-height");
|
|
426
|
+
if (!unchanged) {
|
|
427
|
+
root.className = cls + " capsule-drag-region" + (cls !== lastCls ? " fade" : "");
|
|
428
|
+
root.innerHTML = '<div class="surface">' + html + "</div>";
|
|
429
|
+
if (attention) updateAttentionCountdown();
|
|
430
|
+
renderedAttention = attention ? V : null;
|
|
431
|
+
}
|
|
341
432
|
lastHtml = html;
|
|
342
433
|
lastCls = cls;
|
|
343
434
|
fit(previous);
|
|
344
435
|
}
|
|
345
436
|
|
|
346
|
-
let fitGeneration = 0;
|
|
347
|
-
|
|
437
|
+
let fitGeneration = 0, layoutQueue = Promise.resolve();
|
|
438
|
+
let settledGeneration = 0, settledSize = null, settledExpanded = null;
|
|
439
|
+
function fit(previous) {
|
|
348
440
|
const generation = ++fitGeneration;
|
|
349
441
|
const pad = document.body.classList.contains("mac") ? 20 : 0;
|
|
350
442
|
const target = root.getBoundingClientRect();
|
|
351
443
|
const to = [Math.ceil(target.width), Math.ceil(target.height)];
|
|
352
444
|
const from = previous.width && previous.height ? [previous.width, previous.height] : to;
|
|
445
|
+
const expanded = root.classList.contains("card");
|
|
353
446
|
const border = document.body.classList.contains("mac") ? 1 : 0;
|
|
447
|
+
// Fix the content width before awaiting the native bridge. Otherwise an
|
|
448
|
+
// absolutely positioned surface shrink-wraps for a frame on every tick.
|
|
449
|
+
root.firstElementChild.style.width = Math.max(0, to[0] - border) + "px";
|
|
450
|
+
root.style.setProperty("--content-max-height", Math.max(0, to[1] - border) + "px");
|
|
451
|
+
if (settledGeneration === generation - 1 && settledExpanded === expanded && settledSize
|
|
452
|
+
&& to.every((size, i) => size === settledSize[i] && Math.abs(size - from[i]) < 1)) {
|
|
453
|
+
// Elapsed time/countdowns update the text, not the window geometry.
|
|
454
|
+
root.style.width = to[0] + "px"; root.style.height = to[1] + "px";
|
|
455
|
+
settledGeneration = generation;
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
// Do not paint the new natural size before the native frame catches up.
|
|
459
|
+
root.style.width = from[0] + "px"; root.style.height = from[1] + "px";
|
|
460
|
+
clearTimeout(hoverTimer); clearTimeout(leaveTimer);
|
|
461
|
+
root.classList.add("animating");
|
|
462
|
+
layoutQueue = layoutQueue.then(() => animateFit(generation, expanded, from, to, pad))
|
|
463
|
+
.catch(error => console.error("Capsule layout failed", error));
|
|
464
|
+
}
|
|
465
|
+
async function animateFit(generation, expanded, from, to, pad) {
|
|
466
|
+
if (generation !== fitGeneration || dragging || closing) return;
|
|
467
|
+
const layout = await api().begin_layout(expanded, to[0] + pad, to[1] + pad, generation);
|
|
468
|
+
if (generation !== fitGeneration || dragging || closing || !layout.vertical) return;
|
|
469
|
+
document.body.classList.remove("grow-up", "grow-down", "grow-left", "grow-right");
|
|
470
|
+
document.body.classList.add("grow-" + layout.vertical, "grow-" + layout.horizontal);
|
|
471
|
+
from = [layout.from_width - pad, layout.from_height - pad];
|
|
472
|
+
to = [layout.width - pad, layout.height - pad];
|
|
473
|
+
const border = document.body.classList.contains("mac") ? 1 : 0;
|
|
474
|
+
root.style.setProperty("--content-max-height", Math.max(0, to[1] - border) + "px");
|
|
354
475
|
root.firstElementChild.style.width = Math.max(0, to[0] - border) + "px";
|
|
355
476
|
const duration = matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : 240;
|
|
356
477
|
const started = performance.now();
|
|
@@ -360,11 +481,20 @@ async function fit(previous) {
|
|
|
360
481
|
const eased = 1 - Math.pow(1 - t, 3);
|
|
361
482
|
const width = Math.round(from[0] + (to[0] - from[0]) * eased);
|
|
362
483
|
const height = Math.round(from[1] + (to[1] - from[1]) * eased);
|
|
484
|
+
await api().resize(width + pad, height + pad, eased, generation);
|
|
485
|
+
if (generation !== fitGeneration || dragging || closing) return;
|
|
363
486
|
root.style.width = width + "px"; root.style.height = height + "px";
|
|
364
|
-
await api().resize(width + pad, height + pad);
|
|
365
487
|
if (t === 1) break;
|
|
366
488
|
await new Promise(requestAnimationFrame);
|
|
367
489
|
}
|
|
490
|
+
if (generation === fitGeneration && !dragging && !closing) {
|
|
491
|
+
await api().finish_layout(generation);
|
|
492
|
+
if (generation === fitGeneration) {
|
|
493
|
+
root.classList.remove("animating");
|
|
494
|
+
settledGeneration = generation; settledSize = to; settledExpanded = expanded;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
observeHover();
|
|
368
498
|
}
|
|
369
499
|
|
|
370
500
|
async function tick() {
|
|
@@ -375,6 +505,9 @@ async function tick() {
|
|
|
375
505
|
// Once the prompt is handled an open card folds back unless the pointer is on it.
|
|
376
506
|
if (before === "attention" && V.mode !== "attention" && !hovering && !dragging && !panel) open = false;
|
|
377
507
|
render(false);
|
|
508
|
+
// Also detect a real pointer departure when clamping moved the window away
|
|
509
|
+
// from a stationary cursor (there may be no further native boundary event).
|
|
510
|
+
if (document.body.classList.contains("mac")) observeHover();
|
|
378
511
|
}
|
|
379
512
|
|
|
380
513
|
function say(text) { flash = { text: text, until: Date.now() + 6000 }; render(true); }
|
|
@@ -386,6 +519,7 @@ async function act(action, target) {
|
|
|
386
519
|
case "minimize": open = false; panel = ""; render(true); return api().minimize(); // back as a capsule when restored
|
|
387
520
|
case "close": closing = true; ++fitGeneration; clearInterval(pollTimer); clearTimeout(hoverTimer); clearTimeout(leaveTimer); return api().request_close(); // no call left waiting on a closed page
|
|
388
521
|
case "folder": return api().open_folder();
|
|
522
|
+
case "group": return toggleGroup(Number(target.dataset.group));
|
|
389
523
|
case "show_browser": {
|
|
390
524
|
try { await inputActivation; }
|
|
391
525
|
catch (error) { return say("未能激活进度窗口,请重试"); }
|
|
@@ -440,11 +574,17 @@ async function act(action, target) {
|
|
|
440
574
|
}
|
|
441
575
|
}
|
|
442
576
|
|
|
443
|
-
|
|
577
|
+
// A paper list scrolls; pressing in it must not drag the window.
|
|
578
|
+
const interactive = (target) => target.closest('button, input, select, textarea, a, [contenteditable="true"], [role="button"], .paper-list');
|
|
444
579
|
root.addEventListener("pointerdown", (event) => {
|
|
445
580
|
if (event.button === 0 && api().activate_on_input) inputActivation = api().activate_on_input();
|
|
581
|
+
if (event.button === 0 && event.target.closest(".attention-target")) {
|
|
582
|
+
attentionPointer = event.pointerId;
|
|
583
|
+
clearTimeout(hoverTimer); clearTimeout(leaveTimer);
|
|
584
|
+
}
|
|
446
585
|
if (event.button !== 0 || interactive(event.target)) return;
|
|
447
586
|
dragging = true;
|
|
587
|
+
++hoverRequest;
|
|
448
588
|
++fitGeneration;
|
|
449
589
|
clearTimeout(hoverTimer); clearTimeout(leaveTimer);
|
|
450
590
|
root.classList.add("dragging");
|
|
@@ -472,19 +612,21 @@ window.addEventListener("pointermove", event => {
|
|
|
472
612
|
nextDragPoint = [event.screenX, event.screenY];
|
|
473
613
|
if (!movingDrag) dragMove = flushDragMoves();
|
|
474
614
|
});
|
|
475
|
-
async function finishDrag() {
|
|
615
|
+
async function finishDrag(event) {
|
|
476
616
|
if (!dragging || endingDrag) return;
|
|
477
617
|
endingDrag = true;
|
|
478
618
|
try {
|
|
479
619
|
await dragReady;
|
|
480
620
|
await dragMove;
|
|
481
|
-
await api().set_dragging(false);
|
|
621
|
+
if (event.type === "pointerup") await api().set_dragging(false, event.screenX, event.screenY);
|
|
622
|
+
else await api().set_dragging(false);
|
|
482
623
|
} finally {
|
|
483
624
|
dragging = false; endingDrag = false;
|
|
484
625
|
root.classList.remove("dragging");
|
|
485
626
|
// Events queued by native tracking during a drag must not fold the card.
|
|
486
627
|
render(true);
|
|
487
|
-
|
|
628
|
+
await layoutQueue;
|
|
629
|
+
observeHover(root.matches(':hover'), true);
|
|
488
630
|
}
|
|
489
631
|
}
|
|
490
632
|
window.addEventListener("pointerup", finishDrag);
|
|
@@ -501,7 +643,7 @@ function setHover(inside, force = false) {
|
|
|
501
643
|
if (!force && hovering === inside && (!inside || open)) return;
|
|
502
644
|
hovering = inside;
|
|
503
645
|
clearTimeout(hoverTimer); clearTimeout(leaveTimer);
|
|
504
|
-
if (dragging) return;
|
|
646
|
+
if (dragging || attentionPointer !== null) return;
|
|
505
647
|
if (inside) {
|
|
506
648
|
hoverTimer = setTimeout(() => { if (!open) { open = true; render(true); } }, 100);
|
|
507
649
|
} else {
|
|
@@ -509,8 +651,41 @@ function setHover(inside, force = false) {
|
|
|
509
651
|
leaveTimer = setTimeout(() => { if (!panel) { open = false; render(true); } }, 280);
|
|
510
652
|
}
|
|
511
653
|
}
|
|
512
|
-
|
|
513
|
-
|
|
654
|
+
let hoverRequest = 0, lastNativePointer = null;
|
|
655
|
+
async function observeHover(inside, force = false) {
|
|
656
|
+
if (dragging || endingDrag || closing) return;
|
|
657
|
+
if (!document.body.classList.contains("mac")) {
|
|
658
|
+
if (typeof inside === "boolean") setHover(inside, force);
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
if (root.classList.contains("animating")) return;
|
|
662
|
+
const request = ++hoverRequest;
|
|
663
|
+
let pointer;
|
|
664
|
+
try { pointer = await api().hover_state(); }
|
|
665
|
+
catch (error) {
|
|
666
|
+
if (!closing) console.error("Capsule pointer query failed", error);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (request !== hoverRequest || dragging || endingDrag || closing || root.classList.contains("animating")) return;
|
|
670
|
+
// Moving/resizing the frame can generate enter/exit without mouse movement.
|
|
671
|
+
// It must not start a collapse/open loop, including across display boundaries.
|
|
672
|
+
if (!force && lastNativePointer && pointer.x === lastNativePointer.x && pointer.y === lastNativePointer.y) return;
|
|
673
|
+
lastNativePointer = pointer;
|
|
674
|
+
setHover(pointer.inside, force);
|
|
675
|
+
}
|
|
676
|
+
root.addEventListener("mouseenter", () => observeHover(true));
|
|
677
|
+
root.addEventListener("mouseleave", () => {
|
|
678
|
+
attentionPointer = null;
|
|
679
|
+
observeHover(false);
|
|
680
|
+
});
|
|
681
|
+
function endAttentionPress(event) {
|
|
682
|
+
if (attentionPointer === null || (event.pointerId !== undefined && attentionPointer !== event.pointerId)) return;
|
|
683
|
+
attentionPointer = null;
|
|
684
|
+
observeHover(root.matches(":hover"), true);
|
|
685
|
+
}
|
|
686
|
+
window.addEventListener("pointerup", endAttentionPress);
|
|
687
|
+
window.addEventListener("pointercancel", endAttentionPress);
|
|
688
|
+
window.addEventListener("blur", endAttentionPress);
|
|
514
689
|
document.addEventListener("keydown", (event) => {
|
|
515
690
|
if (event.key === "Escape" && panel) { panel = ""; render(true); }
|
|
516
691
|
if (event.key === "Enter" && panel === "settings") act("save");
|