dsh-game-material-master 0.1.1 → 0.2.1

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/lib/client.js CHANGED
@@ -27,7 +27,9 @@ window.__ModuleLoader__.load({
27
27
  const GAME_STUDIO_PANEL_ID = "gameStudio";
28
28
  // ── 远程贡献 ─────────────────────────────────────────────────────────
29
29
  // 与宿主 src/wire.ts 的 METHODS 必须一一对应;那份是唯一的真源。
30
- const codec = (symbol) => ({ mode: "strict", typeSymbol: symbol, schema: { parse: (value) => value } });
30
+ // 宿主校验在服务端;浏览器半区只声明同一套 strict codec。
31
+ // DSH 的 typert 要求 create() 工厂,运行时走 codec.create().parse()。
32
+ const codec = (symbol) => ({ mode: "strict", typeSymbol: symbol, create: () => ({ parse: (value) => value }) });
31
33
  const REMOTE_METHODS = [
32
34
  ["getConfig", false],
33
35
  ["saveConfig", true],
@@ -47,10 +49,21 @@ window.__ModuleLoader__.load({
47
49
  ["revealProject", true],
48
50
  ["runImage", true],
49
51
  ["runImages", true],
52
+ ["setImageMode", true],
53
+ ["runTurnVideo", true],
54
+ ["runTurnFrames", true],
55
+ ["setTurnPick", true],
56
+ ["setTurnPicks", true],
57
+ ["resetTurnPicks", true],
58
+ ["cutTurnFrames", true],
50
59
  ["runVideos", true],
51
60
  ["pollVideos", true],
52
61
  ["clearVideos", true],
53
62
  ["runFrames", true],
63
+ ["prepareFramePick", true],
64
+ ["setFramePick", true],
65
+ ["setFramePicks", true],
66
+ ["resetFramePicks", true],
54
67
  ["rekey", true],
55
68
  ["compose", true],
56
69
  // 模块②:图片生成
@@ -217,7 +230,7 @@ window.__ModuleLoader__.load({
217
230
  const STAGES = [
218
231
  { key: "images", title: "① 八方向绿幕图", hint: "以源图为基准,按依赖顺序生成八个方位的纯绿幕全身图" },
219
232
  { key: "videos", title: "② 行走动作视频", hint: "固定镜头、固定背景,让角色朝原方位原地走三步" },
220
- { key: "frames", title: "③ 提取序列帧", hint: "每段视频按时长平均抽帧,逐帧核对动作连贯性" },
233
+ { key: "frames", title: "③ 提取序列帧", hint: "可整批等分抽帧,也可对每一段视频手动选帧" },
221
234
  { key: "sheet", title: "④ 抠绿幕合成整图", hint: "剔除绿幕并按行序拼成一张精灵图" },
222
235
  { key: "preview", title: "⑤ 行走预览", hint: "用 WASD 或方向键操控角色,看看八方向接起来顺不顺" }
223
236
  ];
@@ -472,6 +485,39 @@ window.__ModuleLoader__.load({
472
485
  .SPR_badge{font-size:11px;padding:1px 7px;border-radius:999px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-tertiary)}
473
486
  .SPR_videoWrap{position:relative;width:100%}
474
487
  .SPR_video{width:100%;border-radius:8px;display:block;background:#000}
488
+ /* 转圈视频多半是竖屏(角色立绘比例):按 width:100% 铺开会有上千像素高,把下面的
489
+ 时间轴与八个方向图全顶出屏幕,所以改成按高度封顶、水平居中。 */
490
+ .SPR_videoTurn{width:auto;max-width:100%;max-height:360px;margin:0 auto}
491
+ /* 双击看大图:序列帧缩略图太小,看不清动作与抠像质量 */
492
+ .SPR_zoomMask{position:fixed;inset:0;z-index:80;background:rgba(10,12,16,.84);display:flex;align-items:center;justify-content:center;padding:28px;box-sizing:border-box;cursor:zoom-out}
493
+ .SPR_zoomImg{max-width:92vw;max-height:82vh;object-fit:contain;image-rendering:pixelated;border-radius:8px;background-color:var(--dsw-alias-bg-layer-1);cursor:default;box-shadow:0 14px 44px rgba(0,0,0,.5)}
494
+ .SPR_zoomClose{position:absolute;top:16px;right:20px;width:36px;height:36px;border-radius:999px;border:1px solid rgba(255,255,255,.34);background:rgba(28,32,40,.86);color:#fff;font-size:20px;line-height:1;cursor:pointer;font-family:inherit;display:flex;align-items:center;justify-content:center;padding:0}
495
+ .SPR_zoomClose:hover{background:rgba(64,70,82,.96)}
496
+ .SPR_zoomCaption{position:absolute;left:20px;right:20px;bottom:16px;text-align:center;color:#e9ebf1;font-size:12px}
497
+ .SPR_input[data-dirty=true]{border-color:var(--dsw-alias-state-business-primary)}
498
+ /* 阶段①的生成方式切换(转圈截帧为默认,逐方向生图为备选) */
499
+ .SPR_modeBar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:0 0 10px}
500
+ .SPR_modeBarLabel{font-size:12px;color:var(--dsw-alias-label-tertiary)}
501
+ .SPR_mode{font:inherit;font-size:12px;cursor:pointer;display:inline-flex;align-items:center;gap:6px;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l2);border-radius:999px;padding:4px 12px;color:var(--dsw-alias-label-secondary)}
502
+ .SPR_mode[data-active=true]{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-state-business-primary);box-shadow:0 0 0 1px color-mix(in srgb, var(--dsw-alias-state-business-primary) 28%, transparent)}
503
+ .SPR_modeTag{font-size:10px;line-height:14px;padding:0 5px;border-radius:999px;background:var(--dsw-alias-state-business-primary);color:#fff}
504
+ .SPR_modeBarHint{font-size:11px;color:var(--dsw-alias-label-tertiary)}
505
+ /* 转圈截帧的时间轴:缩略条带 + 八个可拖动的圆圈 */
506
+ .SPR_axisWrap{margin:12px 0 4px}
507
+ .SPR_axis{position:relative;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1);padding:34px 0 8px;touch-action:none;user-select:none}
508
+ .SPR_axis[data-dragging=true]{cursor:ew-resize}
509
+ .SPR_axisStrip{display:block;width:100%;border-radius:6px;pointer-events:none;-webkit-user-drag:none}
510
+ .SPR_axisDot{position:absolute;transform:translateX(-50%);min-width:30px;padding:2px 6px;display:flex;flex-direction:column;align-items:center;gap:0;font:inherit;font-size:11px;line-height:14px;cursor:grab;border:1px solid var(--dsw-alias-state-business-primary);border-radius:999px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);box-shadow:0 1px 3px rgba(0,0,0,.22)}
511
+ .SPR_axisDot:active{cursor:grabbing}
512
+ .SPR_axisDot[data-active=true]{box-shadow:0 0 0 2px color-mix(in srgb, var(--dsw-alias-state-business-primary) 40%, transparent)}
513
+ .SPR_axisDot[data-approved=true]{border-color:var(--dsw-alias-state-success-primary)}
514
+ .SPR_axisDot[data-approved=true] .SPR_axisDotIndex{color:var(--dsw-alias-state-success-primary)}
515
+ .SPR_axisDotLabel{font-weight:600;white-space:nowrap}
516
+ .SPR_axisDotIndex{font-size:10px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}
517
+ .SPR_axisRuler{display:flex;align-items:center;justify-content:space-between;gap:10px;font-size:11px;color:var(--dsw-alias-label-tertiary);margin-top:6px}
518
+ .SPR_axisRulerMid{text-align:center}
519
+ .SPR_pickPanel{grid-column:1 / -1;border:1px solid var(--dsw-alias-border-l2);border-radius:12px;padding:12px;background:var(--dsw-alias-bg-layer-1)}
520
+ .SPR_pickHead{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:8px;flex-wrap:wrap}
475
521
  .SPR_modules{display:flex;gap:8px;padding:10px 18px;border-bottom:1px solid var(--dsw-alias-border-l2);flex:none;flex-wrap:wrap}
476
522
  .SPR_module{font:inherit;cursor:pointer;text-align:left;display:flex;flex-direction:column;gap:1px;padding:6px 12px;border-radius:10px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary)}
477
523
  .SPR_module:hover{background:var(--dsw-alias-interactive-bg-hover-solid)}
@@ -681,20 +727,65 @@ window.__ModuleLoader__.load({
681
727
  "aria-busy": busy === true ? "true" : undefined
682
728
  }, children);
683
729
  }
684
- function NumField({ label, value, onChange, min, max, step }) {
730
+ /**
731
+ * 数字参数输入框。
732
+ *
733
+ * ★ 必须**在失焦 / 回车时才提交**,不能边打字边提交:宿主那边对每个参数
734
+ * 都会 clamp(单格宽最小 16、时长最小 4 秒…),敲一个字符就提交一次的话,
735
+ * 想输入「128」会在敲下「1」的瞬间被夹成 16、输入框随即被回包覆盖——
736
+ * 表现就是「数字总跳成别的值,根本没法输入」。所以这里本地存草稿文本,
737
+ * 只在 onBlur / Enter 时解析 + 夹取 + 回调,输入过程中一个远程调用都不发。
738
+ */
739
+ function NumField({ label, value, onChange, min, max, step, hint }) {
740
+ const [text, setText] = React.useState(String(value ?? ""));
741
+ const [focused, setFocused] = React.useState(false);
742
+ // 外部值变了(宿主回包、切换项目)而用户没在输入时,同步过来。
743
+ React.useEffect(() => {
744
+ if (!focused)
745
+ setText(String(value ?? ""));
746
+ }, [value, focused]);
747
+ const commit = () => {
748
+ const parsed = Number(text);
749
+ if (text.trim() === "" || !Number.isFinite(parsed)) {
750
+ setText(String(value ?? ""));
751
+ return;
752
+ }
753
+ const clamped = Math.min(max ?? Number.POSITIVE_INFINITY, Math.max(min ?? Number.NEGATIVE_INFINITY, parsed));
754
+ setText(String(clamped));
755
+ if (clamped !== value)
756
+ onChange(clamped);
757
+ };
685
758
  return h("label", { className: "SPR_field" }, h("span", { className: "SPR_fieldLabel" }, label), h("input", {
686
759
  className: "SPR_input",
687
760
  type: "number",
688
- value: value,
761
+ inputMode: "decimal",
762
+ value: text,
689
763
  min,
690
764
  max,
691
765
  step: step === undefined ? 1 : step,
692
- onChange: (event) => {
693
- const next = Number(event.target.value);
694
- if (Number.isFinite(next))
695
- onChange(next);
766
+ "data-dirty": focused && text !== String(value ?? "") ? "true" : undefined,
767
+ onChange: (event) => setText(event.target.value),
768
+ onFocus: (event) => {
769
+ setFocused(true);
770
+ // 光标落进来就全选:改参数基本都是整份替换,省一次三击。
771
+ try {
772
+ event.target.select?.();
773
+ }
774
+ catch {
775
+ /* 个别浏览器对 number 输入框的 select 有限制,忽略即可 */
776
+ }
777
+ },
778
+ onBlur: () => {
779
+ setFocused(false);
780
+ commit();
781
+ },
782
+ onKeyDown: (event) => {
783
+ if (event.key === "Enter") {
784
+ event.preventDefault();
785
+ event.currentTarget.blur();
786
+ }
696
787
  }
697
- }));
788
+ }), hint === undefined ? null : h("span", { className: "SPR_fieldLabel" }, hint));
698
789
  }
699
790
  /**
700
791
  * 全局模型设置。生图模型 / 视频模型都是插件级设置(设置 → 游戏素材大师),
@@ -732,6 +823,67 @@ window.__ModuleLoader__.load({
732
823
  const suffix = version === undefined ? "" : `?v=${version}`;
733
824
  return `${base}${relative}${suffix}`;
734
825
  }
826
+ /**
827
+ * 双击看大图的缩略图。
828
+ *
829
+ * 序列帧缩略图按格子尺寸显示(默认 256px、像素风还会更小),肉眼根本看不清
830
+ * 动作与抠像质量——双击弹出原图,右上角「×」、点背景、按 Esc 都能关。
831
+ * 遮罩用 position:fixed,所以它在卡片内部渲染也能盖住整页。
832
+ */
833
+ function ZoomableImage({ src, alt, className, caption, style }) {
834
+ const [open, setOpen] = React.useState(false);
835
+ React.useEffect(() => {
836
+ if (!open)
837
+ return undefined;
838
+ const onKey = (event) => {
839
+ if (event.key === "Escape")
840
+ setOpen(false);
841
+ };
842
+ if (typeof window !== "undefined")
843
+ window.addEventListener("keydown", onKey);
844
+ return () => {
845
+ if (typeof window !== "undefined")
846
+ window.removeEventListener("keydown", onKey);
847
+ };
848
+ }, [open]);
849
+ const openImage = (event) => {
850
+ event.preventDefault();
851
+ event.stopPropagation();
852
+ setOpen(true);
853
+ };
854
+ return h(React.Fragment, null, h("img", {
855
+ className,
856
+ src,
857
+ alt,
858
+ style,
859
+ title: "双击看大图",
860
+ "data-zoomable": "true",
861
+ onDoubleClick: openImage
862
+ }), open
863
+ ? h("div", {
864
+ className: "SPR_zoomMask",
865
+ role: "dialog",
866
+ "aria-modal": "true",
867
+ "data-testid": "zoom-mask",
868
+ onClick: () => setOpen(false)
869
+ }, h("button", {
870
+ type: "button",
871
+ className: "SPR_zoomClose",
872
+ "aria-label": "关闭大图",
873
+ title: "关闭(Esc)",
874
+ "data-testid": "zoom-close",
875
+ onClick: (event) => {
876
+ event.stopPropagation();
877
+ setOpen(false);
878
+ }
879
+ }, "×"), h("img", {
880
+ className: "SPR_zoomImg",
881
+ src,
882
+ alt,
883
+ onClick: (event) => event.stopPropagation()
884
+ }), caption !== undefined && caption !== null ? h("div", { className: "SPR_zoomCaption" }, caption) : null)
885
+ : null);
886
+ }
735
887
  // ── 「正在调用接口」的视觉反馈 ───────────────────────────────────────
736
888
  /**
737
889
  * 点一次按钮 = 一次远程调用。调用期间界面必须看得见「在跑」,
@@ -906,7 +1058,11 @@ window.__ModuleLoader__.load({
906
1058
  setStage(intent.stage);
907
1059
  }, [intent]);
908
1060
  const busy = project !== null && ((project.jobs?.length ?? 0) > 0 ||
909
- DIRECTION_KEYS.some((key) => project.videos?.[key]?.status === "running"));
1061
+ DIRECTION_KEYS.some((key) => project.videos?.[key]?.status === "running") ||
1062
+ // 转圈视频是「提交完就返回」的后台任务:kick 的那条记录在提交结束时就撤了,
1063
+ // 之后只剩节点自己还是 running。不把它算进来,界面在几分钟的等视频期间
1064
+ // 一次都不会刷新(宿主其实一直在轮询),看着就像卡住了。
1065
+ project.turn?.video?.status === "running");
910
1066
  // 轮询条件也要算上正在跑的这一次调用,否则点完按钮到 running 落盘之间不会刷新。
911
1067
  const polling = busy || tasks.active;
912
1068
  const refreshProjects = React.useCallback(async () => {
@@ -1125,7 +1281,10 @@ window.__ModuleLoader__.load({
1125
1281
  ? "var(--dsw-alias-state-success-primary)"
1126
1282
  : "var(--dsw-alias-label-tertiary)"
1127
1283
  }
1128
- }), item.title))), h("div", { className: "SPR_card" }, h("div", { className: "SPR_cardHead" }, h("h3", null, activeStage.title)), h("p", { className: "SPR_hint" }, activeStage.hint), stage === "images"
1284
+ }), item.title))), h("div", { className: "SPR_card" }, h("div", { className: "SPR_cardHead" }, h("h3", null, activeStage.title)),
1285
+ // 阶段①的说明跟着生成方式走:转圈截帧不是「八个方向各生成一次」,
1286
+ // 沿用逐方向生图那句话会让人以为走错了页面。
1287
+ h("p", { className: "SPR_hint" }, stageHint(project, stage, activeStage)), stage === "images"
1129
1288
  ? renderImageStage({
1130
1289
  project,
1131
1290
  api,
@@ -1204,6 +1363,13 @@ window.__ModuleLoader__.load({
1204
1363
  ? h(SequenceModule, { api })
1205
1364
  : h(RigModule, { api }));
1206
1365
  }
1366
+ /** 阶段卡片下方的说明文字(阶段①有两种生成方式,各说各的)。 */
1367
+ function stageHint(project, stage, activeStage) {
1368
+ if (stage === "images" && imageModeOf(project) === "turn") {
1369
+ return "先生成一段「角色原地匀速转一整圈」的绿幕视频,再按时间截出八个方向的帧;下面时间轴上的八个圆圈就是各自的截帧位置,拖动即可改。";
1370
+ }
1371
+ return activeStage.hint;
1372
+ }
1207
1373
  function stageDone(project, key) {
1208
1374
  if (key === "images")
1209
1375
  return DIRECTION_KEYS.every((k) => project.images?.[k]?.approved);
@@ -1221,8 +1387,309 @@ window.__ModuleLoader__.load({
1221
1387
  const KEY_IMG_ALL = "image:*all";
1222
1388
  const KEY_IMG_REGENERATE = "image:*regenerate";
1223
1389
  const KEY_PROMPT_RESET = "prompt:*reset";
1390
+ // ── 阶段①的另一种生成方式:转圈截帧 ──────────────────────────────────
1391
+ //
1392
+ // 逐方向生图是八次独立调用,模型每次都要重新「理解」角色,脸型/发色/服装
1393
+ // 容易在八个方向之间漂移。转圈截帧只生成**一段**「原地匀速转一整圈」的视频,
1394
+ // 八个方向是它时间轴上的八个截帧位置——八个方向天生同源,一致性最好。
1395
+ // 这条是默认路径,逐方向生图保留为备选(单张更清晰,但一致性看运气)。
1396
+ const IMAGE_MODES = [
1397
+ { key: "turn", title: "转圈截帧", hint: "先生成一段「原地匀速转一整圈」的视频,再按时间截出八个方向(默认,一致性最好)" },
1398
+ { key: "direct", title: "逐方向生图", hint: "每个方向单独生图(备选:单张更清晰,但八个方向容易不一致)" }
1399
+ ];
1400
+ const KEY_TURN_VIDEO = "turn:*video";
1401
+ const KEY_TURN_FRAMES = "turn:*frames";
1402
+ const KEY_TURN_PICK = (key) => `turn:pick:${key}`;
1403
+ const TURN_FRAME_MIN = 8;
1404
+ const TURN_FRAME_MAX = 64;
1405
+ /**
1406
+ * 项目用的是哪种生成方式。
1407
+ *
1408
+ * 宿主 `normalizeProject` 一定会补齐 `imageMode`;这里再兜一层是给**渲染桩数据**
1409
+ * 用的(测试里的项目对象不经过宿主),也是给「字段还不存在的老项目」用的:
1410
+ * 已经有图就按逐方向生图走,否则走默认的转圈截帧。
1411
+ */
1412
+ function imageModeOf(project) {
1413
+ if (project?.imageMode === "direct")
1414
+ return "direct";
1415
+ if (project?.imageMode === "turn")
1416
+ return "turn";
1417
+ const hasImages = DIRECTION_KEYS.some((key) => project?.images?.[key]?.file !== undefined);
1418
+ return hasImages ? "direct" : "turn";
1419
+ }
1420
+ /** 方向的短名(轴上的圆圈放不下「西南 · 四分之三正面」这种长标签)。 */
1421
+ function shortLabelOf(key) {
1422
+ const label = LABEL_OF[key] ?? key;
1423
+ return label.split(" · ")[0];
1424
+ }
1425
+ function clamp01(value) {
1426
+ return Math.min(1, Math.max(0, value));
1427
+ }
1428
+ /** 阶段①的生成方式切换条。 */
1429
+ function ImageModeBar({ project, api, start, mode }) {
1430
+ return h("div", { className: "SPR_modeBar" }, h("span", { className: "SPR_modeBarLabel" }, "生成方式"), IMAGE_MODES.map((entry) => h("button", {
1431
+ key: entry.key,
1432
+ type: "button",
1433
+ className: "SPR_mode",
1434
+ "data-active": mode === entry.key ? "true" : "false",
1435
+ title: entry.hint,
1436
+ "data-testid": `image-mode-${entry.key}`,
1437
+ onClick: () => void start(() => api.setImageMode({ projectId: project.id, mode: entry.key }), { reload: true })
1438
+ }, h("span", { className: "SPR_modeTitle" }, entry.title), entry.key === "turn" ? h("span", { className: "SPR_modeTag" }, "默认") : null)), h("span", { className: "SPR_modeBarHint" }, (IMAGE_MODES.find((entry) => entry.key === mode) ?? IMAGE_MODES[0]).hint));
1439
+ }
1440
+ /**
1441
+ * 八个截帧位置的时间轴。
1442
+ *
1443
+ * 轴底是整圈候选帧的缩略条带,「对着画面拖圆圈」是唯一不需要解释的交互——
1444
+ * 拖到哪个位置,那个方向就切那一帧。松手才提交(拖动过程只改本地状态),
1445
+ * 所以一次拖动最多只触发一次重切。方向键 ←/→ 也能逐个候选帧地微调。
1446
+ */
1447
+ function TurnAxis({ project, total, duration, picks, images, api, start, busy }) {
1448
+ const trackRef = React.useRef(null);
1449
+ // 拖动过程只改这份本地状态(圆圈跟着手走),松手才提交一次远程调用。
1450
+ const [drag, setDrag] = React.useState(null);
1451
+ const pickOf = (key) => {
1452
+ if (drag !== null && drag.key === key)
1453
+ return drag.index;
1454
+ return Math.min(total - 1, Math.max(0, Number(picks?.[key] ?? 0)));
1455
+ };
1456
+ const indexFromEvent = (event) => {
1457
+ const node = trackRef.current;
1458
+ if (node === null || total <= 0)
1459
+ return 0;
1460
+ const rect = node.getBoundingClientRect();
1461
+ if (rect.width <= 0)
1462
+ return 0;
1463
+ const fraction = clamp01((event.clientX - rect.left) / rect.width);
1464
+ return Math.min(total - 1, Math.max(0, Math.round(fraction * total - 0.5)));
1465
+ };
1466
+ const commit = (key, index) => {
1467
+ const current = Math.min(total - 1, Math.max(0, Number(picks?.[key] ?? 0)));
1468
+ if (index === current)
1469
+ return;
1470
+ void start(() => api.setTurnPick({ projectId: project.id, key, index }), { reload: true }, { key: KEY_TURN_PICK(key), label: `正在切出「${LABEL_OF[key] ?? key}」第 ${index + 1} 帧…` });
1471
+ };
1472
+ const nudge = (key, delta) => {
1473
+ const next = Math.min(total - 1, Math.max(0, Number(picks?.[key] ?? 0) + delta));
1474
+ commit(key, next);
1475
+ };
1476
+ // 两个方向被拖到同一帧时会叠在一起,往上错一层;顺序不变,只是看起来分明。
1477
+ const lanes = {};
1478
+ const used = [];
1479
+ [...DIRECTION_KEYS]
1480
+ .map((key) => ({ key, index: pickOf(key) }))
1481
+ .sort((a, b) => a.index - b.index)
1482
+ .forEach((item) => {
1483
+ let lane = 0;
1484
+ while (used.some((slot) => slot.lane === lane && Math.abs(slot.index - item.index) < 2))
1485
+ lane++;
1486
+ used.push({ lane, index: item.index });
1487
+ lanes[item.key] = lane;
1488
+ });
1489
+ return h("div", { className: "SPR_axisWrap" }, h("div", {
1490
+ className: "SPR_axis",
1491
+ ref: trackRef,
1492
+ "data-dragging": drag === null ? undefined : "true",
1493
+ onPointerMove: (event) => {
1494
+ if (drag === null)
1495
+ return;
1496
+ const index = indexFromEvent(event);
1497
+ if (index !== drag.index)
1498
+ setDrag({ key: drag.key, index });
1499
+ },
1500
+ onPointerUp: (event) => {
1501
+ if (drag === null)
1502
+ return;
1503
+ const index = indexFromEvent(event);
1504
+ const key = drag.key;
1505
+ setDrag(null);
1506
+ commit(key, index);
1507
+ },
1508
+ onPointerLeave: () => {
1509
+ if (drag === null)
1510
+ return;
1511
+ setDrag(null);
1512
+ }
1513
+ }, h("img", {
1514
+ className: "SPR_axisStrip",
1515
+ src: assetUrl(project, project.turn?.frames?.strip, project.turn?.frames?.updatedAt),
1516
+ alt: "整圈候选帧",
1517
+ draggable: false
1518
+ }), DIRECTION_KEYS.map((key) => {
1519
+ const index = pickOf(key);
1520
+ const approved = images?.[key]?.approved === true;
1521
+ const active = drag !== null && drag.key === key;
1522
+ const time = duration > 0 && total > 0 ? (index * duration) / total : 0;
1523
+ return h("button", {
1524
+ key,
1525
+ type: "button",
1526
+ className: "SPR_axisDot",
1527
+ "data-active": active ? "true" : "false",
1528
+ "data-approved": approved ? "true" : "false",
1529
+ "data-dragging": busy === true ? "true" : undefined,
1530
+ "data-testid": `turn-dot-${key}`,
1531
+ style: { left: `${((index + 0.5) / Math.max(1, total)) * 100}%`, top: `${6 + (lanes[key] ?? 0) * 26}px` },
1532
+ title: `${LABEL_OF[key] ?? key}:第 ${index + 1}/${total} 帧(${time.toFixed(2)} 秒)— 拖动改位置,←/→ 微调`,
1533
+ "aria-label": `${LABEL_OF[key] ?? key} 第 ${index + 1} 帧`,
1534
+ onPointerDown: (event) => {
1535
+ event.preventDefault();
1536
+ setDrag({ key, index });
1537
+ try {
1538
+ event.currentTarget.setPointerCapture?.(event.pointerId);
1539
+ }
1540
+ catch {
1541
+ /* 指针捕获失败不影响拖动:move/up 挂在轴上 */
1542
+ }
1543
+ },
1544
+ onKeyDown: (event) => {
1545
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight")
1546
+ return;
1547
+ event.preventDefault();
1548
+ nudge(key, event.key === "ArrowLeft" ? -1 : 1);
1549
+ }
1550
+ }, h("span", { className: "SPR_axisDotLabel" }, shortLabelOf(key)), h("span", { className: "SPR_axisDotIndex" }, `${index + 1}`));
1551
+ })), h("div", { className: "SPR_axisRuler" }, h("span", null, "0 秒"), h("span", { className: "SPR_axisRulerMid" }, total > 0
1552
+ ? `共 ${total} 张候选帧 · 每张约 ${(duration / total).toFixed(2)} 秒 —— 拖动圆圈调整每个方向截在哪一帧`
1553
+ : "还没有候选帧:先点「生成转圈视频」,视频到手会自动抽帧"), h("span", null, `${duration.toFixed(2)} 秒`)));
1554
+ }
1555
+ /** 转圈截帧:转圈视频 → 候选帧 → 八圆圈时间轴 → 八张方向图。 */
1556
+ function TurnImageStage({ project, api, start, setNotice, tasks, savePrompts }) {
1557
+ const video = project.turn?.video ?? {};
1558
+ const frames = project.turn?.frames ?? {};
1559
+ const total = Array.isArray(frames.frames) ? frames.frames.length : 0;
1560
+ const duration = Number(frames.duration ?? 0);
1561
+ const picks = frames.picks ?? {};
1562
+ const [promptDraft, setPromptDraft] = React.useState(project.prompts?.turn ?? "");
1563
+ const [countDraft, setCountDraft] = React.useState(null);
1564
+ React.useEffect(() => {
1565
+ setPromptDraft(project.prompts?.turn ?? "");
1566
+ }, [project.prompts?.turn]);
1567
+ const videoRunning = video.status === "running" || tasks.has(KEY_TURN_VIDEO);
1568
+ const videoLabel = tasks.label(KEY_TURN_VIDEO) ?? (video.remoteStatus ?? "正在生成转圈视频…");
1569
+ // 「在切帧」= 本地刚点下去 / 宿主那批抽帧还在跑。抽帧是 kick 型调用,
1570
+ // 一提交就返回,真正的活(抽 32 张 + 切 8 张图)在后台,所以两者都要看。
1571
+ const hostFrames = hostJob(project, "turn:frames");
1572
+ const cutting = frames.status === "running" || tasks.has(KEY_TURN_FRAMES) || hostFrames !== undefined;
1573
+ const cutLabel = tasks.label(KEY_TURN_FRAMES) ?? (frames.status === "running" ? "正在抽取候选帧…" : "正在抽取候选帧并切出八个方向…");
1574
+ const promptDirty = promptDraft !== (project.prompts?.turn ?? "");
1575
+ const frameCount = Number(countDraft ?? project.settings?.turnFrameCount ?? 32);
1576
+ const allApproved = DIRECTION_KEYS.every((key) => project.images?.[key]?.approved);
1577
+ const readyImages = DIRECTION_KEYS.filter((key) => project.images?.[key]?.file !== undefined).length;
1578
+ const stale = frames.stale === true;
1579
+ return h(React.Fragment, null, h("p", { className: "SPR_hint" }, "先生成一段「角色原地匀速转一整圈」的视频(绿幕、保持原图风格、除旋转外不做任何动作),再按时间截出八个方向的帧。八个方向出自同一段视频,一致性比逐方向生图好得多;下面时间轴上的八个圆圈就是各自的截帧位置,随便拖。"), h("textarea", {
1580
+ className: "SPR_area",
1581
+ value: promptDraft,
1582
+ "data-testid": "turn-prompt",
1583
+ onChange: (event) => setPromptDraft(event.target.value)
1584
+ }), h("div", { className: "SPR_toolbar" }, h(Btn, { disabled: !promptDirty, onClick: () => void savePrompts({ turn: promptDraft }) }, promptDirty ? "保存转圈提示词" : "转圈提示词已保存"), h(Btn, {
1585
+ onClick: () => void start(() => api.savePrompts({ projectId: project.id, resetTurnToDefault: true }), {
1586
+ reload: true,
1587
+ notice: "转圈提示词已重置为默认模板",
1588
+ noticeKind: "ok"
1589
+ })
1590
+ }, "重置为默认")), h("div", { className: "SPR_toolbar" }, h(BusyBtn, {
1591
+ primary: video.file === undefined,
1592
+ busy: tasks.has(KEY_TURN_VIDEO),
1593
+ busyText: "正在提交…",
1594
+ disabled: project.source === null || videoRunning,
1595
+ onClick: () => void start(() => api.runTurnVideo({ projectId: project.id }), { reload: true }, {
1596
+ key: KEY_TURN_VIDEO,
1597
+ label: "正在提交转圈视频任务…"
1598
+ })
1599
+ }, video.file === undefined
1600
+ ? "生成转圈视频(计费一次)"
1601
+ : videoRunning
1602
+ ? "转圈视频生成中…"
1603
+ : "重新生成转圈视频(计费一次)"), h(BusyBtn, {
1604
+ busy: tasks.has(KEY_TURN_FRAMES),
1605
+ busyText: "正在抽帧…",
1606
+ disabled: video.file === undefined || cutting,
1607
+ onClick: () => void start(() => api.runTurnFrames({ projectId: project.id }), { reload: true }, {
1608
+ key: KEY_TURN_FRAMES,
1609
+ label: "正在抽取候选帧并切出八个方向…"
1610
+ })
1611
+ }, total > 0 ? `重新抽帧(当前 ${total} 张)` : "抽取候选帧"), h(NumField, {
1612
+ label: "候选帧数(8~64)",
1613
+ value: frameCount,
1614
+ min: TURN_FRAME_MIN,
1615
+ max: TURN_FRAME_MAX,
1616
+ onChange: (value) => setCountDraft(value)
1617
+ }), h(BusyBtn, {
1618
+ busy: tasks.has(KEY_TURN_FRAMES),
1619
+ busyText: "正在抽帧…",
1620
+ disabled: video.file === undefined || cutting || countDraft === null || countDraft === project.settings?.turnFrameCount,
1621
+ onClick: () => void start(() => api.runTurnFrames({ projectId: project.id, count: frameCount }), { reload: true, notice: `已按 ${frameCount} 张重抽候选帧`, noticeKind: "ok" }, {
1622
+ key: KEY_TURN_FRAMES,
1623
+ label: `正在按 ${frameCount} 张重抽候选帧…`
1624
+ })
1625
+ }, "应用帧数"), h("span", { className: "SPR_refRow" }, project.settings?.turnFrameCount === frameCount ? `当前 ${project.settings?.turnFrameCount ?? "—"} 张` : `未应用(当前 ${project.settings?.turnFrameCount ?? "—"} 张)`)), h("div", { className: "SPR_toolbar" }, h(Btn, {
1626
+ disabled: total === 0 || cutting,
1627
+ onClick: () => void start(() => api.resetTurnPicks({ projectId: project.id }), { reload: true, notice: "八个圆圈已回到默认等分位置", noticeKind: "ok" })
1628
+ }, "重置八个圆圈"), h(Btn, {
1629
+ disabled: total === 0 || cutting,
1630
+ title: "转圈方向决定默认位置怎么排;拖动过的圆圈以你的位置为准",
1631
+ onClick: () => void start(() => api.resetTurnPicks({ projectId: project.id, direction: project.turn?.direction === "ccw" ? "cw" : "ccw" }), {
1632
+ reload: true,
1633
+ notice: project.turn?.direction === "ccw" ? "已改为顺时针并重排八个圆圈" : "已改为逆时针并重排八个圆圈",
1634
+ noticeKind: "ok"
1635
+ })
1636
+ }, project.turn?.direction === "ccw" ? "转圈方向:逆时针(点一下换向)" : "转圈方向:顺时针(点一下换向)"), h(Btn, {
1637
+ on: allApproved,
1638
+ disabled: readyImages === 0,
1639
+ onClick: () => void start(() => api.setApproved({ projectId: project.id, stage: "images", approved: !allApproved }), { reload: true })
1640
+ }, allApproved ? "取消全部通过" : "全部标记通过"), h(BusyBadge, { show: videoRunning || cutting, text: videoRunning ? videoLabel : cutLabel })), video.file !== undefined
1641
+ ? h("div", { className: "SPR_videoWrap" }, h(MediaBox, {
1642
+ overlay: videoRunning,
1643
+ text: videoLabel,
1644
+ children: h("video", {
1645
+ className: "SPR_video SPR_videoTurn",
1646
+ src: assetUrl(project, video.file, video.updatedAt),
1647
+ controls: true,
1648
+ preload: "metadata",
1649
+ "data-testid": "turn-video"
1650
+ })
1651
+ }))
1652
+ : h("div", { className: "SPR_thumbEmpty", style: { aspectRatio: "16/9" } }, videoRunning ? "正在生成转圈视频…" : "还没有转圈视频:点上面的「生成转圈视频」"), video.error !== undefined ? h("p", { className: "SPR_error" }, video.error) : null, h("div", { className: "SPR_refRow" }, `首帧用的是${video.firstFrame !== undefined && String(video.firstFrame).startsWith("images/") ? "已生成的正面绿幕图" : "上传的源图"}:${video.firstFrame ?? "—"}`), total > 0
1653
+ ? h(TurnAxis, {
1654
+ project,
1655
+ total,
1656
+ duration,
1657
+ picks,
1658
+ images: project.images,
1659
+ api,
1660
+ start,
1661
+ busy: cutting
1662
+ })
1663
+ : h("div", { className: "SPR_thumbEmpty", style: { marginTop: 10 } }, cutting ? "正在抽取候选帧…" : stale ? "候选帧已过期(转圈视频换过了):点「重新抽帧」" : "还没有候选帧"), frames.error !== undefined ? h("p", { className: "SPR_error" }, frames.error) : null, h("div", { className: "SPR_grid", style: { marginTop: 12 } }, DIRECTION_KEYS.map((key) => {
1664
+ const node = project.images?.[key];
1665
+ const index = Math.min(Math.max(0, total - 1), Math.max(0, Number(picks[key] ?? 0)));
1666
+ const queued = (tasks.has(KEY_TURN_FRAMES) || jobCovers(hostFrames, key)) && node?.status !== "error";
1667
+ const nodeBusy = node?.status === "running" || tasks.has(KEY_TURN_PICK(key)) || queued;
1668
+ const overlayText = tasks.label(KEY_TURN_PICK(key)) ?? (queued ? cutLabel : "正在切出这一帧…");
1669
+ return h("div", { key, className: "SPR_node", "data-busy": nodeBusy ? "true" : undefined }, h("div", { className: "SPR_nodeTop" }, h("span", { className: "SPR_nodeTitle" }, LABEL_OF[key] ?? key), nodeBusy ? h(Chip, { kind: "running", text: "切帧中" }) : h(StatusChip, { node })), node?.file !== undefined
1670
+ ? h(MediaBox, { overlay: nodeBusy, text: overlayText }, h("img", { className: "SPR_thumb", src: assetUrl(project, node.file, node.updatedAt ?? project.updatedAt), alt: LABEL_OF[key] ?? key }))
1671
+ : h("div", { className: "SPR_thumbEmpty" }, nodeBusy ? "正在切出这一帧…" : "还没有这一方向的图"), node?.error !== undefined ? h("p", { className: "SPR_error" }, node.error) : null, h("span", { className: "SPR_refRow" }, total > 0
1672
+ ? `第 ${index + 1}/${total} 帧 · ${((index * duration) / Math.max(1, total)).toFixed(2)} 秒`
1673
+ : "等待候选帧"), h("div", { className: "SPR_btnRow" }, h(Btn, {
1674
+ disabled: node?.status !== "ready" || nodeBusy,
1675
+ on: node?.approved === true,
1676
+ onClick: () => void start(() => api.setApproved({
1677
+ projectId: project.id,
1678
+ stage: "images",
1679
+ key,
1680
+ approved: node?.approved !== true
1681
+ }), { reload: true })
1682
+ }, node?.approved === true ? "已通过" : "通过")));
1683
+ })));
1684
+ }
1224
1685
  function renderImageStage(ctx) {
1225
1686
  const { project, api, promptDraft, setPromptDraft, promptOpen, setPromptOpen, savePrompts, start, setNotice, tasks } = ctx;
1687
+ const mode = imageModeOf(project);
1688
+ const modeBar = h(ImageModeBar, { project, api, start, mode });
1689
+ // 转圈截帧(默认):整条链路都在 TurnImageStage 里,产物同样是 images/<方向>.png。
1690
+ if (mode === "turn") {
1691
+ return h(React.Fragment, null, modeBar, h(TurnImageStage, { project, api, start, setNotice, tasks, savePrompts }));
1692
+ }
1226
1693
  const allApproved = DIRECTION_KEYS.every((key) => project.images?.[key]?.approved);
1227
1694
  // 「一键生成全部」/「全部重新生成」提交后,八个方向都可能要重出图,
1228
1695
  // 在宿主状态回来之前先整体盖住,别让用户以为按钮没生效。
@@ -1233,7 +1700,7 @@ window.__ModuleLoader__.load({
1233
1700
  const hostAll = hostJob(project, "images:all");
1234
1701
  const batchBusy = batch || hostAll !== undefined;
1235
1702
  const resetting = tasks.has(KEY_PROMPT_RESET);
1236
- return h(React.Fragment, null, h("div", { className: "SPR_toolbar" }, h(BusyBtn, {
1703
+ return h(React.Fragment, null, modeBar, h("div", { className: "SPR_toolbar" }, h(BusyBtn, {
1237
1704
  primary: true,
1238
1705
  busy: tasks.has(KEY_IMG_ALL),
1239
1706
  busyText: "正在提交全部方向…",
@@ -1420,19 +1887,181 @@ window.__ModuleLoader__.load({
1420
1887
  }, video?.approved === true ? "已通过" : "通过")));
1421
1888
  })));
1422
1889
  }
1890
+ /**
1891
+ * 某一段行走视频的选帧轴。圆圈个数 = 输出帧数,拖到候选条带的哪一格,
1892
+ * 那一张输出帧就用那一格。松手才提交,和转圈截帧的八圆圈是同一套交互。
1893
+ */
1894
+ function FramePickAxis({ project, directionKey, total, duration, picks, api, start, busy }) {
1895
+ const trackRef = React.useRef(null);
1896
+ const [drag, setDrag] = React.useState(null);
1897
+ const pickOf = (slot) => {
1898
+ if (drag !== null && drag.slot === slot)
1899
+ return drag.index;
1900
+ return Math.min(total - 1, Math.max(0, Number(picks?.[slot] ?? 0)));
1901
+ };
1902
+ const indexFromEvent = (event) => {
1903
+ const node = trackRef.current;
1904
+ if (node === null || total <= 0)
1905
+ return 0;
1906
+ const rect = node.getBoundingClientRect();
1907
+ if (rect.width <= 0)
1908
+ return 0;
1909
+ const fraction = clamp01((event.clientX - rect.left) / rect.width);
1910
+ return Math.min(total - 1, Math.max(0, Math.round(fraction * total - 0.5)));
1911
+ };
1912
+ const commit = (slot, index) => {
1913
+ const current = Math.min(total - 1, Math.max(0, Number(picks?.[slot] ?? 0)));
1914
+ if (index === current)
1915
+ return;
1916
+ void start(() => api.setFramePick({ projectId: project.id, key: directionKey, slot, index }), { reload: true }, { key: `frames:slot:${directionKey}:${slot}`, label: `正在切出第 ${slot + 1} 帧…` });
1917
+ };
1918
+ const nudge = (slot, delta) => {
1919
+ const next = Math.min(total - 1, Math.max(0, Number(picks?.[slot] ?? 0) + delta));
1920
+ commit(slot, next);
1921
+ };
1922
+ const lanes = {};
1923
+ const used = [];
1924
+ picks.forEach((_, slot) => {
1925
+ const index = pickOf(slot);
1926
+ let lane = 0;
1927
+ while (used.some((item) => item.lane === lane && Math.abs(item.index - index) < 2))
1928
+ lane++;
1929
+ used.push({ lane, index });
1930
+ lanes[slot] = lane;
1931
+ });
1932
+ const candidates = project.frames?.[directionKey]?.candidates ?? {};
1933
+ return h("div", { className: "SPR_axisWrap" }, h("div", {
1934
+ className: "SPR_axis",
1935
+ ref: trackRef,
1936
+ "data-dragging": drag === null ? undefined : "true",
1937
+ onPointerMove: (event) => {
1938
+ if (drag === null)
1939
+ return;
1940
+ const index = indexFromEvent(event);
1941
+ if (index !== drag.index)
1942
+ setDrag({ slot: drag.slot, index });
1943
+ },
1944
+ onPointerUp: (event) => {
1945
+ if (drag === null)
1946
+ return;
1947
+ const index = indexFromEvent(event);
1948
+ const slot = drag.slot;
1949
+ setDrag(null);
1950
+ commit(slot, index);
1951
+ },
1952
+ onPointerLeave: () => {
1953
+ if (drag === null)
1954
+ return;
1955
+ setDrag(null);
1956
+ }
1957
+ }, h("img", {
1958
+ className: "SPR_axisStrip",
1959
+ src: assetUrl(project, candidates.strip, candidates.updatedAt),
1960
+ alt: "候选帧",
1961
+ draggable: false
1962
+ }), picks.map((_, slot) => {
1963
+ const index = pickOf(slot);
1964
+ const active = drag !== null && drag.slot === slot;
1965
+ const time = duration > 0 && total > 0 ? (index * duration) / total : 0;
1966
+ return h("button", {
1967
+ key: slot,
1968
+ type: "button",
1969
+ className: "SPR_axisDot",
1970
+ "data-active": active ? "true" : "false",
1971
+ "data-testid": `frame-dot-${directionKey}-${slot}`,
1972
+ style: { left: `${((index + 0.5) / Math.max(1, total)) * 100}%`, top: `${6 + (lanes[slot] ?? 0) * 26}px` },
1973
+ title: `第 ${slot + 1} 帧:候选第 ${index + 1}/${total}(${time.toFixed(2)} 秒)— 拖动改位置,←/→ 微调`,
1974
+ "aria-label": `第 ${slot + 1} 帧,候选第 ${index + 1}`,
1975
+ onPointerDown: (event) => {
1976
+ if (busy === true)
1977
+ return;
1978
+ event.preventDefault();
1979
+ setDrag({ slot, index });
1980
+ try {
1981
+ event.currentTarget.setPointerCapture?.(event.pointerId);
1982
+ }
1983
+ catch {
1984
+ /* 指针捕获失败不影响拖动 */
1985
+ }
1986
+ },
1987
+ onKeyDown: (event) => {
1988
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight")
1989
+ return;
1990
+ event.preventDefault();
1991
+ nudge(slot, event.key === "ArrowLeft" ? -1 : 1);
1992
+ }
1993
+ }, h("span", { className: "SPR_axisDotLabel" }, String(slot + 1)), h("span", { className: "SPR_axisDotIndex" }, String(index + 1)));
1994
+ })), h("div", { className: "SPR_axisRuler" }, h("span", null, "0 秒"), h("span", { className: "SPR_axisRulerMid" }, `共 ${total} 张候选帧 · ${picks.length} 个圆圈 —— 拖动圆圈决定每一张输出帧截在哪`), h("span", null, `${duration.toFixed(2)} 秒`)));
1995
+ }
1996
+ function FramePickPanel({ project, direction, api, start, tasks, countDraft, setCountDraft }) {
1997
+ const node = project.frames?.[direction.key] ?? {};
1998
+ const candidates = node.candidates ?? {};
1999
+ const total = Array.isArray(candidates.frames) ? candidates.frames.length : 0;
2000
+ const duration = Number(candidates.duration ?? node.duration ?? 0);
2001
+ const picks = Array.isArray(candidates.picks) ? candidates.picks : [];
2002
+ const frameCount = Number(countDraft ?? candidates.rawFrameCount ?? 32);
2003
+ const taskKey = `frames:pick:${direction.key}`;
2004
+ const hostPick = hostJob(project, taskKey);
2005
+ const cutting = candidates.status === "running" || tasks.has(taskKey) || hostPick !== undefined;
2006
+ const video = project.videos?.[direction.key];
2007
+ return h("div", { className: "SPR_pickPanel", "data-testid": `frame-pick-${direction.key}` }, h("div", { className: "SPR_pickHead" }, h("span", { className: "SPR_nodeTitle" }, `手动选帧 · ${direction.label}`), h("span", { className: "SPR_refRow" }, "只影响这一段视频。圆圈个数跟「每段视频抽帧数」走,拖到哪一格就截哪一格。")), video?.file !== undefined
2008
+ ? h("video", {
2009
+ className: "SPR_video",
2010
+ src: assetUrl(project, video.file, video.updatedAt),
2011
+ controls: true,
2012
+ preload: "metadata"
2013
+ })
2014
+ : null, h("div", { className: "SPR_toolbar" }, h(NumField, {
2015
+ label: "候选帧数(8~64)",
2016
+ value: frameCount,
2017
+ min: TURN_FRAME_MIN,
2018
+ max: TURN_FRAME_MAX,
2019
+ onChange: (value) => setCountDraft(value)
2020
+ }), h(BusyBtn, {
2021
+ busy: tasks.has(taskKey),
2022
+ busyText: "正在抽候选帧…",
2023
+ disabled: cutting && !tasks.has(taskKey),
2024
+ onClick: () => void start(() => api.prepareFramePick({ projectId: project.id, key: direction.key, count: frameCount }), { reload: true, notice: `已按 ${frameCount} 张候选帧重抽「${direction.label}」`, noticeKind: "ok" }, { key: taskKey, label: `正在抽取「${direction.label}」的候选帧…` })
2025
+ }, total > 0 ? "重新抽取候选帧" : "抽取候选帧"), h(BusyBtn, {
2026
+ busy: tasks.has(`frames:slot:${direction.key}:reset`),
2027
+ busyText: "正在重置…",
2028
+ disabled: total === 0 || cutting,
2029
+ onClick: () => void start(() => api.resetFramePicks({ projectId: project.id, key: direction.key }), { reload: true, notice: "圆圈已回到等分位置", noticeKind: "ok" }, { key: `frames:slot:${direction.key}:reset`, label: `正在重置「${direction.label}」的选帧…` })
2030
+ }, "重置为等分"), h(BusyBadge, { show: cutting, text: tasks.label(taskKey) ?? "正在抽取候选帧…" })), total > 0
2031
+ ? h(FramePickAxis, {
2032
+ project,
2033
+ directionKey: direction.key,
2034
+ total,
2035
+ duration,
2036
+ picks,
2037
+ api,
2038
+ start,
2039
+ busy: cutting
2040
+ })
2041
+ : h("div", { className: "SPR_thumbEmpty" }, cutting ? "正在抽取候选帧…" : "还没有候选帧"), candidates.error !== undefined ? h("p", { className: "SPR_error" }, candidates.error) : null);
2042
+ }
1423
2043
  // ── 阶段 3:抽帧 ─────────────────────────────────────────────────────
1424
2044
  const KEY_FRAMES_ONE = (key) => `frames:${key}`;
1425
2045
  const KEY_FRAMES_ALL = "frames:*all";
2046
+ const KEY_FRAMES_PICK = (key) => `frames:pick:${key}`;
1426
2047
  function renderFrameStage(ctx) {
1427
2048
  const { project, start, api, settingsDraft, saveSettings, tasks } = ctx;
2049
+ // 选帧草稿必须放在独立组件里。这里是普通函数,而且只在切到「提取序列帧」
2050
+ // 时才被调用;直接 useState 会算进 StudioPanel,前后两次渲染的 Hook 数量对不上。
2051
+ return h(FrameStage, { project, start, api, settingsDraft, saveSettings, tasks });
2052
+ }
2053
+ function FrameStage({ project, start, api, settingsDraft, saveSettings, tasks }) {
1428
2054
  const readyVideos = DIRECTION_KEYS.filter((key) => project.videos?.[key]?.file !== undefined);
1429
2055
  const allApproved = DIRECTION_KEYS.every((key) => project.frames?.[key]?.approved);
1430
2056
  const draft = settingsDraft ?? project.settings ?? {};
1431
2057
  // 宿主侧那次抽帧任务盖住了哪些方向。批量抽帧是「一次两个方向」慢慢做的,
1432
2058
  // 本地 pending 表只多留 700ms,盖不住还没轮到的那六个方向——只看它就会
1433
2059
  // 出现「先转圈、紧接着变回尚未抽帧、过一阵才出结果」。
2060
+ const [pickKey, setPickKey] = React.useState(null);
2061
+ const [pickCount, setPickCount] = React.useState(null);
1434
2062
  const hostExtract = hostJob(project, "frames:extract");
1435
- const extracting = tasks.any("frames:*") || hostExtract !== undefined;
2063
+ const hostPicking = Array.isArray(project.jobs) && project.jobs.some((job) => typeof job?.key === "string" && job.key.startsWith("frames:pick:"));
2064
+ const extracting = tasks.any("frames:*") || tasks.any("frames:pick:") || hostExtract !== undefined || hostPicking;
1436
2065
  const batchLabel = tasks.label(KEY_FRAMES_ALL) ?? "正在抽取全部序列帧…";
1437
2066
  return h(React.Fragment, null, h("div", { className: "SPR_fields" }, h(NumField, {
1438
2067
  label: "单格宽(px)",
@@ -1464,7 +2093,9 @@ window.__ModuleLoader__.load({
1464
2093
  min: 1,
1465
2094
  max: 8,
1466
2095
  onChange: (value) => saveSettings({ concurrency: value })
1467
- })), h("p", { className: "SPR_hint" }, "抽帧抽到的是「工作尺寸」(长边上限),不是最终格子尺寸。自动裁剪、统一缩放和像素量化都在第 4 步做,这样八个方向才能共享同一个裁剪框、脚底对齐同一条基线。改完这里需要重新抽帧。"), h("div", { className: "SPR_toolbar" }, h(BusyBtn, {
2096
+ })), h("p", { className: "SPR_hint" }, "抽帧抽到的是「工作尺寸」(长边上限),不是最终格子尺寸。自动裁剪、统一缩放和像素量化都在第 4 步做,这样八个方向才能共享同一个裁剪框、脚底对齐同一条基线。改完这里需要重新抽帧。" +
2097
+ "「提取全部」对每一段视频用同一套等分;要某一段单独挑帧,点那张卡片上的「手动选帧」,拖圆圈即可(和转圈截帧一样)。" +
2098
+ "预览带是**双击看大图**:格子尺寸只有 256px,看不清动作和抠像质量。"), h("div", { className: "SPR_toolbar" }, h(BusyBtn, {
1468
2099
  primary: true,
1469
2100
  busy: tasks.has(KEY_FRAMES_ALL),
1470
2101
  busyText: "正在抽取全部序列帧…",
@@ -1477,39 +2108,80 @@ window.__ModuleLoader__.load({
1477
2108
  on: allApproved,
1478
2109
  disabled: extracting,
1479
2110
  onClick: () => void start(() => api.setApproved({ projectId: project.id, stage: "frames", approved: !allApproved }), { reload: true })
1480
- }, allApproved ? "取消全部通过" : "全部标记通过"), h(BusyBadge, { show: extracting, text: tasks.label(KEY_FRAMES_ALL) ?? "正在抽帧…" })), h("div", { className: "SPR_grid" }, DIRECTIONS.map((direction) => {
2111
+ }, allApproved ? "取消全部通过" : "全部标记通过"), h(BusyBadge, { show: extracting, text: tasks.label(KEY_FRAMES_ALL) ?? "正在抽帧…" })), h("div", { className: "SPR_grid" }, DIRECTIONS.flatMap((direction) => {
1481
2112
  const node = project.frames?.[direction.key];
1482
2113
  const taskKey = KEY_FRAMES_ONE(direction.key);
1483
2114
  // 这一批还没轮到 / 产物还没出来的方向也要盖着。两条路:本地刚点下去
1484
2115
  // (批量 key 在远程调用返回后还会多留 700ms,覆盖「下一次轮询还没回来」
1485
2116
  // 的那一下),以及宿主任务表(整段任务都在)。已经报错的方向不盖,
1486
2117
  // 否则失败原因被遮罩挡住,看着像还在跑。
1487
- const queued = (tasks.has(KEY_FRAMES_ALL) || jobCovers(hostExtract, direction.key)) && node?.status !== "error";
1488
- const nodeBusy = node?.status === "running" || tasks.has(taskKey) || queued;
2118
+ const hostPick = hostJob(project, KEY_FRAMES_PICK(direction.key));
2119
+ const queued = (tasks.has(KEY_FRAMES_ALL) || jobCovers(hostExtract, direction.key) || jobCovers(hostPick, direction.key)) && node?.status !== "error";
2120
+ const nodeBusy = node?.status === "running" || tasks.has(taskKey) || tasks.has(KEY_FRAMES_PICK(direction.key)) || tasks.any(`frames:slot:${direction.key}:`) || queued;
1489
2121
  const overlayText = tasks.label(taskKey) ?? (queued ? batchLabel : undefined) ?? "正在抽取序列帧…";
1490
- return h("div", { key: direction.key, className: "SPR_node", "data-busy": nodeBusy ? "true" : undefined }, h("div", { className: "SPR_nodeTop" }, h("span", { className: "SPR_nodeTitle" }, direction.label), nodeBusy ? h(Chip, { kind: "running", text: "抽帧中" }) : h(StatusChip, { node })), node?.strip !== undefined
1491
- ? h(MediaBox, { overlay: nodeBusy, text: overlayText }, h("img", { className: "SPR_thumb", src: assetUrl(project, node.strip, node.updatedAt), alt: `${direction.label} 序列帧` }))
1492
- : h("div", { className: "SPR_thumbEmpty" }, nodeBusy ? "正在抽帧…" : "尚未抽帧"), nodeBusy ? h(BusyBadge, { show: true, text: overlayText }) : null, node?.duration !== undefined
1493
- ? h("span", { className: "SPR_refRow" }, `${node.frames?.length ?? 0} 帧 · 视频 ${node.duration.toFixed(2)} 秒`)
1494
- : null, node?.error !== undefined ? h("p", { className: "SPR_error" }, node.error) : null, h("div", { className: "SPR_btnRow" }, h(BusyBtn, {
1495
- primary: node?.status !== "ready",
1496
- busy: tasks.has(taskKey),
1497
- busyText: "正在抽帧…",
1498
- disabled: project.videos?.[direction.key]?.file === undefined,
1499
- onClick: () => void start(() => api.runFrames({ projectId: project.id, keys: [direction.key] }), { reload: true }, {
1500
- key: taskKey,
1501
- label: `正在抽取「${direction.label}」序列帧…`
1502
- })
1503
- }, node?.status === "ready" ? "重新抽帧" : "抽取"), h(Btn, {
1504
- on: node?.approved === true,
1505
- disabled: node?.status !== "ready",
1506
- onClick: () => void start(() => api.setApproved({
1507
- projectId: project.id,
1508
- stage: "frames",
1509
- key: direction.key,
1510
- approved: node?.approved !== true
1511
- }), { reload: true })
1512
- }, node?.approved === true ? "已通过" : "通过")));
2122
+ return [
2123
+ h("div", { key: direction.key, className: "SPR_node", "data-busy": nodeBusy ? "true" : undefined }, h("div", { className: "SPR_nodeTop" }, h("span", { className: "SPR_nodeTitle" }, direction.label), nodeBusy ? h(Chip, { kind: "running", text: "抽帧中" }) : h(StatusChip, { node })), node?.strip !== undefined
2124
+ ? h(MediaBox, { overlay: nodeBusy, text: overlayText }, h(ZoomableImage, {
2125
+ className: "SPR_thumb",
2126
+ src: assetUrl(project, node.strip, node.updatedAt),
2127
+ alt: `${direction.label} 序列帧`,
2128
+ caption: `${direction.label} · ${node.frames?.length ?? 0} 帧 · 视频 ${(node.duration ?? 0).toFixed(2)} 秒(点「×」/ 背景 / Esc 关闭)`
2129
+ }))
2130
+ : h("div", { className: "SPR_thumbEmpty" }, nodeBusy ? "正在抽帧…" : "尚未抽帧"), nodeBusy ? h(BusyBadge, { show: true, text: overlayText }) : null, node?.duration !== undefined
2131
+ ? h("span", { className: "SPR_refRow" }, `${node.frames?.length ?? 0} 帧 · 视频 ${node.duration.toFixed(2)} 秒`)
2132
+ : null, (node?.candidates?.frames?.length ?? 0) > 0
2133
+ ? h("span", { className: "SPR_refRow" }, `手动选帧 · ${node.candidates.picks?.length ?? 0} 个圆圈 / ${node.candidates.frames.length} 张候选`)
2134
+ : null, node?.error !== undefined ? h("p", { className: "SPR_error" }, node.error) : null, h("div", { className: "SPR_btnRow" }, h(BusyBtn, {
2135
+ primary: node?.status !== "ready",
2136
+ busy: tasks.has(taskKey),
2137
+ busyText: "正在抽帧…",
2138
+ disabled: project.videos?.[direction.key]?.file === undefined || tasks.has(KEY_FRAMES_PICK(direction.key)) || hostPick !== undefined,
2139
+ onClick: () => void start(() => api.runFrames({ projectId: project.id, keys: [direction.key] }), { reload: true }, {
2140
+ key: taskKey,
2141
+ label: `正在抽取「${direction.label}」序列帧…`
2142
+ })
2143
+ }, node?.status === "ready" ? "重新抽帧" : "抽取"), h(BusyBtn, {
2144
+ busy: tasks.has(KEY_FRAMES_PICK(direction.key)),
2145
+ busyText: "正在抽候选帧…",
2146
+ disabled: project.videos?.[direction.key]?.file === undefined || (nodeBusy && !tasks.has(KEY_FRAMES_PICK(direction.key))),
2147
+ onClick: () => {
2148
+ if (pickKey === direction.key) {
2149
+ setPickKey(null);
2150
+ return;
2151
+ }
2152
+ setPickKey(direction.key);
2153
+ setPickCount(null);
2154
+ const ready = (project.frames?.[direction.key]?.candidates?.frames?.length ?? 0) > 0;
2155
+ if (!ready) {
2156
+ void start(() => api.prepareFramePick({ projectId: project.id, key: direction.key }), { reload: true }, {
2157
+ key: KEY_FRAMES_PICK(direction.key),
2158
+ label: `正在抽取「${direction.label}」的候选帧…`
2159
+ });
2160
+ }
2161
+ }
2162
+ }, pickKey === direction.key ? "收起选帧" : (node?.candidates?.frames?.length ?? 0) > 0 ? "调整选帧" : "手动选帧"), h(Btn, {
2163
+ on: node?.approved === true,
2164
+ disabled: node?.status !== "ready",
2165
+ onClick: () => void start(() => api.setApproved({
2166
+ projectId: project.id,
2167
+ stage: "frames",
2168
+ key: direction.key,
2169
+ approved: node?.approved !== true
2170
+ }), { reload: true })
2171
+ }, node?.approved === true ? "已通过" : "通过"))),
2172
+ pickKey === direction.key
2173
+ ? h(FramePickPanel, {
2174
+ key: `${direction.key}-pick`,
2175
+ project,
2176
+ direction,
2177
+ api,
2178
+ start,
2179
+ tasks,
2180
+ countDraft: pickCount,
2181
+ setCountDraft: setPickCount
2182
+ })
2183
+ : null
2184
+ ].filter(Boolean);
1513
2185
  })));
1514
2186
  }
1515
2187
  // ── 阶段 4:合成整图 ─────────────────────────────────────────────────
@@ -1519,10 +2191,15 @@ window.__ModuleLoader__.load({
1519
2191
  function renderSheetStage(ctx) {
1520
2192
  const { project, settingsDraft, setSettingsDraft, saveSettings, start, api, tasks } = ctx;
1521
2193
  const draft = settingsDraft ?? project.settings ?? {};
2194
+ // 用户会问「第 3 步不是已经抠过了吗」,所以这里把两处抠像的分工讲清楚:
2195
+ // 第 3 步抠的是**每个方向的预览带**(顺手把整图也合出来),第 4 步在同样的
2196
+ // 帧缓存上重抠一遍,只是为了让上面那十个参数改完立刻生效、不必重新抽帧。
2197
+ // 两处读的是同一份 raw.bin、同一套参数,所以结果永远一致。
1522
2198
  const rowOrder = Array.isArray(draft.rowOrder) && draft.rowOrder.length > 0 ? draft.rowOrder : DIRECTION_KEYS;
1523
2199
  const framesReady = DIRECTION_KEYS.filter((key) => project.frames?.[key]?.status === "ready").length;
1524
2200
  // 合成整图是本地 CPU 重活,宿主侧会标 running;重抠像同样走这个状态。
1525
2201
  const composing = project.sheet?.status === "running" || tasks.has(KEY_SHEET_COMPOSE) || tasks.has(KEY_SHEET_REKEY);
2202
+ const keyed = project.sheet?.backgroundFraction;
1526
2203
  const composeLabel = tasks.label(KEY_SHEET_REKEY) ?? tasks.label(KEY_SHEET_COMPOSE) ?? "正在抠绿幕并合成整图…";
1527
2204
  const moveRow = (index, delta) => {
1528
2205
  const next = [...rowOrder];
@@ -1535,7 +2212,8 @@ window.__ModuleLoader__.load({
1535
2212
  setSettingsDraft({ ...draft, rowOrder: next });
1536
2213
  void saveSettings({ rowOrder: next });
1537
2214
  };
1538
- return h(React.Fragment, null, h("div", { className: "SPR_fields" }, h(NumField, {
2215
+ return h(React.Fragment, null, h("p", { className: "SPR_hint" }, "抠像在这里会**再跑一次**:第 3 步那次抠的是每个方向的预览带(顺便把整图合出来),这里重抠是为了让下面这些参数改完立刻生效——两次读的是同一份帧缓存(raw.bin)、同一套参数,所以结果一致。" +
2216
+ "改完参数会自动重新抠像并合成整图,不需要重新抽帧。"), h("div", { className: "SPR_fields" }, h(NumField, {
1539
2217
  label: "整图单格宽(px)",
1540
2218
  value: draft.cellWidth ?? 256,
1541
2219
  min: 16,
@@ -1659,11 +2337,16 @@ window.__ModuleLoader__.load({
1659
2337
  disabled: project.sheet?.status !== "ready" || composing,
1660
2338
  onClick: () => void start(() => api.setApproved({ projectId: project.id, stage: "sheet", approved: project.sheet?.approved !== true }), { reload: true })
1661
2339
  }, project.sheet?.approved === true ? "整图已通过" : "整图通过")), project.sheet?.error !== undefined ? h("p", { className: "SPR_error" }, project.sheet.error) : null, h("div", { style: { display: "flex", gap: 18, alignItems: "flex-start", flexWrap: "wrap" } }, h("div", { className: "SPR_rowOrder" }, h("span", { className: "SPR_fieldLabel" }, "行序(第 1 行在最上方)"), rowOrder.map((key, index) => h("div", { key: `${key}-${index}`, className: "SPR_rowOrderItem" }, h("span", { className: "SPR_rowOrderIdx" }, String(index + 1)), h("span", { className: "SPR_rowOrderName" }, LABEL_OF[key] ?? key), h("button", { type: "button", className: "SPR_miniBtn", disabled: index === 0 || composing, onClick: () => moveRow(index, -1) }, "↑"), h("button", { type: "button", className: "SPR_miniBtn", disabled: index === rowOrder.length - 1 || composing, onClick: () => moveRow(index, 1) }, "↓")))), h("div", { style: { flex: 1, minWidth: 300 } }, project.sheet?.file !== undefined
1662
- ? h(React.Fragment, null, h("p", { className: "SPR_hint" }, `输出 ${project.sheet.width}×${project.sheet.height} 像素 · 单格 ${draft.cellWidth}×${draft.cellHeight} · 每行 ${draft.frameCount ?? 8} 帧`), h("div", { className: "SPR_sheetWrap", style: { position: "relative" } }, h("img", {
2340
+ ? h(React.Fragment, null, h("p", { className: "SPR_hint" }, `输出 ${project.sheet.width}×${project.sheet.height} 像素 · 单格 ${draft.cellWidth}×${draft.cellHeight} · 每行 ${draft.frameCount ?? 8} 帧` +
2341
+ (keyed === undefined ? "" : ` · 抠掉的背景占 ${(keyed * 100).toFixed(1)}%`) +
2342
+ ((project.sheet?.borderSamplesDropped ?? 0) > 0
2343
+ ? ` · 边框采样排除了 ${project.sheet.borderSamplesDropped} 个不属于背景主色的点(角色贴边)`
2344
+ : "")), h("div", { className: "SPR_sheetWrap", style: { position: "relative" } }, h(ZoomableImage, {
1663
2345
  className: "SPR_sheet",
1664
2346
  src: assetUrl(project, project.sheet.file, project.sheet.generatedAt),
1665
2347
  alt: "整图",
1666
- style: { visibility: composing ? "hidden" : undefined }
2348
+ style: { visibility: composing ? "hidden" : undefined },
2349
+ caption: `整图 ${project.sheet.width}×${project.sheet.height} · 单格 ${draft.cellWidth}×${draft.cellHeight}(点「×」/ 背景 / Esc 关闭)`
1667
2350
  }), h(LoadingOverlay, { show: composing, text: composeLabel, sub: "本地抠像 + 合成,不上传" })))
1668
2351
  : h("div", { style: { position: "relative", minHeight: 160 } }, h("p", { className: "SPR_empty" }, composing ? "正在生成第一张整图…" : framesReady === 0 ? "请先完成第 3 步的抽帧" : "还没有合成整图"), h(LoadingOverlay, { show: composing, text: composeLabel })))));
1669
2352
  }
@@ -2437,7 +3120,13 @@ window.__ModuleLoader__.load({
2437
3120
  ? h("div", { className: "SPR_sheetWrap", style: { position: "relative" } }, h("img", { className: "SPR_sheet", src: `${job.assetBase}${job.sheet.file}?v=${job.sheet.updatedAt}`, alt: "序列帧条图", style: { visibility: composing ? "hidden" : undefined } }), h(LoadingOverlay, { show: composing, text: composeText }))
2438
3121
  : null, frameUrls.length === 0
2439
3122
  ? null
2440
- : h("div", { className: "SPR_frames" }, frameUrls.map((url, index) => h("img", { key: index, className: "SPR_frame", src: url, alt: `第 ${index + 1} 帧` })))), h("div", { className: "SPR_card" }, h("div", { className: "SPR_cardHead" }, h("h3", null, "⑤ 验收")), h("p", { className: "SPR_hint" }, "三步各自打「通过」。对话里的 agent 读写同一份标记:选「每一步人工审核」时,它会等你通过才继续。"), h(ReviewModeBar, { api, module: "sequence", id: job.id, mode: job.reviewMode, onChanged: () => void load(job.id) }), [
3123
+ : h("div", { className: "SPR_frames" }, frameUrls.map((url, index) => h(ZoomableImage, {
3124
+ key: index,
3125
+ className: "SPR_frame",
3126
+ src: url,
3127
+ alt: `第 ${index + 1} 帧`,
3128
+ caption: `第 ${index + 1} / ${frameUrls.length} 帧(点「×」/ 背景 / Esc 关闭)`
3129
+ })))), h("div", { className: "SPR_card" }, h("div", { className: "SPR_cardHead" }, h("h3", null, "⑤ 验收")), h("p", { className: "SPR_hint" }, "三步各自打「通过」。对话里的 agent 读写同一份标记:选「每一步人工审核」时,它会等你通过才继续。"), h(ReviewModeBar, { api, module: "sequence", id: job.id, mode: job.reviewMode, onChanged: () => void load(job.id) }), [
2441
3130
  { step: "video", title: "① 生成视频", node: job.video },
2442
3131
  { step: "frames", title: "② 抽帧 + 抠像", node: job.frames },
2443
3132
  { step: "sheet", title: "③ 横向条图", node: job.sheet }
@@ -5063,10 +5752,21 @@ window.__ModuleLoader__.load({
5063
5752
  revealProject: (payload) => call("revealProject", payload),
5064
5753
  runImage: (payload) => call("runImage", payload),
5065
5754
  runImages: (payload) => call("runImages", payload),
5755
+ setImageMode: (payload) => call("setImageMode", payload),
5756
+ runTurnVideo: (payload) => call("runTurnVideo", payload),
5757
+ runTurnFrames: (payload) => call("runTurnFrames", payload),
5758
+ setTurnPick: (payload) => call("setTurnPick", payload),
5759
+ setTurnPicks: (payload) => call("setTurnPicks", payload),
5760
+ resetTurnPicks: (payload) => call("resetTurnPicks", payload),
5761
+ cutTurnFrames: (payload) => call("cutTurnFrames", payload),
5066
5762
  runVideos: (payload) => call("runVideos", payload),
5067
5763
  pollVideos: (payload) => call("pollVideos", payload),
5068
5764
  clearVideos: (payload) => call("clearVideos", payload),
5069
5765
  runFrames: (payload) => call("runFrames", payload),
5766
+ prepareFramePick: (payload) => call("prepareFramePick", payload),
5767
+ setFramePick: (payload) => call("setFramePick", payload),
5768
+ setFramePicks: (payload) => call("setFramePicks", payload),
5769
+ resetFramePicks: (payload) => call("resetFramePicks", payload),
5070
5770
  rekey: (payload) => call("rekey", payload),
5071
5771
  compose: (payload) => call("compose", payload),
5072
5772
  listImageJobs: () => call("listImageJobs"),
@@ -5180,7 +5880,7 @@ window.__ModuleLoader__.load({
5180
5880
  bundleModule.exports.GAME_STUDIO_PANEL_ID = GAME_STUDIO_PANEL_ID;
5181
5881
  // 仅测试用把手:三个模块组件在工厂闭包里,脚本要能拿出来单独渲染
5182
5882
  // (见 scripts/verify-feedback.mjs)。运行时没有任何调用点。
5183
- bundleModule.exports.__test = { StudioPanel, ImageModule, SequenceModule, usePendingTasks, LoadingOverlay, MediaBox, BusyBtn, BusyBadge, CSS, subscribeIntent, parseIntents, openStudioIntent, OPEN_QUERY_KEY };
5883
+ bundleModule.exports.__test = { StudioPanel, ImageModule, SequenceModule, usePendingTasks, LoadingOverlay, MediaBox, BusyBtn, BusyBadge, NumField, ZoomableImage, CSS, subscribeIntent, parseIntents, openStudioIntent, OPEN_QUERY_KEY };
5184
5884
  return bundleModule.exports;
5185
5885
  }
5186
5886
  });