+
+
+
+
+ {p.list.length} / {MAX_LOCAL_ADJUSTMENTS}
+
+
+
+
+
+ {p.list.length === 0 ? (
+
+ {t(
+ "範囲を選んで、そこだけに補正を掛けます。「円形を追加」で始めるか、プリセットを選んでください。",
+ "Select an area to adjust only that part. Add an ellipse or choose a preset to begin.",
+ )}
+
+ ) : (
+
+ {p.list.map((l, i) => (
+ -
+
+
+
+
+ ))}
+
+ )}
+ {selected && selected.mask.kind !== "ellipse" && (
+
+
+
+ {t("キャンバスをなぞって範囲を塗る", "Paint an area on the canvas")}
+
+
+ {(
+ [
+ ["add", "塗る"],
+ ["erase", "消す"],
+ ] as const
+ ).map(([mode, label]) => (
+
+ ))}
+
+
`${v}%`}
+ onPreview={(v) => p.onBrush({ ...p.brush, size: v / 100 })}
+ onCommit={(v) => p.onBrush({ ...p.brush, size: v / 100 })}
+ />
+ `${v}%`}
+ onPreview={(v) => p.onBrush({ ...p.brush, hardness: v / 100 })}
+ onCommit={(v) => p.onBrush({ ...p.brush, hardness: v / 100 })}
+ />
+
+ )}
+
+
+ {selected
+ ? t("選択中の範囲に適用", "Apply to selected area")
+ : p.onAuto
+ ? t(
+ "瞳・美肌は顔を認識して置き、装備は画像をタップして切り抜きます",
+ "Eyes and skin use face detection; tap the image to select gear.",
+ )
+ : t(
+ "新しいマスクを追加して適用 (瞳・美肌は円形、装備はブラシ)",
+ "Add a new mask (ellipse for eyes or skin, brush for gear)",
+ )}
+
+
+ {LOCAL_PRESETS.map((preset) => (
+
+ ))}
+
+ {p.onAuto && selected && (
+
+
+ {t("自動選択で追加:", "Add with auto selection:")}
+
+ {LOCAL_PRESETS.map((preset) => (
+
+ ))}
+
+ )}
+ {p.onAuto && (
+
+
+ {t("タップで範囲だけ選ぶ:", "Select an area by tapping:")}
+
+
+
+
+ )}
+ {p.tap && (
+
+ {t(
+ `画像の中の${p.tap === "gear" ? "装備" : "キャラクター"}をタップしてください`,
+ `Tap the ${p.tap === "gear" ? "gear" : "character"} in the image`,
+ )}
+
+
+ )}
+ {selected && p.segment?.localId === selected.id && p.onSegmentLevel && (
+
+
+ {t("切り抜きの範囲:", "Selection scope:")}
+
+ {SAM_LEVELS.map((level) => (
+
+ ))}
+
+ )}
+ {busy && (
+
+ {p.inference.status === "loading" && p.inference.progress
+ ? t(
+ `認識用のデータを読み込んでいます (${Math.round((p.inference.progress.loaded / p.inference.progress.total) * 100)}%)`,
+ `Loading detection data (${Math.round((p.inference.progress.loaded / p.inference.progress.total) * 100)}%)`,
+ )
+ : p.inference.status === "loading"
+ ? t("認識の準備をしています…", "Preparing detection…")
+ : t("画像を読み取っています…", "Analyzing image…")}
+
+ )}
+ {p.notice && !busy && (
+
+ {tx(p.notice)}
+
+ )}
+
+ {selected && (
+
+ p.onAmountPreview(selected.id, v)}
+ onCommit={(v) => p.onAmountCommit(selected.id, v)}
+ onReset={() => p.onAmountCommit(selected.id, 100)}
+ />
+ {ROWS.map((r) => (
+ `${v >= 0 ? "+" : ""}${v.toFixed(2)}`
+ : r.key === "blur"
+ ? (v) => `${v}px`
+ : (v) => `${v > 0 ? "+" : ""}${v}`
+ }
+ onPreview={(v) => p.onAdjustPreview(selected.id, r.key, v)}
+ onCommit={(v) => p.onAdjustCommit(selected.id, r.key, v)}
+ onReset={() => p.onAdjustCommit(selected.id, r.key, 0)}
+ />
+ ))}
+
+ )}
+
+ );
+}
diff --git a/packages/editor-react/src/PortraitPanel.tsx b/packages/editor-react/src/PortraitPanel.tsx
new file mode 100644
index 0000000..06da812
--- /dev/null
+++ b/packages/editor-react/src/PortraitPanel.tsx
@@ -0,0 +1,165 @@
+import { PORTRAIT_PRESETS, type PortraitPresetId } from "@lumorphia/editor-recipe";
+import type { FaceResult } from "@lumorphia/editor-engine";
+import type { InferenceStatus } from "@lumorphia/editor-engine";
+import { Slider } from "./Slider.tsx";
+import { useEditorI18n } from "./EditorI18n.tsx";
+
+type Props = {
+ faces: readonly FaceResult[] | null;
+ selectedFace: number;
+ groupId: string | null;
+ presetId: PortraitPresetId | null;
+ /** グループの効果量 0..100 */
+ amount: number;
+ inference: InferenceStatus;
+ notice: string | null;
+ onDetect: () => void;
+ onSelectFace: (index: number) => void;
+ onApply: (presetId: PortraitPresetId) => void;
+ onAmountPreview: (value: number) => void;
+ onAmountCommit: (value: number) => void;
+ /** 部分補正タブへ (自動で置いた 5 件を個別に直す) */
+ onGoLocal: () => void;
+};
+
+const btn =
+ "rounded border border-line-soft px-2 py-1 text-xs hover:bg-surface-hover disabled:opacity-40 disabled:hover:bg-transparent";
+
+/**
+ * 人物補正 (#175): 人物を検出 → (複数なら) 選ぶ → プリセット → 効果量。
+ * 中身は部分補正 5 件 (背景・人物・顔・瞳 ×2) で、部分補正タブで個別に直せる
+ */
+export function PortraitPanel(p: Props) {
+ const { t, tx } = useEditorI18n();
+ const busy = p.inference.status !== "idle";
+ const faces = p.faces ?? [];
+ return (
+
+
+ {t(
+ "人物を認識して、顔・瞳・人物・背景をまとめて整えます。認識も補正もこの端末の中だけで行います。",
+ "Detect a person and adjust their face, eyes, body, and background together. Detection and editing stay on this device.",
+ )}
+
+ {p.faces === null ? (
+
+ ) : faces.length === 0 ? (
+
+ {p.notice
+ ? tx(p.notice)
+ : t(
+ "自動選択できませんでした。手動で範囲を指定できます",
+ "Automatic selection failed. You can select an area manually.",
+ )}
+
+
+ ) : (
+ <>
+ {faces.length > 1 && (
+
+ {t("補正する人物:", "Person:")}
+ {faces.map((_, i) => (
+
+ ))}
+
+ {t(
+ "(画像の番号をタップしても選べます)",
+ "(You can also tap a number on the image)",
+ )}
+
+
+ )}
+
+
+ {p.groupId
+ ? t("プリセットを切り替える", "Switch preset")
+ : t("プリセットを選ぶと補正を置きます", "Choose a preset to apply adjustments")}
+
+
+ {PORTRAIT_PRESETS.map((preset) => (
+
+ ))}
+
+
+ {p.groupId && (
+
+
p.onAmountCommit(100)}
+ />
+
+ {t(
+ "顔・瞳・人物・背景のマスクは",
+ "Edit the face, eyes, person, and background masks under",
+ )}{" "}
+
+ {t(
+ "で個別に直せます (ブラシで足す / 消す、値の調整)。",
+ " (paint, erase, or adjust individual values).",
+ )}
+
+
+ )}
+ >
+ )}
+ {busy && (
+
+ {p.inference.status === "loading" && p.inference.progress
+ ? t(
+ `認識用のデータを読み込んでいます (${Math.round((p.inference.progress.loaded / p.inference.progress.total) * 100)}%)`,
+ `Loading detection data (${Math.round((p.inference.progress.loaded / p.inference.progress.total) * 100)}%)`,
+ )
+ : p.inference.status === "loading"
+ ? t("認識の準備をしています…", "Preparing detection…")
+ : t("人物を認識しています…", "Detecting people…")}
+
+ )}
+ {p.notice && !busy && faces.length > 0 && (
+
+ {tx(p.notice)}
+
+ )}
+
+ );
+}
diff --git a/packages/editor-react/src/PresetPanel.tsx b/packages/editor-react/src/PresetPanel.tsx
new file mode 100644
index 0000000..b6d7473
--- /dev/null
+++ b/packages/editor-react/src/PresetPanel.tsx
@@ -0,0 +1,34 @@
+import { PRESETS } from "@lumorphia/editor-recipe";
+import { useEditorI18n } from "./EditorI18n.tsx";
+
+type Props = {
+ activeId: string | null;
+ onApply: (id: string) => void;
+};
+
+export function PresetPanel({ activeId, onApply }: Props) {
+ const { tx } = useEditorI18n();
+ return (
+
+ {PRESETS.map((p) => {
+ const active = p.id === activeId;
+ return (
+
+ );
+ })}
+
+ );
+}
diff --git a/packages/editor-react/src/Slider.tsx b/packages/editor-react/src/Slider.tsx
new file mode 100644
index 0000000..c0a0c50
--- /dev/null
+++ b/packages/editor-react/src/Slider.tsx
@@ -0,0 +1,91 @@
+import { useId } from "react";
+
+type Props = {
+ label: string;
+ value: number;
+ min: number;
+ max: number;
+ step: number;
+ format?: (v: number) => string;
+ onPreview: (v: number) => void;
+ onCommit: (v: number) => void;
+ onReset?: () => void;
+};
+
+/**
+ * 補正用スライダー。ドラッグ中は onPreview、離したら onCommit (docs/design/04 §3)。
+ * キーボード操作は矢印で step、Shift+矢印で 10 step (docs/design/08 §6)。
+ */
+export function Slider({
+ label,
+ value,
+ min,
+ max,
+ step,
+ format,
+ onPreview,
+ onCommit,
+ onReset,
+}: Props) {
+ const id = useId();
+ const text = format ? format(value) : String(value);
+ return (
+ {
+ if (e.button !== 0) return;
+ e.preventDefault();
+ const host = e.currentTarget.getBoundingClientRect();
+ const canvas = {
+ x: (e.clientX - host.left - view.x) / view.scale,
+ y: (e.clientY - host.top - view.y) / view.scale,
+ };
+ const uv = canvasToImageUv(canvas, source, geometry);
+ if (uv.x < 0 || uv.x > 1 || uv.y < 0 || uv.y > 1) return;
+ onTap(uv);
+ }}
+ >
+
+ {hint} {t("(Esc でやめる)", "(press Esc to cancel)")}
+
+
+ );
+}
diff --git a/packages/editor-react/src/crop-drag.test.ts b/packages/editor-react/src/crop-drag.test.ts
new file mode 100644
index 0000000..0a9c35e
--- /dev/null
+++ b/packages/editor-react/src/crop-drag.test.ts
@@ -0,0 +1,36 @@
+import { describe, expect, it } from "vitest";
+import { dragCrop } from "./crop-drag.ts";
+
+const full = { x: 0, y: 0, w: 1, h: 1 };
+const mid = { x: 0.25, y: 0.25, w: 0.5, h: 0.5 };
+
+describe("dragCrop", () => {
+ it("moves within bounds", () => {
+ expect(dragCrop(mid, "move", 0.1, -0.1)).toEqual({ x: 0.35, y: 0.15, w: 0.5, h: 0.5 });
+ expect(dragCrop(mid, "move", 1, 1)).toEqual({ x: 0.5, y: 0.5, w: 0.5, h: 0.5 });
+ });
+
+ it("resizes from the east edge without moving the west edge", () => {
+ const r = dragCrop(mid, "e", 0.1, 0);
+ expect(r.x).toBe(0.25);
+ expect(r.w).toBeCloseTo(0.6);
+ });
+
+ it("keeps a minimum size", () => {
+ const r = dragCrop(mid, "e", -1, 0);
+ expect(r.w).toBeCloseTo(0.05);
+ });
+
+ it("locks ratio when resizing a corner", () => {
+ const r = dragCrop(full, "se", -0.5, 0, 1);
+ expect(r.w).toBeCloseTo(r.h);
+ expect(r.x).toBe(0);
+ expect(r.y).toBe(0);
+ });
+
+ it("locked ratio never exceeds the canvas", () => {
+ const r = dragCrop({ x: 0.5, y: 0.5, w: 0.4, h: 0.4 }, "se", 0.5, 0.5, 1);
+ expect(r.x + r.w).toBeLessThanOrEqual(1 + 1e-9);
+ expect(r.y + r.h).toBeLessThanOrEqual(1 + 1e-9);
+ });
+});
diff --git a/packages/editor-react/src/crop-drag.ts b/packages/editor-react/src/crop-drag.ts
new file mode 100644
index 0000000..1a5c594
--- /dev/null
+++ b/packages/editor-react/src/crop-drag.ts
@@ -0,0 +1,73 @@
+import type { GeometryV1 } from "@lumorphia/editor-recipe";
+
+export type Crop = NonNullable