Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbec20633e | ||
|
|
8b82a3103d | ||
|
|
d70905d032 |
@@ -1,5 +1,293 @@
|
||||
# DEVLOG - ComfyUI-Workflow-Studio
|
||||
|
||||
---
|
||||
|
||||
## 計画: Image Edit 拡張 — ABRブラシ連携 + Mask Editor One 統合
|
||||
|
||||
**方針**: Mask Editor One(同作者)のインストールを前提に、WFS Image Edit タブに2つの拡張を加える。
|
||||
|
||||
### フェーズ1: Draw ツール — ABRブラシ対応
|
||||
|
||||
#### 概要
|
||||
WFS の Draw ツール(`DrawTool.js`)に画像ブラシ(PNG スタンプ)描画機能を追加する。
|
||||
ブラシデータは Mask Editor One の API エンドポイントを介して取得・管理する。
|
||||
|
||||
#### バックエンド(Mask Editor One API 共用)
|
||||
Mask Editor One がインストールされていれば以下のエンドポイントが利用可能:
|
||||
|
||||
| エンドポイント | 用途 |
|
||||
|---------------|------|
|
||||
| `GET /mask_editor/brushes/list` | フォルダツリー + ブラシ一覧取得 |
|
||||
| `GET /mask_editor/brushes/raw?path=…` | ブラシ PNG 画像をサーブ |
|
||||
| `POST /mask_editor/brushes/import` | PNG フォルダ一括インポート |
|
||||
| `POST /mask_editor/brushes/upload_abr` | ABR ファイルインポート(パーサーは Mask Editor One 側) |
|
||||
|
||||
ブラシの格納先は Mask Editor One のフォルダ(`comfyui-mask-editor-one/brushes/`)を共用。
|
||||
一度インポートすれば WFS / Mask Editor One の両方で同じブラシが使える。
|
||||
|
||||
#### フロントエンド変更
|
||||
|
||||
**`DrawTool.js`**
|
||||
- `brushType: "soft"` | `"image"` プロパティ追加
|
||||
- `imageBrush: { canvas, width, height }` — スタンプ用 OffscreenCanvas をキャッシュ
|
||||
- `_stamp()` を改修: `"image"` モード時は `ctx.drawImage(stamp)` で描画(Jitter は phase 2 以降)
|
||||
- サイズは `brushSize` を高さ基準に、アスペクト比を維持してスケーリング
|
||||
|
||||
**Image Edit タブ (`image-edit-tab.js`)**
|
||||
- Draw ツール Options パネルに「Brush Library」ボタンを追加
|
||||
- Mask Editor One 未検出時はボタンをグレーアウト + ツールチップ表示
|
||||
|
||||
**ブラシライブラリ UI(新規モーダルまたはサイドパネル)**
|
||||
- Mask Editor One API 未応答時は「Mask Editor One が必要です」メッセージ
|
||||
- 応答時: フォルダツリー + ブラシサムネイルグリッド表示
|
||||
- クリックでブラシを選択 → `DrawTool` に適用
|
||||
- Import Folder / Import ABR ボタン(Mask Editor One の import エンドポイントを呼ぶ)
|
||||
|
||||
#### Mask Editor One 検出ロジック
|
||||
```javascript
|
||||
// /mask_editor/brushes/list に HEAD または GET を投げて 200 なら存在確認
|
||||
async function detectMaskEditorOne() {
|
||||
try {
|
||||
const r = await fetch("/mask_editor/brushes/list");
|
||||
return r.ok;
|
||||
} catch { return false; }
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### フェーズ2: Mask Editor One 連携ボタン
|
||||
|
||||
#### 概要
|
||||
WFS Image Edit タブのツールバーまたは Mask ツールのオプションパネルに
|
||||
「Mask Editor で開く」ボタンを追加する。
|
||||
現在のキャンバスレイヤーを画像として Mask Editor One に渡し、編集結果を WFS に戻す。
|
||||
|
||||
#### 実装ポイント
|
||||
- WFS のキャンバス合成画像 (`_exportComposite()`) を Blob として取得
|
||||
- Mask Editor One の `/mask_editor/store_image` に POST してキャッシュ
|
||||
- Mask Editor One のモーダルを JavaScript から起動(`window.maskEditorOpen()` など)
|
||||
- Apply 後のコールバックで Mask Editor One の結果マスク PNG を取得
|
||||
- WFS の mask レイヤーとして追加
|
||||
|
||||
#### Mask Editor One 未インストール時
|
||||
- ボタンを非表示(検出ロジックで判定)
|
||||
|
||||
---
|
||||
|
||||
### 変更ファイル予定
|
||||
|
||||
| ファイル | 変更内容 |
|
||||
|---------|---------|
|
||||
| `static/js/image-edit/DrawTool.js` | 画像ブラシ描画対応 |
|
||||
| `static/js/image-edit-tab.js` | Brush Library ボタン・Mask Editor 連携ボタン |
|
||||
| `static/js/image-edit/BrushLibrary.js` | 新規: ブラシライブラリモーダル UI |
|
||||
| `py/routes/` | 不要(Mask Editor One API を直接利用) |
|
||||
| `static/css/main.css` | ブラシライブラリ UI スタイル |
|
||||
| `static/js/i18n.js` | ブラシ関連 i18n キー追加 |
|
||||
| `templates/index.html` | 不要(動的生成) |
|
||||
|
||||
---
|
||||
|
||||
### 実装順序
|
||||
1. `DrawTool.js` に画像ブラシ描画機能を追加(スタンプモード)
|
||||
2. Mask Editor One 検出ロジックを実装
|
||||
3. `BrushLibrary.js` 新規作成(ライブラリモーダル UI)
|
||||
4. Draw ツール Options パネルに Brush Library ボタンを接続
|
||||
5. フェーズ2: Mask Editor 連携ボタンを追加
|
||||
|
||||
---
|
||||
|
||||
## 2026-06-29: v0.3.65 — Mask Editor One 連携修正・トップバーアイコン修正・Mask ABRブラシ対応
|
||||
|
||||
**変更ファイル**: `static/js/image-edit-tab.js`, `static/js/image-edit/MaskTool.js`, `web/comfyui/top_menu_extension.js`, `custom_nodes/comfyui-mask-editor-one/server.py`(インストール済み)
|
||||
|
||||
**Mask Editor One 対応バージョン**: v0.1.9+(BiRefNet / SAM3 / ABRブラシライブラリ連携)
|
||||
|
||||
### 概要
|
||||
|
||||
Mask Editor One の仕様変更に伴う連携修正、プロパティパネル開閉によるトップバーアイコン消滅バグの修正、および Mask ツールへの ABR ブラシサポート追加。
|
||||
|
||||
---
|
||||
|
||||
### Mask Editor One 連携修正(BiRefNet / SAM3)
|
||||
|
||||
#### 問題
|
||||
Mask Editor One の `store_image` API エンドポイントがフィールド名を `image_b64` から `bg_image_b64` に変更(仕様変更)したが、WFS 側が追随していなかったため、BiRefNet・SAM3 推論時に「no image available for this node」エラーが発生。
|
||||
|
||||
#### 修正内容
|
||||
- **`image-edit-tab.js`**: SAM3・BiRefNet の `store_image` 呼び出しで `image_b64` → `bg_image_b64` に修正(2箇所)
|
||||
- **`server.py`(インストール済み)**: `store_image` エンドポイントが `bg_image_b64` と旧キー `image_b64` の両方を受け付けるよう後方互換対応を追加
|
||||
|
||||
```python
|
||||
# Before
|
||||
entry["bg_image_b64"] = data.get("bg_image_b64")
|
||||
|
||||
# After
|
||||
img = data.get("bg_image_b64") or data.get("image_b64")
|
||||
entry["bg_image_b64"] = img
|
||||
```
|
||||
|
||||
> **Mask Editor One リポジトリ側**: 開発元 `server.py` にも同修正を適用済み。PR 時に含めること。
|
||||
|
||||
---
|
||||
|
||||
### トップバーアイコン消滅バグ修正(MutationObserver 追加)
|
||||
|
||||
#### 問題
|
||||
サブグラフノード選択時などにプロパティパネルを開くと、Vue がアクションバーを再レンダリングし、WFS・Snapshot・Node Sets のカスタム SVG アイコンが `<i>` タグにリセットされて消滅する([ComfyUI-Lora-Manager #996](https://github.com/willmiao/ComfyUI-Lora-Manager/issues/996) と同根)。
|
||||
|
||||
#### 修正内容(`top_menu_extension.js`)
|
||||
- `replaceButtonIcons` を `applyIconToButton` + `pollUntilFound` に分割
|
||||
- SVG が既存の場合はスキップ(`btn.querySelector("svg")` チェック)
|
||||
- `MutationObserver` を追加して Vue 再レンダリング後も即座に SVG を再適用
|
||||
- `btn.querySelector("i")` で `<i>` リセットを検知 → `applyIconToButton` 再実行
|
||||
- 監視ノード: `[data-testid="action-bar-buttons"]` → `.actionbar-container` → `document.body`(フォールバック順)
|
||||
- Observer 参照を `window.__wfmIconObserver` に保持
|
||||
|
||||
```javascript
|
||||
// 旧: 一度だけ適用、Vue 再レンダリングで消滅
|
||||
const replaceButtonIcons = () => { ... btn.innerHTML = cfg.getIcon(); };
|
||||
|
||||
// 新: MutationObserver で監視・再適用
|
||||
const applyIconToButton = (btn, cfg) => {
|
||||
if (btn.querySelector("svg")) return; // 既存なら skip
|
||||
btn.innerHTML = cfg.getIcon();
|
||||
...
|
||||
};
|
||||
observer.observe(watchNode, { childList: true, subtree: true });
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Mask ツール — ABRブラシ対応(Mask Editor One オプション)
|
||||
|
||||
Mask Editor One がインストールされている場合のみ有効。未インストール時は従来の円形ブラシのみで動作(機能維持)。
|
||||
|
||||
#### MaskTool.js 変更
|
||||
|
||||
| 追加プロパティ | 説明 |
|
||||
|---|---|
|
||||
| `brushImage` / `brushName` | ABR 画像ブラシ(null = デフォルト円形) |
|
||||
| `spacing` (0.05–1.0) | スタンプ間隔(ブラシサイズの倍率) |
|
||||
| `angle` (0–359°) | ブラシ固定回転角 |
|
||||
| `sizeJitter` / `sizeJitterAmount` | スタンプごとのサイズランダム変動 |
|
||||
| `rotationJitter` | スタンプごとの角度ランダム変動 (0–360°) |
|
||||
|
||||
- `setImageBrush(img, name)` / `clearImageBrush()` メソッド追加
|
||||
- **ストロークバッファ**: `_initStrokeBuffer` / `_mergeStroke` — PaintTool.js と同パターンで intra-stroke 蓄積を防止(`lighten` ブレンド)
|
||||
- `_getImageStamp()`: アルファチャンネル自動判定(ABR 透過 PNG 対応、グレースケール PNG は輝度から逆算)
|
||||
- `_paintImageBrush()`: `angle` 非ゼロ時に translate + rotate で描画
|
||||
- `_paintToStroke()`: Jitter 有効時は各スタンプに適用後、状態をリストア(PaintTool.js 同様)
|
||||
|
||||
#### image-edit-tab.js 変更
|
||||
|
||||
**初期化**
|
||||
- `_abrAvailable`、`_abrBrushTree` を追加
|
||||
- 起動時に `_checkAbrAvailability()` を非同期実行(`/mask_editor/brushes/list` が空でなければ有効)
|
||||
|
||||
**プロパティパネル(Paint サブツール)**
|
||||
|
||||
```
|
||||
Mode [Add] [Erase]
|
||||
Size ━━━━━━ 30px
|
||||
Hardness ━━━━━━ 85% ← ABRブラシ選択中は disabled
|
||||
─── MASK EDITOR ONE ───
|
||||
Brush Circle [Select] [✕]
|
||||
↓ ブラシ選択後
|
||||
Spacing ━━━━━━ 25%
|
||||
Angle ━━━━━━ 0°
|
||||
Sz Jitter━━━━━━ 50%
|
||||
Rot. Jitter □ On
|
||||
```
|
||||
|
||||
- **Select ボタン**: ABR ブラシライブラリピッカーモーダルを開く
|
||||
- **✕ ボタン**: Circle(デフォルト)に戻す(ブラシ選択中のみ表示)
|
||||
- ABR セクションは Mask Editor One インストール済みの場合のみ表示
|
||||
|
||||
**ABR ブラシライブラリピッカー** (`_openAbrBrushPicker()`)
|
||||
- フォルダツリー(左)+ブラシサムネイルグリッド(右)のモーダル
|
||||
- サムネイル生成: BrushLibrary.js と同ロジック(アルファ判定・輝度変換・タイトルトリム)
|
||||
- 「Round Brush (default)」ボタンでリセット
|
||||
- ブラシクリック → `setImageBrush()` 適用後モーダル閉じる
|
||||
|
||||
---
|
||||
|
||||
## 2026-06-28: v0.3.64 — Image Edit マスク Add/Subtract・BiRefNet BG Remove・SAM3 セグメンテーション・ブラシカーソルバグ修正
|
||||
|
||||
**変更ファイル**: `static/js/image-edit-tab.js`, `static/js/image-edit/LayerManager.js`
|
||||
|
||||
### 概要
|
||||
|
||||
Image Edit タブのマスク機能を強化。Mask Editor One インストール済み環境向けに BiRefNet 背景削除と SAM3 テキストプロンプトセグメンテーションを追加。また独立機能としてマスクレイヤーの合成モード(Add/Subtract)を実装。
|
||||
|
||||
---
|
||||
|
||||
### マスクレイヤー Add/Subtract 合成モード
|
||||
|
||||
#### LayerManager.js
|
||||
- `Layer` クラスに `operation: "add"` プロパティ追加(`maskApply` 用)
|
||||
- `toJSON()` / `fromJSON()` で保存・復元対応
|
||||
- `LayerManager.toggleOperation(id)` メソッド追加(add ⇔ subtract トグル)
|
||||
|
||||
#### image-edit-tab.js — レイヤーパネル
|
||||
- マスクレイヤー行に **A/S トグルボタン** を追加(緑=Add、赤=Subtract)
|
||||
- クリックで `toggleOperation()` を呼び出し、合成ビューと一覧を再描画
|
||||
- マスクレイヤー選択時、`operation` に合わせて MaskTool の `mode` を自動同期(subtract → erase)
|
||||
|
||||
#### image-edit-tab.js — `_updateCompositeView()` 改修
|
||||
- 連続する `maskApply: true` マスクレイヤーをグループとして検出
|
||||
- グループを back→front 順で合成(Mask Editor One `CanvasCompositor` と同ロジック)
|
||||
- `add` → `globalCompositeOperation = "lighten"`
|
||||
- `subtract` → `globalCompositeOperation = "destination-out"`
|
||||
- 合成マスクでターゲットレイヤーを `destination-in` でクリップ
|
||||
- バグ修正: `maskApply=true` マスクが layers 末尾(ターゲットなし)の場合にオーバーレイ表示のみにフォールバック
|
||||
|
||||
---
|
||||
|
||||
### BG Remove — BiRefNet(Mask Editor One 連携)
|
||||
|
||||
- BG Remove ツール起動時に `/mask_editor/birefnet/status` を確認
|
||||
- Mask Editor One 未インストール時: BiRefNet オプションを `disabled`("Mask Editor One required" 表示)
|
||||
- インストール済み時: BiRefNet 選択可能
|
||||
- 実行フロー:
|
||||
1. `store_image` でアクティブレイヤー画像を Mask Editor One キャッシュに送信(`node_id: "wfs_bgremove"`)
|
||||
2. `birefnet/remove_bg` で推論
|
||||
3. グレースケールマスク(白=前景)→ RGBA PNG に変換(`_applyMaskToImage()`)
|
||||
4. 既存の BG Remove フロー(New Layer / 上書き)で結果を適用
|
||||
|
||||
---
|
||||
|
||||
### SAM3 セグメンテーション(Mask Editor One 連携)
|
||||
|
||||
- Mask ツールの上部メニューに **[SAM3] ボタン**を追加(Paint の隣)
|
||||
- 起動時に `/mask_editor/sam3/status` を確認して有効/無効を制御
|
||||
|
||||
#### SAM3 モードの上部メニュー
|
||||
| 要素 | 説明 |
|
||||
|------|------|
|
||||
| テキスト入力 | セグメント対象のプロンプト("cat", "person" 等) |
|
||||
| Max セレクト | 最大マスク取得数(3/6/9/12) |
|
||||
| Segment ボタン | 推論実行 |
|
||||
|
||||
#### プロパティペイン(SAM3)
|
||||
| 要素 | 説明 |
|
||||
|------|------|
|
||||
| Mode: Add/Erase | 適用モード切り替え |
|
||||
| サムネイルグリッド | 候補マスクをクリックで選択/解除(青ボーダー + ✓ マーク) |
|
||||
| Apply Selected (N) | 選択マスクをまとめて適用 |
|
||||
|
||||
#### 実行フロー
|
||||
1. `store_image` でイメージレイヤーを送信(`node_id: "wfs_sam3"`)
|
||||
2. `sam3/segment` で推論 → 複数マスク候補をプロパティペインに表示
|
||||
3. サムネイルをクリックして複数選択(新規 Segment 時に選択リセット)
|
||||
4. Apply Selected でまとめて合成適用
|
||||
- Add → `source-over`(既存マスクに重ね塗り)
|
||||
- Erase → `destination-out`(既存マスクから消去)
|
||||
5. アクティブレイヤーがマスクでない場合は新規マスクレイヤーを自動作成
|
||||
|
||||
---
|
||||
|
||||
## 2026-06-28: v0.3.63 — ノードタブ複数選択・全タブフィルタークリア・検索Xボタン
|
||||
|
||||
**変更ファイル**: `static/js/nodes-tab.js`, `static/js/workflow-tab.js`, `static/js/models-tab.js`, `static/js/gallery-tab.js`, `static/js/util.js`, `static/js/i18n.js`, `static/css/main.css`, `templates/index.html`
|
||||
|
||||
@@ -18,7 +18,7 @@ A comprehensive workflow, asset management, and generation UI plugin for [ComfyU
|
||||
- Built-in AI tools (translation and more)
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Screenshots
|
||||
|
||||
@@ -225,7 +225,7 @@ Two independent modes selectable via **[Image Loop] / [Gallery]** toggle buttons
|
||||
- **DB tab** — searchable SQLite database of all tagged images; click a row to open the edit panel and modify WD Tags / VLM Tags; Save updates the record, Delete removes it; Export CSV downloads all records
|
||||
- **Dependencies** — install into ComfyUI's embedded Python: `python_embedded\python.exe -m pip install -r requirements.txt`; for GPU inference use `onnxruntime-gpu`; TensorFlow (DeepDanbooru) is optional and commented out in `requirements.txt`
|
||||
|
||||
### Image Edit Tab (v0.3.61)
|
||||
### Image Edit Tab (v0.3.65)
|
||||
- **Layer-based image editor** — compose images with multiple layers (Image, Text, Draw, Mask types) and export the composite as PNG
|
||||
- **Loading images** — drag & drop onto the canvas, Upload button, or send from the Gallery tab via the **Image Edit** toolbar button; first image becomes Layer 1 (auto-locked), subsequent images are added as new layers scaled to fit the canvas
|
||||
- **New button** — create a blank canvas with custom dimensions (WxH prompt); clears all existing layers
|
||||
@@ -234,9 +234,9 @@ Two independent modes selectable via **[Image Loop] / [Gallery]** toggle buttons
|
||||
- **Draw** — freehand brush; options: color, brush size, blend mode; paints directly onto the active draw layer while all other layers remain visible; brush cursor shown as a size-accurate circle; strokes can start from outside the canvas margin and continue past the edge
|
||||
- **Text** — click to place; configure font, size, bold/italic, align, and color; placed as an exact-size text layer sized to the measured bounding box; double-click to re-edit
|
||||
- **Shape** — drag to draw geometric shapes (Rect / Ellipse / Line / FreeLine); options: shape type, Rounded toggle (Rect/Ellipse), Fill color, Stroke color + width, Opacity; each committed shape becomes an independent draw layer; Stroke None hidden for Line/FreeLine (stroke always active)
|
||||
- **Mask** — paint a white mask onto a dedicated mask layer; click **M** in the Layers header to add a mask layer (Mask tool activates automatically); clicking a mask layer in the list also switches to the Mask tool; **Tool Options bar**: Paint sub-tool button, Invert checkbox, Overlay color picker (default red), Blur slider (0–50 px); **Properties pane** (left of the Layers panel): Size (1–200 px), Hardness (0–100%), Mode — **Add** (draw white = mask present) / **Erase** (erase to transparent = mask absent); **✂ button** on the layer row enables/disables the mask as a clipping mask — when enabled (blue), the layer directly below is clipped to the painted area and the result is applied when exporting; brush cursor shown as a size-accurate circle; strokes can start from outside the canvas margin and continue past the edge
|
||||
- **Mask** — paint a white mask onto a dedicated mask layer, or use SAM3 text-prompt segmentation (requires Mask Editor One); click **M** in the Layers header to add a mask layer (Mask tool activates automatically); clicking a mask layer in the list also switches to the Mask tool; **Tool Options bar**: Paint / SAM3 sub-tool buttons, Invert checkbox, Overlay color picker (default red), Blur slider (0–50 px); SAM3 button disabled when Mask Editor One is not installed; **Properties pane — Paint mode**: Mode (Add / Erase), Size (1–200 px), Hardness (0–100%); **MASK EDITOR ONE section** (visible when Mask Editor One is installed): Select opens the ABR stamp-brush library — choosing a brush replaces the default circle; ✕ clears back to Circle; when an image brush is active, Hardness is disabled and Spacing (5–100%), Angle (0–359°), Sz Jitter (random size per stamp, 0–100%), Rot. Jitter (random rotation per stamp on/off) controls appear; **Properties pane — SAM3 mode**: enter a text prompt (e.g. "cat"), set Max candidates (3/6/9/12), click Segment — candidate mask thumbnails appear; click to select (blue border + ✓, multi-select supported), click Apply Selected (N) to apply with current Mode (Add / Erase); a new mask layer is created automatically if needed; **Mask layer A/S operation**: A/S toggle button on each mask layer row — Add (green) composites normally, Subtract (red) cuts the mask from the layer below; **✂ clipping mask button** on the layer row clips the layer directly below to the painted area; brush cursor shown as size-accurate circle; strokes can start from outside the canvas margin and continue past the edge
|
||||
- **Blur** — **Whole Blur**: Gaussian blur to the entire active layer with intensity slider (1–50 px); **Whole Mosaic**: pixelation mosaic with block-size slider (5–100 px); **Rect Blur / Rect Mosaic**: enable the toggle then drag a rectangle on the canvas to apply blur or mosaic to that region only (blue preview for blur, orange for mosaic); Rect Blur and Rect Mosaic are mutually exclusive; all operations support Undo
|
||||
- **BG Remove** — remove the background from the active layer; **Lightweight (@imgly)**: runs entirely in the browser via CDN (no server required; ~40 MB model downloaded on first use); **BiRefNet**: high-quality removal via the Python backend (coming soon); **New Layer** option (default on) adds the result as a new layer above the original; when off, replaces the active layer in-place
|
||||
- **BG Remove** — remove the background from the active layer; **Lightweight (@imgly)**: runs entirely in the browser via CDN (no server required; ~40 MB model downloaded on first use); **BiRefNet**: high-quality removal via Mask Editor One's Python backend (requires Mask Editor One installed and `birefnet.safetensors` in `ComfyUI/models/background_removal/`); **New Layer** option (default on) adds the result as a new layer above the original; when off, replaces the active layer in-place
|
||||
- **Filter (G'MIC)** — apply G'MIC-Qt filter effects to the active image layer; click **Edit with G'MIC** to launch G'MIC-Qt GUI; select a filter and click OK — a "G'MIC-Qt filter output" window appears; close it to save the result back as the active layer; requires G'MIC-Qt Standalone installed and path configured in Settings → G'MIC-Qt Executable Path
|
||||
- **Layer panel** — layer list with visibility (👁/🚫), lock (🔒/🔓), and clipping-mask (✂) toggles; opacity slider; type icons (🖼 image / T text / ✏ draw / ⬚ mask); Layer 1 is automatically locked on first image load
|
||||
- **Layer lock** — locked layers show an orange bounding box and 🔒 icon on the canvas; move/resize/rotate are disabled while locked; click the 🔓 button in the layer row to unlock
|
||||
@@ -356,6 +356,7 @@ Click the **camera icon** (next to the W button) in ComfyUI's top bar to capture
|
||||
- **[Ollama](https://ollama.com/)** — for AI chat assistant, translation, and VLM features
|
||||
- **[LM Studio](https://lmstudio.ai/)** — alternative backend for translation and VLM (OpenAI-compatible API)
|
||||
- **[Eagle](https://eagle.cool/)** — for auto-saving generated images with metadata
|
||||
- **[comfyui-mask-editor-one](https://github.com/ketle-man/comfyui-mask-editor-one) (v0.1.9+)** — enables BiRefNet background removal, SAM3 text-prompt segmentation, and ABR stamp-brush library in the Image Edit Mask tool; `birefnet.safetensors` must be placed in `ComfyUI/models/background_removal/` for BiRefNet
|
||||
|
||||
---
|
||||
|
||||
@@ -371,6 +372,18 @@ Click the **camera icon** (next to the W button) in ComfyUI's top bar to capture
|
||||
|
||||
## Changelog
|
||||
|
||||
### v0.3.65
|
||||
- **Image Edit — Mask Editor One integration fixes** — `store_image` API field mismatch (`image_b64` → `bg_image_b64`) corrected so BiRefNet and SAM3 no longer report "no image available"; `server.py` updated to accept both field names for backward compatibility
|
||||
- **Image Edit — top bar icon persistence** — WFS / Snapshot / Node Sets SVG icons in the ComfyUI action bar disappeared when the Properties Panel was opened (Vue re-render reset custom `innerHTML` to `<i>`); fixed with a `MutationObserver` that re-applies SVG icons whenever a reset is detected
|
||||
- **Image Edit — Mask Tool: ABR brush library** (requires Mask Editor One) — Select button in the Properties pane opens a folder-tree + thumbnail-grid brush picker; stamp brushes are loaded from Mask Editor One's `/mask_editor/brushes/` folder; ✕ clears back to the default circle brush
|
||||
- **Image Edit — Mask Tool: ABR brush controls** — when an image brush is active, Hardness is disabled and new controls appear in the Properties pane: Spacing (stamp interval 5–100%), Angle (fixed rotation 0–359°), Sz Jitter (random size reduction per stamp 0–100%), Rot. Jitter (random angle per stamp on/off); size jitter clamped to minimum 1 px to prevent zero-dimension canvas errors
|
||||
- **Image Edit — Mask brush cursor** — brush size circle is now hidden outside the canvas; only shown when the pointer is within the canvas bounds (window-level mousemove no longer shows the cursor overlay outside)
|
||||
|
||||
### v0.3.64
|
||||
- **Image Edit — Mask layer Add/Subtract** — A/S toggle button on each mask layer row; Add (green, default) composites the mask normally; Subtract (red) cuts the mask area from the layer below; multiple mask layers are composited back-to-front matching Mask Editor One's CanvasCompositor logic
|
||||
- **Image Edit — BiRefNet BG Remove** (requires Mask Editor One + `birefnet.safetensors` in `ComfyUI/models/background_removal/`) — BiRefNet model now fully functional via Mask Editor One's Python backend; grayscale mask returned as RGBA PNG and applied as a new layer or in-place per the New Layer toggle
|
||||
- **Image Edit — SAM3 segmentation** (requires Mask Editor One) — new SAM3 sub-tool in the Mask tool options bar; enter a text prompt, set Max candidates (3/6/9/12), click Segment; candidate mask thumbnails shown in the Properties pane; click to select (multi-select), Apply Selected (N) applies all chosen masks with Add or Erase mode; new mask layer auto-created if active layer is not a mask
|
||||
|
||||
### v0.3.63
|
||||
- **Nodes tab — multi-select** — Ctrl+click to toggle individual nodes, Shift+click for range selection; bulk action bar appears with add to group / remove from group / create & add group / bulk favorite / unfavorite; works in both Card and Table view modes
|
||||
- **All tabs — search clear (✕)** — inline ✕ overlay button inside each search box (Workflow / Nodes / Models / Gallery); shown only when text is entered, click to clear and re-filter immediately
|
||||
|
||||
+2
-1
@@ -457,7 +457,8 @@ function applyI18nToHtml() {
|
||||
"wfm-help-imageedit-mask-title": "helpImageEditMaskTitle",
|
||||
"wfm-help-imageedit-mask-1": "helpImageEditMask1", "wfm-help-imageedit-mask-2": "helpImageEditMask2",
|
||||
"wfm-help-imageedit-mask-3": "helpImageEditMask3", "wfm-help-imageedit-mask-4": "helpImageEditMask4",
|
||||
"wfm-help-imageedit-mask-5": "helpImageEditMask5",
|
||||
"wfm-help-imageedit-mask-5": "helpImageEditMask5", "wfm-help-imageedit-mask-6": "helpImageEditMask6",
|
||||
"wfm-help-imageedit-mask-7": "helpImageEditMask7", "wfm-help-imageedit-mask-8": "helpImageEditMask8",
|
||||
"wfm-help-imageedit-gmic-title": "helpImageEditGmicTitle",
|
||||
"wfm-help-imageedit-gmic-1": "helpImageEditGmic1", "wfm-help-imageedit-gmic-2": "helpImageEditGmic2",
|
||||
"wfm-help-imageedit-gmic-3": "helpImageEditGmic3", "wfm-help-imageedit-gmic-4": "helpImageEditGmic4",
|
||||
|
||||
+24
-15
@@ -785,16 +785,19 @@ const LANGUAGES = {
|
||||
helpImageEdit29: "Mouse wheel: Zoom in / out",
|
||||
helpImageEdit30: "Double-click (Select tool on text layer): Re-edit text",
|
||||
helpImageEdit7b: "Blur (≈): apply Gaussian blur or mosaic to the active layer — whole-layer or region-based (drag a rectangle); see the Blur Tool card below for details",
|
||||
helpImageEdit7c: "BG Remove (⬚): remove the background from the active layer using Lightweight (@imgly, runs in browser) or BiRefNet (Python backend, coming soon); see the BG Remove Tool card below for details",
|
||||
helpImageEdit7d: "Mask (🎭): paint a white mask on the canvas; click \"M\" in the Layers header to add a mask layer — the Mask tool activates automatically; the mask is shown as a colored semi-transparent overlay; the Properties pane (left of the Layers panel) shows Paint controls; see the Mask Tool card below for details",
|
||||
helpImageEdit7c: "BG Remove (⬚): remove the background from the active layer using Lightweight (@imgly, runs in browser) or BiRefNet (requires Mask Editor One + birefnet.safetensors in ComfyUI/models/background_removal/); see the BG Remove Tool card below for details",
|
||||
helpImageEdit7d: "Mask (🎭): paint a white mask on the canvas with Paint mode or use SAM3 text-prompt segmentation (requires Mask Editor One); click \"M\" in the Layers header to add a mask layer — the Mask tool activates automatically; the mask is shown as a colored semi-transparent overlay; see the Mask Tool card below for details",
|
||||
helpImageEdit8b: "\"M\" button in the Layers header: adds a new mask layer above the current layer and automatically switches to the Mask tool",
|
||||
helpImageEdit12: "Type icons: 🖼 = image layer, T = text layer, ✏ = draw layer, ⬚ = mask layer",
|
||||
helpImageEditMaskTitle: "Mask Tool (🎭)",
|
||||
helpImageEditMask1: "Add a mask layer: click the \"M\" button in the Layers panel header; the new mask layer is inserted above the active layer and the Mask tool activates automatically",
|
||||
helpImageEditMask2: "Clicking a mask layer in the layer list automatically switches to the Mask tool",
|
||||
helpImageEditMask3: "Tool Options bar (Paint / Invert / Overlay / Blur): Paint button toggles the Paint sub-tool; Invert checkbox inverts the overlay preview (shows color where mask is absent); Overlay color picker changes the preview color (default red); Blur slider (0–50 px) softens the overlay edge",
|
||||
helpImageEditMask4: "Properties pane (left of the Layers panel, visible when Mask tool is active): Size (1–200 px), Hardness (0–100%), Mode — Add button draws white (mask present) / Erase button removes to transparent (mask absent); the active mode is highlighted in blue",
|
||||
helpImageEditMask3: "Tool Options bar (Paint / SAM3 / Invert / Overlay / Blur): Paint/SAM3 buttons switch sub-tools; Invert checkbox inverts the overlay preview (shows color where mask is absent); Overlay color picker changes the preview color (default red); Blur slider (0–50 px) softens the overlay edge; SAM3 button is disabled when Mask Editor One is not installed",
|
||||
helpImageEditMask4: "Properties pane — Paint mode: Mode (Add / Erase), Size (1–200 px), Hardness (0–100%); MASK EDITOR ONE section (visible when Mask Editor One is installed): Select button opens the ABR brush library — choosing a brush replaces the default circle brush; ✕ clears the brush back to Circle; when an image brush is active, Hardness is disabled and additional controls appear: Spacing (stamp interval 5–100%), Angle (rotation 0–359°), Sz Jitter (random size reduction per stamp 0–100%), Rot. Jitter (random rotation per stamp on/off)",
|
||||
helpImageEditMask5: "✂ button on a mask layer row: toggles the layer as a clipping mask — when enabled (blue), the mask clips the layer directly below it so only the painted area is visible; clipping is applied when saving PNG / Gallery / ComfyUI",
|
||||
helpImageEditMask6: "SAM3 (Mask Editor One required): text-prompt segmentation powered by the SAM3 model; enter a description of the object to segment (e.g. \"cat\", \"person\"), set Max (maximum mask candidates: 3/6/9/12), then click Segment",
|
||||
helpImageEditMask7: "SAM3 workflow: after Segment, candidate masks appear as thumbnails in the Properties pane — click to select (blue border + ✓); multiple masks can be selected; click Apply Selected (N) to apply them all; Mode (Add / Erase) controls how masks are merged into the current mask layer; a new mask layer is created automatically if the active layer is not a mask",
|
||||
helpImageEditMask8: "ABR Brush Library (Mask Editor One required, Paint mode only): click Select in the MASK EDITOR ONE section to open the brush picker — browse folders on the left, click a thumbnail to apply; \"Round Brush (default)\" restores the circle brush; brushes are shared with Mask Editor One and stored in its brushes/ folder",
|
||||
helpImageEditBlurTitle: "Blur Tool (≈)",
|
||||
helpImageEditBlur1: "Whole Blur: applies a Gaussian blur to the entire active layer — adjust the intensity slider (1–50 px) and click Apply",
|
||||
helpImageEditBlur2: "Whole Mosaic: applies a pixelation mosaic to the entire active layer — adjust the block size slider (5–100 px) and click Apply",
|
||||
@@ -804,7 +807,7 @@ const LANGUAGES = {
|
||||
helpImageEditBlur6: "All operations support Undo (Ctrl+Z)",
|
||||
helpImageEditBgRemoveTitle: "BG Remove Tool (⬚)",
|
||||
helpImageEditBgRemove1: "Model — Lightweight (@imgly): runs entirely in the browser using the @imgly/background-removal library loaded from CDN; no server required; first use downloads the model (~40 MB) and caches it for the session",
|
||||
helpImageEditBgRemove2: "Model — BiRefNet: high-quality background removal using the BiRefNet model via the Workflow Studio Python backend; requires birefnet.safetensors placed in ComfyUI/models/background_removal/ (coming soon)",
|
||||
helpImageEditBgRemove2: "Model — BiRefNet: high-quality background removal using the BiRefNet model; requires Mask Editor One to be installed and birefnet.safetensors placed in ComfyUI/models/background_removal/",
|
||||
helpImageEditBgRemove3: "New Layer (checked by default): the result is added as a new layer above the active layer at the same position and display size — the original layer is preserved",
|
||||
helpImageEditBgRemove4: "When New Layer is unchecked, the active layer's canvas is replaced in-place with the background-removed result",
|
||||
helpImageEditBgRemove5: "Click Remove BG to start processing; status text shows Loading model → Processing → Done; supports Undo (Ctrl+Z)",
|
||||
@@ -1753,15 +1756,18 @@ const LANGUAGES = {
|
||||
helpImageEdit29: "マウスホイール:ズームイン / アウト",
|
||||
helpImageEdit30: "ダブルクリック(Selectツールでテキストレイヤー):テキストを再編集",
|
||||
helpImageEdit7b: "Blur (≈):アクティブレイヤーにガウスぼかしまたはモザイクを適用 — 全体またはドラッグで矩形範囲指定;詳細は下の「Blur Tool」カードを参照",
|
||||
helpImageEdit7c: "BG Remove (⬚):Lightweight(@imgly、ブラウザ内処理)またはBiRefNet(Pythonバックエンド、近日追加)でアクティブレイヤーの背景を除去;詳細は下の「BG Remove Tool」カードを参照",
|
||||
helpImageEdit7d: "Mask (🎭):キャンバス上に白いマスクを描画;レイヤーヘッダーの「M」ボタンでマスクレイヤーを追加すると自動的にMaskツールに切り替わる;マスクはカラーの半透明オーバーレイとして表示;プロパティペイン(レイヤーパネル左隣)にPaintサブツールのコントロール;詳細は下の「Mask Tool」カードを参照",
|
||||
helpImageEdit7c: "BG Remove (⬚):Lightweight(@imgly、ブラウザ内処理)またはBiRefNet(Mask Editor One + ComfyUI/models/background_removal/にbirefnet.safetensors必須)でアクティブレイヤーの背景を除去;詳細は下の「BG Remove Tool」カードを参照",
|
||||
helpImageEdit7d: "Mask (🎭):Paintモードでキャンバス上に白いマスクを描画、またはSAM3テキストプロンプトセグメンテーション(Mask Editor One必須)でマスク生成;レイヤーヘッダーの「M」ボタンでマスクレイヤーを追加すると自動的にMaskツールに切り替わる;マスクはカラーの半透明オーバーレイとして表示;詳細は下の「Mask Tool」カードを参照",
|
||||
helpImageEdit8b: "レイヤーヘッダーの「M」ボタン:アクティブレイヤーの上に新しいマスクレイヤーを追加し、自動的にMaskツールに切り替える",
|
||||
helpImageEditMaskTitle: "Mask ツール (🎭)",
|
||||
helpImageEditMask1: "マスクレイヤーの追加:レイヤーパネルヘッダーの「M」ボタンをクリック;新しいマスクレイヤーはアクティブレイヤーの上に挿入され、Maskツールが自動的に有効化される",
|
||||
helpImageEditMask2: "レイヤーリストでマスクレイヤーをクリックすると自動的にMaskツールに切り替わる",
|
||||
helpImageEditMask3: "ツールオプションバー(Paint / Invert / Overlay / Blur):PaintボタンでPaintサブツールを切り替え;Invertチェックボックスでオーバーレイプレビューを反転(マスクがない部分にオーバーレイを表示);Overlayカラーピッカーでプレビューカラーを変更(デフォルト赤);Blurスライダー(0〜50 px)でオーバーレイプレビューの輪郭をぼかす",
|
||||
helpImageEditMask4: "プロパティペイン(レイヤーパネル左隣、Maskツール選択時に表示):Sizeスライダー(1〜200 px)、Hardnessスライダー(0〜100%)、Modeボタン — Addボタン(白で描画/マスクあり)/ Eraseボタン(透明化/マスクなし);アクティブなModeが青くハイライト",
|
||||
helpImageEditMask3: "ツールオプションバー(Paint / SAM3 / Invert / Overlay / Blur):Paint/SAM3ボタンでサブツールを切り替え;Invertチェックボックスでオーバーレイプレビューを反転(マスクがない部分にオーバーレイを表示);Overlayカラーピッカーでプレビューカラーを変更(デフォルト赤);Blurスライダー(0〜50 px)でオーバーレイプレビューの輪郭をぼかす;SAM3ボタンはMask Editor One未インストール時は無効",
|
||||
helpImageEditMask4: "プロパティペイン — Paintモード:Mode(Add / Erase)・Size(1〜200 px)・Hardness(0〜100%);MASK EDITOR ONEセクション(Mask Editor Oneインストール時のみ表示):Selectボタンでクリックするとスタンプブラシを選択(選択したブラシがデフォルト円形に代わる);✕でCircle(デフォルト)に戻す;画像ブラシ選択中はHardnessが無効になり追加コントロールが表示:Spacing(スタンプ間隔 5〜100%)・Angle(回転角 0〜359°)・Sz Jitter(スタンプごとのサイズランダム変動 0〜100%)・Rot. Jitter(スタンプごとの角度ランダム変動 on/off)",
|
||||
helpImageEditMask5: "マスクレイヤー行の ✂ ボタン:クリッピングマスクとして機能させるon/off切り替え — 有効(青)のとき、直下のレイヤーをマスクの描画範囲でクリッピングして表示;クリッピングはPNG保存 / Gallery / ComfyUI送信にも反映される",
|
||||
helpImageEditMask6: "SAM3(Mask Editor One必須):SAM3モデルによるテキストプロンプトセグメンテーション;対象オブジェクトの説明(例:\"cat\"・\"person\")を入力し、Max(マスク候補の最大数:3/6/9/12)を設定してSegmentをクリック",
|
||||
helpImageEditMask7: "SAM3の操作フロー:Segment後、候補マスクのサムネイルがプロパティペインに表示される — クリックして選択(青ボーダー + ✓);複数選択可;Apply Selected(N)で選択したマスクを一括適用;Mode(Add / Erase)で現在のマスクレイヤーへの合成方法を制御;アクティブレイヤーがマスクでない場合は新規マスクレイヤーを自動作成",
|
||||
helpImageEditMask8: "ABRブラシライブラリ(Mask Editor One必須・Paintモードのみ):MASK EDITOR ONEセクションのSelectボタンでブラシピッカーを開く — 左のフォルダツリーで絞り込み、サムネイルをクリックして適用;「Round Brush (default)」で円形ブラシに戻す;ブラシはMask Editor Oneと共有しその brushes/ フォルダに保存される",
|
||||
helpImageEditBlurTitle: "Blur ツール (≈)",
|
||||
helpImageEditBlur1: "Whole Blur:アクティブレイヤー全体にガウスぼかしを適用 — 強度スライダー(1〜50 px)で調整してApplyをクリック",
|
||||
helpImageEditBlur2: "Whole Mosaic:アクティブレイヤー全体にピクセル化モザイクを適用 — ブロックサイズスライダー(5〜100 px)で調整してApplyをクリック",
|
||||
@@ -1771,7 +1777,7 @@ const LANGUAGES = {
|
||||
helpImageEditBlur6: "全操作でUndo(Ctrl+Z)に対応",
|
||||
helpImageEditBgRemoveTitle: "BG Remove ツール (⬚)",
|
||||
helpImageEditBgRemove1: "モデル — Lightweight(@imgly):CDNから読み込む @imgly/background-removal ライブラリを使用してブラウザ内で処理;サーバー不要;初回使用時にモデル(約40 MB)をダウンロードしてセッション中にキャッシュ",
|
||||
helpImageEditBgRemove2: "モデル — BiRefNet:Workflow Studio Pythonバックエンド経由でBiRefNetモデルを使用する高品質な背景除去;ComfyUI/models/background_removal/ に birefnet.safetensors が必要(近日対応)",
|
||||
helpImageEditBgRemove2: "モデル — BiRefNet:BiRefNetモデルによる高品質な背景除去;Mask Editor Oneのインストールと ComfyUI/models/background_removal/ への birefnet.safetensors 配置が必要",
|
||||
helpImageEditBgRemove3: "New Layer(デフォルトON):結果をアクティブレイヤーの上に同じ位置・表示サイズの新規レイヤーとして追加 — 元レイヤーは保持",
|
||||
helpImageEditBgRemove4: "New LayerをOFFにすると、アクティブレイヤーのキャンバスが背景除去済みの結果で直接置き換えられる",
|
||||
helpImageEditBgRemove5: "Remove BGをクリックして処理開始;ステータステキストに「Loading model → Processing → Done」と表示;Undo(Ctrl+Z)に対応",
|
||||
@@ -2720,15 +2726,18 @@ const LANGUAGES = {
|
||||
helpImageEdit29: "鼠标滚轮:放大/缩小",
|
||||
helpImageEdit30: "双击(Select工具点击文字图层):重新编辑文字",
|
||||
helpImageEdit7b: "Blur (≈):对活动图层应用高斯模糊或马赛克 — 整层或拖动矩形区域;详细内容参见下方「Blur Tool」卡片",
|
||||
helpImageEdit7c: "BG Remove (⬚):使用Lightweight(@imgly,在浏览器中运行)或BiRefNet(Python后端,即将推出)去除活动图层背景;详细内容参见下方「BG Remove Tool」卡片",
|
||||
helpImageEdit7d: "Mask (🎭):在画布上绘制白色遮罩;点击图层标题栏的「M」按钮添加遮罩图层,自动切换至Mask工具;遮罩以彩色半透明叠加方式显示;属性面板(图层面板左侧)显示Paint子工具控件;详细内容参见下方「Mask Tool」卡片",
|
||||
helpImageEdit7c: "BG Remove (⬚):使用Lightweight(@imgly,在浏览器中运行)或BiRefNet(需要Mask Editor One + ComfyUI/models/background_removal/中的birefnet.safetensors)去除活动图层背景;详细内容参见下方「BG Remove Tool」卡片",
|
||||
helpImageEdit7d: "Mask (🎭):使用Paint模式在画布上绘制白色遮罩,或使用SAM3文本提示分割(需要Mask Editor One);点击图层标题栏的「M」按钮添加遮罩图层,自动切换至Mask工具;遮罩以彩色半透明叠加方式显示;详细内容参见下方「Mask Tool」卡片",
|
||||
helpImageEdit8b: "图层标题栏的「M」按钮:在当前活动图层上方添加新的遮罩图层,并自动切换至Mask工具",
|
||||
helpImageEditMaskTitle: "Mask 工具 (🎭)",
|
||||
helpImageEditMask1: "添加遮罩图层:点击图层面板标题栏的「M」按钮;新遮罩图层插入到活动图层上方,Mask工具自动激活",
|
||||
helpImageEditMask2: "在图层列表中点击遮罩图层会自动切换至Mask工具",
|
||||
helpImageEditMask3: "顶部工具栏(Paint / Invert / Overlay / Blur):Paint按钮切换Paint子工具(默认激活);Invert复选框反转叠加预览(在遮罩缺失处显示颜色);Overlay拾色器更改预览颜色(默认红色);Blur滑块(0–50 px)柔化叠加边缘",
|
||||
helpImageEditMask4: "属性面板(图层面板左侧,Mask工具激活时显示):Size滑块(1–200 px)、Hardness滑块(0–100%)、Mode按钮 — Add按钮(绘制白色/遮罩存在)/ Erase按钮(擦除至透明/遮罩缺失);当前激活模式以蓝色高亮显示",
|
||||
helpImageEditMask3: "顶部工具栏(Paint / SAM3 / Invert / Overlay / Blur):Paint/SAM3按钮切换子工具;Invert复选框反转叠加预览(在遮罩缺失处显示颜色);Overlay拾色器更改预览颜色(默认红色);Blur滑块(0–50 px)柔化叠加边缘;未安装Mask Editor One时SAM3按钮不可用",
|
||||
helpImageEditMask4: "属性面板 — Paint模式:Mode(Add / Erase)、Size(1–200 px)、Hardness(0–100%);MASK EDITOR ONE区域(安装Mask Editor One后显示):Select按钮打开ABR笔刷库 — 选择笔刷将替换默认圆形笔刷;✕恢复Circle(默认);选择图像笔刷后Hardness禁用,并显示额外控件:Spacing(印章间距 5–100%)、Angle(旋转角度 0–359°)、Sz Jitter(每个印章的随机大小变化 0–100%)、Rot. Jitter(每个印章的随机旋转 on/off)",
|
||||
helpImageEditMask5: "遮罩图层行的 ✂ 按钮:切换是否作为剪贴蒙版使用 — 启用(蓝色)时,遮罩将裁剪其正下方图层,仅显示已绘制区域;剪贴效果在保存PNG / Gallery / 发送至ComfyUI时均会生效",
|
||||
helpImageEditMask6: "SAM3(需要Mask Editor One):由SAM3模型驱动的文本提示分割;输入目标对象描述(如\"cat\"、\"person\"),设置Max(最大蒙版候选数:3/6/9/12),然后点击Segment",
|
||||
helpImageEditMask7: "SAM3操作流程:Segment后,候选蒙版缩略图显示在属性面板 — 点击选择(蓝色边框 + ✓);可多选;点击Apply Selected(N)批量应用;Mode(Add / Erase)控制蒙版与当前遮罩图层的合并方式;若活动图层非遮罩图层则自动创建新遮罩图层",
|
||||
helpImageEditMask8: "ABR笔刷库(需要Mask Editor One,仅Paint模式):点击MASK EDITOR ONE区域的Select按钮打开笔刷选择器 — 左侧浏览文件夹,点击缩略图应用;「Round Brush (default)」恢复圆形笔刷;笔刷与Mask Editor One共享,存储在其brushes/文件夹",
|
||||
helpImageEditBlurTitle: "Blur 工具 (≈)",
|
||||
helpImageEditBlur1: "Whole Blur:对整个活动图层应用高斯模糊 — 调整强度滑块(1–50 px),点击Apply",
|
||||
helpImageEditBlur2: "Whole Mosaic:对整个活动图层应用像素化马赛克 — 调整块大小滑块(5–100 px),点击Apply",
|
||||
@@ -2738,7 +2747,7 @@ const LANGUAGES = {
|
||||
helpImageEditBlur6: "所有操作均支持撤销(Ctrl+Z)",
|
||||
helpImageEditBgRemoveTitle: "BG Remove 工具 (⬚)",
|
||||
helpImageEditBgRemove1: "模型 — Lightweight(@imgly):使用从CDN加载的@imgly/background-removal库在浏览器内处理;无需服务器;首次使用时下载模型(约40 MB)并在会话期间缓存",
|
||||
helpImageEditBgRemove2: "模型 — BiRefNet:通过Workflow Studio Python后端使用BiRefNet模型进行高质量背景去除;需要将birefnet.safetensors放置在ComfyUI/models/background_removal/(即将支持)",
|
||||
helpImageEditBgRemove2: "模型 — BiRefNet:使用BiRefNet模型进行高质量背景去除;需要安装Mask Editor One并将birefnet.safetensors放置在ComfyUI/models/background_removal/",
|
||||
helpImageEditBgRemove3: "New Layer(默认勾选):结果作为新图层添加到活动图层上方,位置和显示尺寸相同 — 原始图层保留",
|
||||
helpImageEditBgRemove4: "取消勾选New Layer时,活动图层的画布将被去除背景的结果直接替换",
|
||||
helpImageEditBgRemove5: "点击Remove BG开始处理;状态文字显示「Loading model → Processing → Done」;支持撤销(Ctrl+Z)",
|
||||
|
||||
+750
-28
@@ -53,9 +53,9 @@ class ImageEditTab {
|
||||
constructor() {
|
||||
this._layerMgr = null;
|
||||
this._activeTool = "select";
|
||||
this._drawTool = null;
|
||||
this._textTool = null;
|
||||
this._selectTool = null;
|
||||
this._drawTool = new DrawTool(null);
|
||||
this._textTool = new TextTool(null);
|
||||
this._selectTool = new SelectTool();
|
||||
this._zoom = 1.0;
|
||||
this._panOffset = { x: 0, y: 0 };
|
||||
this._canvasW = 512;
|
||||
@@ -67,9 +67,9 @@ class ImageEditTab {
|
||||
this._panStart = null;
|
||||
this._spaceDown = false;
|
||||
this._compositeMode = false;
|
||||
this._editingTextLayer = null; // テキスト再編集中のレイヤー参照
|
||||
this._editingTextLayer = null;
|
||||
this._initialized = false;
|
||||
this._shapeTool = null;
|
||||
this._shapeTool = new ShapeTool();
|
||||
// Blur ツール
|
||||
this._blurRectMode = null; // null | 'blur' | 'mosaic'
|
||||
this._blurDragging = false;
|
||||
@@ -87,6 +87,19 @@ class ImageEditTab {
|
||||
processing: false,
|
||||
aborted: false
|
||||
};
|
||||
// Mask Editor One BiRefNet 利用可否
|
||||
this._birefnetAvailable = false;
|
||||
// Mask Editor One SAM3 状態
|
||||
this._sam3Available = false;
|
||||
this._sam3Results = []; // [{mask_b64, score, area}, ...]
|
||||
this._sam3Prompt = "";
|
||||
this._sam3MaxMasks = 9;
|
||||
this._sam3Loading = false;
|
||||
this._sam3Mode = "add"; // "add" | "erase"
|
||||
this._sam3Selected = new Set(); // 選択中の結果インデックス
|
||||
// ABR brush (Mask Editor One) — optional feature
|
||||
this._abrAvailable = false;
|
||||
this._abrBrushTree = [];
|
||||
}
|
||||
|
||||
// ── 初期化 ────────────────────────────────────
|
||||
@@ -100,6 +113,44 @@ class ImageEditTab {
|
||||
this._setupLayerPanel();
|
||||
this._setupKeyboard();
|
||||
this._initBrushCursor();
|
||||
// Mask Editor One の BiRefNet / SAM3 が利用可能か非同期で確認
|
||||
this._checkBiRefNetAvailability();
|
||||
this._checkSam3Availability();
|
||||
this._checkAbrAvailability();
|
||||
}
|
||||
|
||||
async _checkBiRefNetAvailability() {
|
||||
try {
|
||||
const resp = await fetch("/mask_editor/birefnet/status");
|
||||
if (!resp.ok) return;
|
||||
const json = await resp.json();
|
||||
this._birefnetAvailable = json.loaded === true || json.model_found === true;
|
||||
} catch {
|
||||
this._birefnetAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
async _checkSam3Availability() {
|
||||
try {
|
||||
const resp = await fetch("/mask_editor/sam3/status");
|
||||
if (!resp.ok) return;
|
||||
const json = await resp.json();
|
||||
this._sam3Available = json.loaded === true || json.ckpt_found === true;
|
||||
} catch {
|
||||
this._sam3Available = false;
|
||||
}
|
||||
}
|
||||
|
||||
async _checkAbrAvailability() {
|
||||
try {
|
||||
const resp = await fetch("/mask_editor/brushes/list");
|
||||
if (!resp.ok) return;
|
||||
const json = await resp.json();
|
||||
this._abrBrushTree = json.tree || [];
|
||||
this._abrAvailable = this._abrBrushTree.length > 0;
|
||||
} catch {
|
||||
this._abrAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── ブラシカーソル ────────────────────────────
|
||||
@@ -133,6 +184,13 @@ class ImageEditTab {
|
||||
const refCanvas = document.getElementById("ie-canvas-draw");
|
||||
if (!refCanvas) { el.style.display = "none"; return; }
|
||||
const rect = refCanvas.getBoundingClientRect();
|
||||
// Image Edit タブ非表示時(width=0)はカーソルを消す
|
||||
if (rect.width === 0 || rect.height === 0) { el.style.display = "none"; return; }
|
||||
// キャンバス外は通常カーソルを表示
|
||||
if (e.clientX < rect.left || e.clientX > rect.right || e.clientY < rect.top || e.clientY > rect.bottom) {
|
||||
el.style.display = "none";
|
||||
return;
|
||||
}
|
||||
const scale = rect.width / refCanvas.width;
|
||||
const px = Math.max(2, size * scale);
|
||||
|
||||
@@ -463,11 +521,39 @@ class ImageEditTab {
|
||||
|
||||
} else if (toolId === "mask") {
|
||||
const sub = this._maskSubtool ?? "paint";
|
||||
const sam3Disabled = this._sam3Available ? "" : "disabled";
|
||||
const sam3Title = this._sam3Available ? "SAM3 Segment" : "SAM3 (Mask Editor One required)";
|
||||
const sam3Ui = this._sam3Available && sub === "sam3" ? `
|
||||
<div class="ie-opt-group">
|
||||
<input type="text" id="ie-sam3-prompt" class="ie-opt-input"
|
||||
placeholder="e.g. cat, person..."
|
||||
value="${this._sam3Prompt}"
|
||||
style="width:160px;font-size:11px;padding:2px 6px;border:1px solid var(--wfm-border);border-radius:3px;background:var(--wfm-surface);color:var(--wfm-text);">
|
||||
</div>
|
||||
<div class="ie-opt-group">
|
||||
<label style="font-size:11px;color:var(--wfm-text-secondary);">Max</label>
|
||||
<select id="ie-sam3-max" class="ie-opt-select" style="width:44px;">
|
||||
${[3,6,9,12].map(n => `<option value="${n}"${n === this._sam3MaxMasks ? " selected" : ""}>${n}</option>`).join("")}
|
||||
</select>
|
||||
</div>
|
||||
<div class="ie-opt-group">
|
||||
<button class="wfm-btn wfm-btn-sm wfm-btn-primary" id="ie-sam3-run-btn" ${this._sam3Loading ? "disabled" : ""}>
|
||||
${this._sam3Loading ? "Running..." : "Segment"}
|
||||
</button>
|
||||
</div>
|
||||
<span id="ie-sam3-status" style="font-size:11px;color:var(--wfm-text-secondary);margin-left:4px;">
|
||||
${this._sam3Results.length > 0 ? `${this._sam3Results.length} masks found` : ""}
|
||||
</span>
|
||||
` : "";
|
||||
el.innerHTML = `
|
||||
<div class="ie-opt-group">
|
||||
<button class="wfm-btn wfm-btn-sm${sub === "paint" ? " ie-opt-active" : ""}" id="ie-mask-paint-btn">Paint</button>
|
||||
<button class="wfm-btn wfm-btn-sm${sub === "sam3" ? " ie-opt-active" : ""}" id="ie-mask-sam3-btn"
|
||||
${sam3Disabled} title="${sam3Title}">SAM3</button>
|
||||
</div>
|
||||
<div style="width:1px;height:22px;background:var(--wfm-border);margin:0 4px;flex-shrink:0;"></div>
|
||||
${sam3Ui}
|
||||
${sub !== "sam3" ? `
|
||||
<div class="ie-opt-group">
|
||||
<label style="font-size:11px;cursor:pointer;color:var(--wfm-text-secondary);">
|
||||
<input type="checkbox" id="ie-mask-invert" ${this._maskInverted ? "checked" : ""}> Invert
|
||||
@@ -482,12 +568,25 @@ class ImageEditTab {
|
||||
<label style="font-size:11px;color:var(--wfm-text-secondary);">Blur</label>
|
||||
<input type="range" id="ie-mask-blur" min="0" max="50" value="${this._maskBlur}" style="width:70px;">
|
||||
<span id="ie-mask-blur-val" style="font-size:11px;min-width:22px;">${this._maskBlur}</span>px
|
||||
</div>
|
||||
</div>` : ""}
|
||||
`;
|
||||
document.getElementById("ie-mask-paint-btn")?.addEventListener("click", () => {
|
||||
this._maskSubtool = "paint";
|
||||
this._renderToolOptions("mask");
|
||||
});
|
||||
document.getElementById("ie-mask-sam3-btn")?.addEventListener("click", () => {
|
||||
if (this._sam3Available) {
|
||||
this._maskSubtool = "sam3";
|
||||
this._renderToolOptions("mask");
|
||||
}
|
||||
});
|
||||
document.getElementById("ie-sam3-prompt")?.addEventListener("input", e => {
|
||||
this._sam3Prompt = e.target.value;
|
||||
});
|
||||
document.getElementById("ie-sam3-max")?.addEventListener("change", e => {
|
||||
this._sam3MaxMasks = parseInt(e.target.value);
|
||||
});
|
||||
document.getElementById("ie-sam3-run-btn")?.addEventListener("click", () => this._runSam3Segment());
|
||||
document.getElementById("ie-mask-invert")?.addEventListener("change", e => {
|
||||
this._maskInverted = e.target.checked;
|
||||
this._updateCompositeView();
|
||||
@@ -575,12 +674,16 @@ class ImageEditTab {
|
||||
});
|
||||
|
||||
} else if (toolId === "bgremove") {
|
||||
const birefnetDisabled = this._birefnetAvailable ? "" : "disabled";
|
||||
const birefnetLabel = this._birefnetAvailable
|
||||
? "BiRefNet (Mask Editor One)"
|
||||
: "BiRefNet (Mask Editor One required)";
|
||||
el.innerHTML = `
|
||||
<div class="ie-opt-group">
|
||||
<label>Model</label>
|
||||
<select id="ie-bgremove-model" class="ie-opt-select">
|
||||
<option value="imgly">Lightweight (@imgly)</option>
|
||||
<option value="birefnet" disabled>BiRefNet (coming soon)</option>
|
||||
<option value="birefnet" ${birefnetDisabled}>${birefnetLabel}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="ie-opt-group">
|
||||
@@ -644,9 +747,43 @@ class ImageEditTab {
|
||||
</div>
|
||||
<div class="ie-props-row">
|
||||
<label>Hardness</label>
|
||||
<input type="range" id="ie-mask-hard" min="0" max="100" value="${Math.round(t.hardness * 100)}">
|
||||
<input type="range" id="ie-mask-hard" min="0" max="100" value="${Math.round(t.hardness * 100)}"
|
||||
${t.brushImage ? "disabled title='Hardness applies to circle brush only'" : ""}>
|
||||
<span id="ie-mask-hard-lbl">${Math.round(t.hardness * 100)}%</span>
|
||||
</div>
|
||||
${this._abrAvailable ? `
|
||||
<div style="margin:6px 0 4px;border-top:1px solid var(--wfm-border);padding-top:6px;font-size:10px;color:var(--wfm-text-secondary);letter-spacing:0.05em;">
|
||||
MASK EDITOR ONE
|
||||
</div>
|
||||
<div class="ie-props-row">
|
||||
<label>Brush</label>
|
||||
<span style="font-size:11px;color:var(--wfm-text-secondary);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"
|
||||
title="${t.brushName ?? "Circle"}">${t.brushName ?? "Circle"}</span>
|
||||
<button class="wfm-btn wfm-btn-sm" id="ie-mask-select-brush" style="font-size:10px;padding:1px 6px;flex-shrink:0;">Select</button>
|
||||
${t.brushImage ? `<button class="wfm-btn wfm-btn-sm" id="ie-mask-clear-brush" style="font-size:10px;padding:1px 5px;flex-shrink:0;">✕</button>` : ""}
|
||||
</div>
|
||||
${t.brushImage ? `
|
||||
<div class="ie-props-row">
|
||||
<label>Spacing</label>
|
||||
<input type="range" id="ie-mask-spacing" min="5" max="100" value="${Math.round((t.spacing ?? 0.25) * 100)}">
|
||||
<span id="ie-mask-spacing-lbl">${Math.round((t.spacing ?? 0.25) * 100)}%</span>
|
||||
</div>
|
||||
<div class="ie-props-row">
|
||||
<label>Angle</label>
|
||||
<input type="range" id="ie-mask-angle" min="0" max="359" value="${t.angle ?? 0}">
|
||||
<span id="ie-mask-angle-lbl">${t.angle ?? 0}°</span>
|
||||
</div>
|
||||
<div class="ie-props-row">
|
||||
<label>Sz Jitter</label>
|
||||
<input type="range" id="ie-mask-szjitter" min="0" max="100" value="${Math.round((t.sizeJitterAmount ?? 0.5) * 100)}">
|
||||
<span id="ie-mask-szjitter-lbl">${Math.round((t.sizeJitterAmount ?? 0.5) * 100)}%</span>
|
||||
</div>
|
||||
<div class="ie-props-row">
|
||||
<label>Rot. Jitter</label>
|
||||
<label style="cursor:pointer;font-size:11px;">
|
||||
<input type="checkbox" id="ie-mask-rotjitter" ${t.rotationJitter ? "checked" : ""}> On
|
||||
</label>
|
||||
</div>` : ""}` : ""}
|
||||
`;
|
||||
document.getElementById("ie-mask-mode-add")?.addEventListener("click", () => {
|
||||
this._maskTool.mode = "paint";
|
||||
@@ -668,6 +805,85 @@ class ImageEditTab {
|
||||
document.getElementById("ie-mask-hard-lbl").textContent = e.target.value + "%";
|
||||
this._maskTool._stamp = null;
|
||||
});
|
||||
document.getElementById("ie-mask-select-brush")?.addEventListener("click", () => this._openAbrBrushPicker());
|
||||
document.getElementById("ie-mask-clear-brush")?.addEventListener("click", () => {
|
||||
this._maskTool?.clearImageBrush();
|
||||
this._renderMaskProps("paint");
|
||||
});
|
||||
document.getElementById("ie-mask-spacing")?.addEventListener("input", e => {
|
||||
this._maskTool.spacing = parseInt(e.target.value) / 100;
|
||||
document.getElementById("ie-mask-spacing-lbl").textContent = e.target.value + "%";
|
||||
});
|
||||
document.getElementById("ie-mask-angle")?.addEventListener("input", e => {
|
||||
this._maskTool.angle = parseInt(e.target.value);
|
||||
document.getElementById("ie-mask-angle-lbl").textContent = e.target.value + "°";
|
||||
});
|
||||
document.getElementById("ie-mask-szjitter")?.addEventListener("input", e => {
|
||||
this._maskTool.sizeJitterAmount = parseInt(e.target.value) / 100;
|
||||
this._maskTool.sizeJitter = this._maskTool.sizeJitterAmount > 0;
|
||||
document.getElementById("ie-mask-szjitter-lbl").textContent = e.target.value + "%";
|
||||
});
|
||||
document.getElementById("ie-mask-rotjitter")?.addEventListener("change", e => {
|
||||
this._maskTool.rotationJitter = e.target.checked;
|
||||
});
|
||||
} else if (sub === "sam3") {
|
||||
const modeAdd = this._sam3Mode === "add";
|
||||
const selCount = this._sam3Selected.size;
|
||||
const hasResult = this._sam3Results.length > 0;
|
||||
body.innerHTML = `
|
||||
<div class="ie-props-row">
|
||||
<label>Mode</label>
|
||||
<div style="display:flex;gap:4px;">
|
||||
<button class="wfm-btn wfm-btn-sm${modeAdd ? " ie-opt-active" : ""}" id="ie-sam3-mode-add" style="flex:1;">Add</button>
|
||||
<button class="wfm-btn wfm-btn-sm${!modeAdd ? " ie-opt-active" : ""}" id="ie-sam3-mode-erase" style="flex:1;">Erase</button>
|
||||
</div>
|
||||
</div>
|
||||
${hasResult ? `
|
||||
<div class="ie-props-row" style="flex-direction:column;align-items:stretch;gap:4px;">
|
||||
<div style="font-size:11px;color:var(--wfm-text-secondary);">Click to select / deselect:</div>
|
||||
<div id="ie-sam3-results" style="display:grid;grid-template-columns:repeat(3,1fr);gap:4px;">
|
||||
${this._sam3Results.map((r, i) => {
|
||||
const sel = this._sam3Selected.has(i);
|
||||
const borderColor = sel ? "var(--wfm-primary,#4682e6)" : "var(--wfm-border)";
|
||||
const bg = sel ? "color-mix(in srgb,var(--wfm-primary,#4682e6) 15%,transparent)" : "transparent";
|
||||
return `<div class="ie-sam3-thumb" data-idx="${i}"
|
||||
style="cursor:pointer;border:2px solid ${borderColor};border-radius:4px;overflow:hidden;text-align:center;background:${bg};position:relative;">
|
||||
<img src="${r.mask_b64}" style="width:100%;display:block;background:#000;">
|
||||
<div style="font-size:10px;padding:2px 0;color:var(--wfm-text-secondary);">
|
||||
${Math.round((r.score ?? 0) * 100)}%
|
||||
</div>
|
||||
${sel ? '<div style="position:absolute;top:2px;right:3px;font-size:12px;line-height:1;color:var(--wfm-primary,#4682e6);">✓</div>' : ""}
|
||||
</div>`;
|
||||
}).join("")}
|
||||
</div>
|
||||
<button class="wfm-btn wfm-btn-sm wfm-btn-primary" id="ie-sam3-apply-btn"
|
||||
${selCount === 0 ? "disabled" : ""} style="margin-top:4px;">
|
||||
Apply Selected${selCount > 0 ? ` (${selCount})` : ""}
|
||||
</button>
|
||||
</div>` : `
|
||||
<div style="font-size:11px;color:var(--wfm-text-secondary);padding:4px 0;">
|
||||
${this._sam3Loading ? "Segmenting..." : "Enter a prompt and press Segment"}
|
||||
</div>`}
|
||||
`;
|
||||
document.getElementById("ie-sam3-mode-add")?.addEventListener("click", () => {
|
||||
this._sam3Mode = "add";
|
||||
this._renderMaskProps("sam3");
|
||||
});
|
||||
document.getElementById("ie-sam3-mode-erase")?.addEventListener("click", () => {
|
||||
this._sam3Mode = "erase";
|
||||
this._renderMaskProps("sam3");
|
||||
});
|
||||
body.querySelectorAll(".ie-sam3-thumb").forEach(el => {
|
||||
el.addEventListener("click", () => {
|
||||
const idx = parseInt(el.dataset.idx);
|
||||
if (this._sam3Selected.has(idx)) this._sam3Selected.delete(idx);
|
||||
else this._sam3Selected.add(idx);
|
||||
this._renderMaskProps("sam3");
|
||||
});
|
||||
});
|
||||
document.getElementById("ie-sam3-apply-btn")?.addEventListener("click", () => {
|
||||
this._applySelectedSam3Masks();
|
||||
});
|
||||
} else {
|
||||
body.innerHTML = `<span style="font-size:11px;color:var(--wfm-text-secondary);">No options</span>`;
|
||||
}
|
||||
@@ -1156,28 +1372,49 @@ class ImageEditTab {
|
||||
ctx.clearRect(0, 0, drawCanvas.width, drawCanvas.height);
|
||||
|
||||
const layers = this._layerMgr.layers;
|
||||
// maskApply=true のマスクの直下(back側、i+1)レイヤーはマスク処理でまとめて描画
|
||||
// layers[0]=front … layers[n-1]=back、走査は back→front (i=n-1→0)
|
||||
const maskedIndices = new Set();
|
||||
for (let i = 0; i < layers.length; i++) {
|
||||
if (layers[i].type === "mask" && layers[i].maskApply && layers[i].visible && i + 1 < layers.length) {
|
||||
maskedIndices.add(i + 1); // 直下のレイヤーを先にスキップ
|
||||
// layers[0]=front … layers[n-1]=back、走査は back→front
|
||||
|
||||
// 前処理: 連続する maskApply=true マスクグループを検出
|
||||
// グループの front 側インデックス → { masks: Layer[], target: Layer, targetIdx }
|
||||
const maskGroupMap = new Map();
|
||||
const skipIndices = new Set();
|
||||
let i = 0;
|
||||
while (i < layers.length) {
|
||||
if (layers[i].type === "mask" && layers[i].maskApply) {
|
||||
const frontIdx = i;
|
||||
const masks = [];
|
||||
while (i < layers.length && layers[i].type === "mask" && layers[i].maskApply) {
|
||||
masks.push(layers[i]);
|
||||
skipIndices.add(i);
|
||||
i++;
|
||||
}
|
||||
if (i < layers.length) {
|
||||
maskGroupMap.set(frontIdx, { masks, target: layers[i], targetIdx: i });
|
||||
skipIndices.add(i); // ターゲットもグループ処理でまとめて描画
|
||||
} else {
|
||||
// ターゲットなし(末尾)→ グループをオーバーレイ表示のみ
|
||||
maskGroupMap.set(frontIdx, { masks, target: null, targetIdx: -1 });
|
||||
}
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = layers.length - 1; i >= 0; i--) {
|
||||
const layer = layers[i];
|
||||
for (let j = layers.length - 1; j >= 0; j--) {
|
||||
if (skipIndices.has(j)) {
|
||||
// マスクグループの front に到達したらグループ全体を描画
|
||||
if (maskGroupMap.has(j)) {
|
||||
const group = maskGroupMap.get(j);
|
||||
this._renderMaskGroup(ctx, drawCanvas, group.masks, group.target);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const layer = layers[j];
|
||||
if (!layer.visible) continue;
|
||||
if (maskedIndices.has(i)) continue; // マスク処理でまとめて描画するのでスキップ
|
||||
|
||||
if (layer.type === "mask") {
|
||||
if (layer.maskApply && i + 1 < layers.length) {
|
||||
// 直下(back側、i+1)のレイヤーをクリッピングマスクとして合成
|
||||
this._renderMaskedLayer(ctx, drawCanvas, layer, layers[i + 1]);
|
||||
} else {
|
||||
// maskApply=false のときはオーバーレイ表示のみ
|
||||
this._renderMaskLayerOverlay(ctx, layer);
|
||||
}
|
||||
// maskApply=false のマスクはオーバーレイ表示のみ
|
||||
this._renderMaskLayerOverlay(ctx, layer);
|
||||
} else {
|
||||
ctx.save();
|
||||
ctx.globalAlpha = layer.opacity;
|
||||
@@ -1190,6 +1427,59 @@ class ImageEditTab {
|
||||
this._compositeMode = true;
|
||||
}
|
||||
|
||||
_renderMaskGroup(ctx, drawCanvas, maskLayers, targetLayer) {
|
||||
const W = drawCanvas.width;
|
||||
const H = drawCanvas.height;
|
||||
|
||||
// ターゲットなし → オーバーレイ表示のみ
|
||||
if (!targetLayer) {
|
||||
for (const ml of maskLayers) {
|
||||
if (ml.visible) this._renderMaskLayerOverlay(ctx, ml);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. マスクグループを合成(Mask Editor One CanvasCompositor と同ロジック)
|
||||
// maskLayers は front→back 順なので back→front(逆順)で合成
|
||||
const maskCanvas = document.createElement("canvas");
|
||||
maskCanvas.width = W;
|
||||
maskCanvas.height = H;
|
||||
const mc = maskCanvas.getContext("2d");
|
||||
for (let k = maskLayers.length - 1; k >= 0; k--) {
|
||||
const ml = maskLayers[k];
|
||||
if (!ml.visible) continue;
|
||||
mc.save();
|
||||
mc.globalAlpha = ml.opacity;
|
||||
mc.globalCompositeOperation = ml.operation === "subtract" ? "destination-out" : "lighten";
|
||||
Layer.applyTransform(mc, ml);
|
||||
mc.drawImage(ml.canvas, -ml.canvas.width / 2, -ml.canvas.height / 2);
|
||||
mc.restore();
|
||||
}
|
||||
|
||||
// 2. 合成マスクでターゲットレイヤーをクリップ
|
||||
const tmp = document.createElement("canvas");
|
||||
tmp.width = W;
|
||||
tmp.height = H;
|
||||
const tc = tmp.getContext("2d");
|
||||
if (targetLayer.visible) {
|
||||
tc.save();
|
||||
tc.globalAlpha = targetLayer.opacity;
|
||||
tc.globalCompositeOperation = targetLayer.blendMode;
|
||||
Layer.applyTransform(tc, targetLayer);
|
||||
tc.drawImage(targetLayer.canvas, -targetLayer.canvas.width / 2, -targetLayer.canvas.height / 2);
|
||||
tc.restore();
|
||||
}
|
||||
tc.globalCompositeOperation = this._maskInverted ? "destination-out" : "destination-in";
|
||||
tc.drawImage(maskCanvas, 0, 0);
|
||||
|
||||
ctx.drawImage(tmp, 0, 0);
|
||||
|
||||
// 3. 全マスクレイヤーのオーバーレイ表示
|
||||
for (const ml of maskLayers) {
|
||||
if (ml.visible) this._renderMaskLayerOverlay(ctx, ml);
|
||||
}
|
||||
}
|
||||
|
||||
_renderMaskedLayer(ctx, drawCanvas, maskLayer, targetLayer, showOverlay = true) {
|
||||
const W = drawCanvas.width;
|
||||
const H = drawCanvas.height;
|
||||
@@ -1330,7 +1620,10 @@ class ImageEditTab {
|
||||
const maskApplyBtn = layer.type === "mask"
|
||||
? `<button class="ie-layer-vis-btn" data-id="${layer.id}" data-action="mask-apply"
|
||||
title="${layer.maskApply ? "Disable clipping mask" : "Enable as clipping mask"}"
|
||||
style="color:${layer.maskApply ? "var(--wfm-primary,#4682e6)" : "inherit"};font-size:11px;">✂</button>`
|
||||
style="color:${layer.maskApply ? "var(--wfm-primary,#4682e6)" : "inherit"};font-size:11px;">✂</button>
|
||||
<button class="ie-layer-vis-btn" data-id="${layer.id}" data-action="mask-op"
|
||||
title="${layer.operation === "subtract" ? "Mode: Subtract (click to switch to Add)" : "Mode: Add (click to switch to Subtract)"}"
|
||||
style="font-size:10px;font-weight:bold;min-width:16px;color:${layer.operation === "subtract" ? "#e2534a" : "#4db84d"};">${layer.operation === "subtract" ? "S" : "A"}</button>`
|
||||
: "";
|
||||
return `
|
||||
<div class="ie-layer-item ${isActive ? "active" : ""}" data-id="${layer.id}" data-action="select" data-type="${layer.type}">
|
||||
@@ -1359,6 +1652,10 @@ class ImageEditTab {
|
||||
this._layerMgr.toggleMaskApply(id);
|
||||
this._updateCompositeView();
|
||||
this._refreshLayerList();
|
||||
} else if (action === "mask-op") {
|
||||
this._layerMgr.toggleOperation(id);
|
||||
this._updateCompositeView();
|
||||
this._refreshLayerList();
|
||||
} else if (action === "lock") {
|
||||
this._layerMgr.toggleLocked(id);
|
||||
// ロック変更はSelectToolのオーバーレイを再描画
|
||||
@@ -1377,6 +1674,11 @@ class ImageEditTab {
|
||||
this._maskTool?.setCanvas(layer.canvas);
|
||||
this._maskTool?.activate();
|
||||
}
|
||||
// operation に合わせて MaskTool の mode を同期
|
||||
if (this._maskTool) {
|
||||
this._maskTool.mode = layer.operation === "subtract" ? "erase" : "paint";
|
||||
this._renderToolOptions("mask");
|
||||
}
|
||||
this._updateCompositeView();
|
||||
} else if (this._activeTool === "draw" && layer) {
|
||||
this._drawTool?.setCanvas(layer.canvas);
|
||||
@@ -1784,10 +2086,430 @@ class ImageEditTab {
|
||||
});
|
||||
}
|
||||
|
||||
_openAbrBrushPicker() {
|
||||
const existing = document.getElementById("wfm-abr-picker-overlay");
|
||||
if (existing) { existing.remove(); return; }
|
||||
|
||||
const overlay = document.createElement("div");
|
||||
overlay.id = "wfm-abr-picker-overlay";
|
||||
Object.assign(overlay.style, {
|
||||
position: "fixed", inset: "0",
|
||||
background: "rgba(0,0,0,0.55)",
|
||||
display: "flex", alignItems: "center", justifyContent: "center",
|
||||
zIndex: "99999",
|
||||
});
|
||||
|
||||
const modal = document.createElement("div");
|
||||
Object.assign(modal.style, {
|
||||
background: "var(--wfm-surface, #2a2a2a)",
|
||||
border: "1px solid var(--wfm-border, #444)",
|
||||
borderRadius: "8px",
|
||||
width: "640px", height: "460px",
|
||||
display: "flex", flexDirection: "column",
|
||||
overflow: "hidden",
|
||||
boxShadow: "0 8px 32px rgba(0,0,0,0.6)",
|
||||
color: "var(--wfm-text, #ddd)",
|
||||
fontFamily: "sans-serif",
|
||||
});
|
||||
|
||||
// Header
|
||||
const header = document.createElement("div");
|
||||
Object.assign(header.style, {
|
||||
display: "flex", alignItems: "center", justifyContent: "space-between",
|
||||
padding: "8px 12px",
|
||||
borderBottom: "1px solid var(--wfm-border, #444)",
|
||||
fontWeight: "bold", fontSize: "13px", flexShrink: "0",
|
||||
});
|
||||
const headerTitle = document.createElement("span");
|
||||
headerTitle.textContent = "ABR Brush Library (Mask Editor One)";
|
||||
const closeBtn = document.createElement("button");
|
||||
closeBtn.textContent = "×";
|
||||
closeBtn.className = "wfm-btn wfm-btn-sm";
|
||||
closeBtn.style.cssText = "font-size:16px;padding:0 6px;";
|
||||
closeBtn.onclick = () => overlay.remove();
|
||||
header.appendChild(headerTitle);
|
||||
header.appendChild(closeBtn);
|
||||
modal.appendChild(header);
|
||||
|
||||
// Body: tree + grid
|
||||
const body = document.createElement("div");
|
||||
Object.assign(body.style, { display: "flex", flex: "1", overflow: "hidden" });
|
||||
|
||||
const treeEl = document.createElement("div");
|
||||
Object.assign(treeEl.style, {
|
||||
width: "150px", flexShrink: "0",
|
||||
borderRight: "1px solid var(--wfm-border, #444)",
|
||||
overflowY: "auto", padding: "4px 0", fontSize: "12px",
|
||||
});
|
||||
|
||||
const gridEl = document.createElement("div");
|
||||
Object.assign(gridEl.style, {
|
||||
flex: "1", overflowY: "auto",
|
||||
display: "flex", flexWrap: "wrap",
|
||||
alignContent: "flex-start", padding: "6px", gap: "4px",
|
||||
});
|
||||
|
||||
body.appendChild(treeEl);
|
||||
body.appendChild(gridEl);
|
||||
modal.appendChild(body);
|
||||
|
||||
// Footer
|
||||
const footer = document.createElement("div");
|
||||
Object.assign(footer.style, {
|
||||
display: "flex", gap: "8px", padding: "8px 12px", flexShrink: "0",
|
||||
borderTop: "1px solid var(--wfm-border, #444)",
|
||||
});
|
||||
const resetBtn = document.createElement("button");
|
||||
resetBtn.className = "wfm-btn wfm-btn-sm";
|
||||
resetBtn.textContent = "⬤ Round Brush (default)";
|
||||
resetBtn.onclick = () => {
|
||||
this._maskTool?.clearImageBrush();
|
||||
this._renderMaskProps("paint");
|
||||
this._renderToolOptions("mask");
|
||||
overlay.remove();
|
||||
};
|
||||
footer.appendChild(resetBtn);
|
||||
modal.appendChild(footer);
|
||||
|
||||
overlay.appendChild(modal);
|
||||
overlay.addEventListener("mousedown", e => { if (e.target === overlay) overlay.remove(); });
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
// ── Data helpers ────────────────────────────────────────────
|
||||
const tree = this._abrBrushTree;
|
||||
let selectedFolder = null;
|
||||
const expanded = new Set();
|
||||
|
||||
const collectFiles = (nodes) => {
|
||||
const result = [];
|
||||
for (const n of nodes) {
|
||||
if (n.type === "file") result.push(n);
|
||||
else if (n.type === "folder" && n.children) result.push(...collectFiles(n.children));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const findFolder = (nodes, path) => {
|
||||
for (const n of nodes) {
|
||||
if (n.type !== "folder") continue;
|
||||
if (n.path === path) return n;
|
||||
const found = findFolder(n.children || [], path);
|
||||
if (found) return found;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// ── Brush thumbnail ─────────────────────────────────────────
|
||||
const makeBrushThumb = (node) => {
|
||||
const item = document.createElement("div");
|
||||
Object.assign(item.style, {
|
||||
width: "72px", cursor: "pointer", textAlign: "center",
|
||||
padding: "4px", borderRadius: "4px",
|
||||
border: "1px solid var(--wfm-border, #444)",
|
||||
background: "var(--wfm-bg, #1a1a1a)",
|
||||
boxSizing: "border-box",
|
||||
});
|
||||
item.title = node.name;
|
||||
|
||||
const THUMB = 64;
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = THUMB; canvas.height = THUMB;
|
||||
canvas.style.cssText = "display:block;border-radius:3px;";
|
||||
const ctx = canvas.getContext("2d");
|
||||
ctx.fillStyle = "#1a1a2a";
|
||||
ctx.fillRect(0, 0, THUMB, THUMB);
|
||||
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
const srcW = img.naturalWidth || img.width;
|
||||
const srcH = img.naturalHeight || img.height;
|
||||
const aspect = srcW / srcH || 1;
|
||||
const WORK = 128;
|
||||
const wW = aspect >= 1 ? WORK : Math.max(1, Math.round(WORK * aspect));
|
||||
const wH = aspect >= 1 ? Math.max(1, Math.round(WORK / aspect)) : WORK;
|
||||
const tmp = document.createElement("canvas");
|
||||
tmp.width = wW; tmp.height = wH;
|
||||
const stx = tmp.getContext("2d");
|
||||
stx.drawImage(img, 0, 0, wW, wH);
|
||||
const id = stx.getImageData(0, 0, wW, wH);
|
||||
const d = id.data;
|
||||
let hasAlpha = false;
|
||||
for (let i = 3; i < d.length; i += 4) if (d[i] < 250) { hasAlpha = true; break; }
|
||||
let invertLum = false;
|
||||
if (!hasAlpha) {
|
||||
const corners = [0, wW - 1, wW * (wH - 1), wW * wH - 1];
|
||||
let bg = 0;
|
||||
for (const ci of corners) { const ii = ci * 4; bg += (d[ii] * 0.299 + d[ii+1] * 0.587 + d[ii+2] * 0.114) / 255; }
|
||||
invertLum = (bg / corners.length) > 0.5;
|
||||
}
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
const a = hasAlpha ? d[i+3] / 255 : (() => { const l = (d[i]*0.299 + d[i+1]*0.587 + d[i+2]*0.114)/255; return invertLum ? 1-l : l; })();
|
||||
d[i] = d[i+1] = d[i+2] = 255; d[i+3] = Math.round(a * 255);
|
||||
}
|
||||
stx.putImageData(id, 0, 0);
|
||||
const THRESHOLD = 15;
|
||||
let x0 = wW, x1 = -1, y0 = wH, y1 = -1;
|
||||
for (let y = 0; y < wH; y++) for (let x = 0; x < wW; x++) if (d[(y*wW+x)*4+3] > THRESHOLD) { if (x<x0)x0=x; if(x>x1)x1=x; if(y<y0)y0=y; if(y>y1)y1=y; }
|
||||
if (x1 >= x0 && y1 >= y0) {
|
||||
const cW = x1-x0+1, cH = y1-y0+1;
|
||||
const s = Math.min((THUMB-4)/cW, (THUMB-4)/cH);
|
||||
ctx.drawImage(tmp, x0, y0, cW, cH, Math.round((THUMB-Math.round(cW*s))/2), Math.round((THUMB-Math.round(cH*s))/2), Math.round(cW*s), Math.round(cH*s));
|
||||
}
|
||||
};
|
||||
img.src = `/mask_editor/brushes/raw?path=${encodeURIComponent(node.path)}`;
|
||||
item.appendChild(canvas);
|
||||
|
||||
const label = document.createElement("div");
|
||||
label.textContent = node.name;
|
||||
Object.assign(label.style, { fontSize: "10px", marginTop: "2px", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", color: "var(--wfm-text-secondary, #999)" });
|
||||
item.appendChild(label);
|
||||
|
||||
item.addEventListener("mouseenter", () => { item.style.background = "color-mix(in srgb, var(--wfm-primary, #4682e6) 20%, transparent)"; item.style.borderColor = "var(--wfm-primary, #4682e6)"; });
|
||||
item.addEventListener("mouseleave", () => { item.style.background = "var(--wfm-bg, #1a1a1a)"; item.style.borderColor = "var(--wfm-border, #444)"; });
|
||||
item.onclick = () => {
|
||||
const loadImg = new Image();
|
||||
loadImg.onload = () => {
|
||||
this._maskTool?.setImageBrush(loadImg, node.name);
|
||||
this._renderMaskProps("paint");
|
||||
this._renderToolOptions("mask");
|
||||
overlay.remove();
|
||||
};
|
||||
loadImg.src = `/mask_editor/brushes/raw?path=${encodeURIComponent(node.path)}`;
|
||||
};
|
||||
return item;
|
||||
};
|
||||
|
||||
// ── Grid rendering ─────────────────────────────────────────
|
||||
const showFolder = (path) => {
|
||||
const files = path === null ? collectFiles(tree) : collectFiles(findFolder(tree, path)?.children || []);
|
||||
gridEl.innerHTML = "";
|
||||
if (files.length === 0) {
|
||||
const msg = document.createElement("span");
|
||||
msg.style.cssText = "font-size:12px;color:var(--wfm-text-secondary,#999);padding:12px;";
|
||||
msg.textContent = tree.length === 0 ? "No brushes installed" : "No brushes in this folder";
|
||||
gridEl.appendChild(msg);
|
||||
return;
|
||||
}
|
||||
for (const file of files) gridEl.appendChild(makeBrushThumb(file));
|
||||
};
|
||||
|
||||
// ── Tree rendering ─────────────────────────────────────────
|
||||
const renderTree = () => {
|
||||
treeEl.innerHTML = "";
|
||||
const allItem = document.createElement("div");
|
||||
Object.assign(allItem.style, {
|
||||
padding: "5px 10px", cursor: "pointer", fontSize: "12px",
|
||||
background: selectedFolder === null ? "color-mix(in srgb, var(--wfm-primary, #4682e6) 25%, transparent)" : "",
|
||||
});
|
||||
allItem.textContent = "All Brushes";
|
||||
allItem.onclick = () => { selectedFolder = null; renderTree(); showFolder(null); };
|
||||
treeEl.appendChild(allItem);
|
||||
|
||||
const renderNodes = (nodes, depth) => {
|
||||
for (const n of nodes) {
|
||||
if (n.type !== "folder") continue;
|
||||
const isExpanded = expanded.has(n.path);
|
||||
const item = document.createElement("div");
|
||||
Object.assign(item.style, {
|
||||
padding: `5px 10px 5px ${10 + depth * 12}px`,
|
||||
cursor: "pointer", fontSize: "12px", display: "flex", alignItems: "center", gap: "4px",
|
||||
background: selectedFolder === n.path ? "color-mix(in srgb, var(--wfm-primary, #4682e6) 25%, transparent)" : "",
|
||||
});
|
||||
const arrow = document.createElement("span");
|
||||
arrow.style.cssText = "font-size:9px;color:var(--wfm-text-secondary,#999);flex-shrink:0;";
|
||||
arrow.textContent = isExpanded ? "▼" : "▶";
|
||||
const nameSpan = document.createElement("span");
|
||||
nameSpan.textContent = n.name;
|
||||
nameSpan.style.overflow = "hidden";
|
||||
nameSpan.style.textOverflow = "ellipsis";
|
||||
nameSpan.style.whiteSpace = "nowrap";
|
||||
item.appendChild(arrow);
|
||||
item.appendChild(nameSpan);
|
||||
item.onclick = () => {
|
||||
if (isExpanded) expanded.delete(n.path); else expanded.add(n.path);
|
||||
selectedFolder = n.path;
|
||||
renderTree(); showFolder(n.path);
|
||||
};
|
||||
treeEl.appendChild(item);
|
||||
if (isExpanded) renderNodes(n.children || [], depth + 1);
|
||||
}
|
||||
};
|
||||
renderNodes(tree, 0);
|
||||
};
|
||||
|
||||
renderTree();
|
||||
showFolder(null);
|
||||
}
|
||||
|
||||
async _runSam3Segment() {
|
||||
if (!this._layerMgr || this._sam3Loading) return;
|
||||
const prompt = this._sam3Prompt.trim();
|
||||
if (!prompt) { showToast("Please enter a prompt", "warning"); return; }
|
||||
|
||||
// 推論対象: アクティブレイヤー(マスクなら下のイメージレイヤーを探す)
|
||||
let imageLayer = this._layerMgr.activeLayer;
|
||||
if (!imageLayer || imageLayer.type === "mask") {
|
||||
imageLayer = this._layerMgr.layers.find(l => l.type !== "mask" && l.visible);
|
||||
}
|
||||
if (!imageLayer) { showToast("No image layer found", "error"); return; }
|
||||
|
||||
const NODE_ID = "wfs_sam3";
|
||||
this._sam3Loading = true;
|
||||
this._sam3Results = [];
|
||||
this._sam3Selected = new Set();
|
||||
this._renderToolOptions("mask");
|
||||
this._renderMaskProps("sam3");
|
||||
|
||||
try {
|
||||
const dataUrl = imageLayer.canvas.toDataURL("image/png");
|
||||
await fetch("/mask_editor/store_image", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ node_id: NODE_ID, image_b64: dataUrl }),
|
||||
});
|
||||
|
||||
const resp = await fetch("/mask_editor/sam3/segment", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ node_id: NODE_ID, prompt, max_masks: this._sam3MaxMasks }),
|
||||
});
|
||||
const json = await resp.json();
|
||||
if (json.error) throw new Error(json.error);
|
||||
this._sam3Results = json.masks || [];
|
||||
if (this._sam3Results.length === 0) showToast("No masks found", "warning");
|
||||
else showToast(`${this._sam3Results.length} mask(s) found`, "success");
|
||||
} catch (err) {
|
||||
showToast("SAM3 error: " + err.message, "error");
|
||||
} finally {
|
||||
this._sam3Loading = false;
|
||||
this._renderToolOptions("mask");
|
||||
this._renderMaskProps("sam3");
|
||||
}
|
||||
}
|
||||
|
||||
async _applySelectedSam3Masks() {
|
||||
if (!this._layerMgr || this._sam3Selected.size === 0) return;
|
||||
const indices = [...this._sam3Selected].sort((a, b) => a - b);
|
||||
const masks = indices.map(i => this._sam3Results[i]).filter(Boolean);
|
||||
if (masks.length === 0) return;
|
||||
|
||||
let maskLayer = this._layerMgr.activeLayer;
|
||||
if (!maskLayer || maskLayer.type !== "mask") {
|
||||
const ref = this._layerMgr.activeLayer;
|
||||
maskLayer = this._layerMgr.addLayer("mask", "SAM3 Mask", {
|
||||
contentW: ref?.canvas.width ?? this._layerMgr.width,
|
||||
contentH: ref?.canvas.height ?? this._layerMgr.height,
|
||||
displayW: ref?.displayW ?? this._layerMgr.width,
|
||||
displayH: ref?.displayH ?? this._layerMgr.height,
|
||||
x: ref?.x ?? 0, y: ref?.y ?? 0,
|
||||
});
|
||||
this._layerMgr.setActive(maskLayer.id);
|
||||
}
|
||||
|
||||
this._saveUndo();
|
||||
for (const r of masks) {
|
||||
await this._applySam3Mask(maskLayer, r.mask_b64, this._sam3Mode);
|
||||
}
|
||||
|
||||
this._updateCompositeView();
|
||||
this._refreshLayerList();
|
||||
showToast(`SAM3: ${masks.length} mask(s) applied (${this._sam3Mode})`, "success");
|
||||
}
|
||||
|
||||
_applySam3Mask(maskLayer, maskB64, mode = "add") {
|
||||
return new Promise(resolve => {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
const W = maskLayer.canvas.width;
|
||||
const H = maskLayer.canvas.height;
|
||||
// グレースケール輝度 → アルファ白マスクに変換
|
||||
const off = document.createElement("canvas");
|
||||
off.width = W; off.height = H;
|
||||
const mc = off.getContext("2d");
|
||||
mc.drawImage(img, 0, 0, W, H);
|
||||
const imgData = mc.getImageData(0, 0, W, H);
|
||||
const d = imgData.data;
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
const lum = d[i];
|
||||
d[i] = d[i+1] = d[i+2] = 255;
|
||||
d[i+3] = lum;
|
||||
}
|
||||
mc.putImageData(imgData, 0, 0);
|
||||
// モードに合わせてマスクキャンバスに合成
|
||||
maskLayer.ctx.save();
|
||||
maskLayer.ctx.globalCompositeOperation = mode === "erase" ? "destination-out" : "source-over";
|
||||
maskLayer.ctx.drawImage(off, 0, 0);
|
||||
maskLayer.ctx.restore();
|
||||
resolve();
|
||||
};
|
||||
img.onerror = resolve;
|
||||
img.src = maskB64;
|
||||
});
|
||||
}
|
||||
|
||||
async _bgRemoveBiRefNet(dataUrl, onStatus) {
|
||||
// TODO: POST /api/wfm/bg-remove — Python backend using comfy.bg_removal_model
|
||||
// Returns RGBA PNG data-URL with background removed
|
||||
throw new Error("BiRefNet not yet implemented");
|
||||
const NODE_ID = "wfs_bgremove";
|
||||
|
||||
// 1. アクティブレイヤー画像を Mask Editor One のキャッシュに登録
|
||||
onStatus("Sending image...");
|
||||
const storeResp = await fetch("/mask_editor/store_image", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ node_id: NODE_ID, image_b64: dataUrl }),
|
||||
});
|
||||
if (!storeResp.ok) throw new Error("Failed to cache image for BiRefNet");
|
||||
|
||||
// 2. BiRefNet 推論実行
|
||||
onStatus("Running BiRefNet...");
|
||||
const resp = await fetch("/mask_editor/birefnet/remove_bg", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ node_id: NODE_ID }),
|
||||
});
|
||||
const json = await resp.json();
|
||||
if (json.error) throw new Error(json.error);
|
||||
|
||||
// 3. グレースケールマスク (白=前景) → RGBA PNG に変換して返す
|
||||
onStatus("Compositing...");
|
||||
return await this._applyMaskToImage(dataUrl, json.mask_b64);
|
||||
}
|
||||
|
||||
async _applyMaskToImage(imageB64, maskB64) {
|
||||
const loadImage = src => new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.onload = () => resolve(img);
|
||||
img.onerror = () => reject(new Error("Image load failed: " + src.slice(0, 40)));
|
||||
img.src = src;
|
||||
});
|
||||
const [origImg, maskImg] = await Promise.all([loadImage(imageB64), loadImage(maskB64)]);
|
||||
|
||||
const w = origImg.naturalWidth;
|
||||
const h = origImg.naturalHeight;
|
||||
|
||||
// マスク: グレースケール輝度値 → アルファチャンネル (RGBA 白マスク)
|
||||
const maskCanvas = document.createElement("canvas");
|
||||
maskCanvas.width = w;
|
||||
maskCanvas.height = h;
|
||||
const mc = maskCanvas.getContext("2d");
|
||||
mc.drawImage(maskImg, 0, 0, w, h);
|
||||
const maskData = mc.getImageData(0, 0, w, h);
|
||||
const md = maskData.data;
|
||||
for (let i = 0; i < md.length; i += 4) {
|
||||
md[i + 3] = md[i]; // 輝度 → アルファ
|
||||
md[i] = md[i + 1] = md[i + 2] = 255;
|
||||
}
|
||||
mc.putImageData(maskData, 0, 0);
|
||||
|
||||
// 元画像にマスクを destination-in で適用
|
||||
const out = document.createElement("canvas");
|
||||
out.width = w;
|
||||
out.height = h;
|
||||
const ctx = out.getContext("2d");
|
||||
ctx.drawImage(origImg, 0, 0, w, h);
|
||||
ctx.globalCompositeOperation = "destination-in";
|
||||
ctx.drawImage(maskCanvas, 0, 0, w, h);
|
||||
|
||||
return out.toDataURL("image/png");
|
||||
}
|
||||
|
||||
async _applyBgRemove() {
|
||||
|
||||
@@ -28,6 +28,7 @@ export class Layer {
|
||||
this.textProps = null; // テキストレイヤー用プロパティ(再編集・再描画に使用)
|
||||
this.locked = false; // ロック中は SelectTool の変形を禁止
|
||||
this.maskApply = false; // マスクレイヤー: true=クリッピングマスクとして機能
|
||||
this.operation = "add"; // マスクレイヤー合成モード: "add" | "subtract"
|
||||
}
|
||||
|
||||
clear() {
|
||||
@@ -59,6 +60,7 @@ export class Layer {
|
||||
textProps: this.textProps ?? null,
|
||||
locked: this.locked ?? false,
|
||||
maskApply: this.maskApply ?? false,
|
||||
operation: this.operation ?? "add",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -80,6 +82,7 @@ export class Layer {
|
||||
layer.textProps = json.textProps ?? null;
|
||||
layer.locked = json.locked ?? false;
|
||||
layer.maskApply = json.maskApply ?? false;
|
||||
layer.operation = json.operation ?? "add";
|
||||
|
||||
if (json.imageData) {
|
||||
return new Promise(resolve => {
|
||||
@@ -182,6 +185,14 @@ export class LayerManager {
|
||||
if (layer && layer.type === "mask") { layer.maskApply = !layer.maskApply; this._emit("change"); }
|
||||
}
|
||||
|
||||
toggleOperation(id) {
|
||||
const layer = this.layers.find(l => l.id === id);
|
||||
if (layer && layer.type === "mask") {
|
||||
layer.operation = layer.operation === "add" ? "subtract" : "add";
|
||||
this._emit("change");
|
||||
}
|
||||
}
|
||||
|
||||
setOpacity(id, opacity) {
|
||||
const layer = this.layers.find(l => l.id === id);
|
||||
if (layer) { layer.opacity = Math.max(0, Math.min(1, opacity)); this._emit("change"); }
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
* White-paint / erase brush for mask layers.
|
||||
* paint mode: draws white (opaque) = mask present
|
||||
* erase mode: destination-out (transparent) = mask absent
|
||||
*
|
||||
* Supports circular soft brush (built-in) and image brushes loaded
|
||||
* from Mask Editor One's ABR brush library (optional).
|
||||
*/
|
||||
|
||||
export class MaskTool {
|
||||
@@ -11,34 +14,69 @@ export class MaskTool {
|
||||
this.ctx = canvas?.getContext("2d");
|
||||
this.brushSize = 30;
|
||||
this.hardness = 0.85;
|
||||
this.spacing = 0.25; // stamp interval as fraction of brushSize (image brush only)
|
||||
this.mode = "paint"; // "paint" | "erase"
|
||||
|
||||
// Image brush from ABR library (null = default circle brush)
|
||||
this.brushImage = null;
|
||||
this.brushName = "Circle";
|
||||
this.angle = 0; // degrees [0, 359]
|
||||
this.sizeJitter = false;
|
||||
this.sizeJitterAmount = 0.5; // 0–1: fraction of brushSize that can be removed
|
||||
this.rotationJitter = false;
|
||||
|
||||
this._drawing = false;
|
||||
this._lastX = 0;
|
||||
this._lastY = 0;
|
||||
|
||||
// Cached circle stamp
|
||||
this._stamp = null;
|
||||
this._stampSize = 0;
|
||||
this._stampHard = 0;
|
||||
this._stampMode = null;
|
||||
|
||||
// Cached image stamp
|
||||
this._imgStamp = null;
|
||||
this._imgStampSize = 0;
|
||||
this._imgStampImg = null;
|
||||
|
||||
// Stroke buffer: prevents intra-stroke opacity accumulation (image brush only)
|
||||
this._baseCanvas = null;
|
||||
this._strokeCanvas = null;
|
||||
this._strokeCtx = null;
|
||||
|
||||
this._onChange = null;
|
||||
}
|
||||
|
||||
setCanvas(canvas) {
|
||||
this.canvas = canvas;
|
||||
this.ctx = canvas.getContext("2d");
|
||||
this._stamp = null;
|
||||
this._stamp = null;
|
||||
this._imgStamp = null;
|
||||
}
|
||||
|
||||
onChange(fn) { this._onChange = fn; }
|
||||
|
||||
setImageBrush(img, name) {
|
||||
this.brushImage = img;
|
||||
this.brushName = name;
|
||||
this._imgStamp = null;
|
||||
}
|
||||
|
||||
clearImageBrush() {
|
||||
this.brushImage = null;
|
||||
this.brushName = "Circle";
|
||||
this._stamp = null;
|
||||
this._imgStamp = null;
|
||||
}
|
||||
|
||||
activate() {
|
||||
if (this.canvas) this.canvas.style.cursor = "none";
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
this._drawing = false;
|
||||
this._clearStrokeBuffer();
|
||||
if (this.canvas) this.canvas.style.cursor = "";
|
||||
}
|
||||
|
||||
@@ -46,12 +84,23 @@ export class MaskTool {
|
||||
this._drawing = true;
|
||||
this._lastX = x;
|
||||
this._lastY = y;
|
||||
this._paint(x, y);
|
||||
if (this.brushImage) {
|
||||
this._initStrokeBuffer();
|
||||
this._paintToStroke(x, y);
|
||||
this._mergeStroke();
|
||||
} else {
|
||||
this._paint(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
onMouseMove(x, y) {
|
||||
if (!this._drawing) return;
|
||||
this._paintLine(this._lastX, this._lastY, x, y);
|
||||
if (this.brushImage) {
|
||||
this._paintLineToStroke(this._lastX, this._lastY, x, y);
|
||||
this._mergeStroke();
|
||||
} else {
|
||||
this._paintLine(this._lastX, this._lastY, x, y);
|
||||
}
|
||||
this._lastX = x;
|
||||
this._lastY = y;
|
||||
}
|
||||
@@ -59,6 +108,7 @@ export class MaskTool {
|
||||
onMouseUp() {
|
||||
if (this._drawing) {
|
||||
this._drawing = false;
|
||||
this._clearStrokeBuffer();
|
||||
if (this._onChange) this._onChange();
|
||||
}
|
||||
}
|
||||
@@ -67,6 +117,77 @@ export class MaskTool {
|
||||
if (this._drawing) this.onMouseUp();
|
||||
}
|
||||
|
||||
// ── Stroke buffer (image brush only) ─────────────────────────────
|
||||
|
||||
_initStrokeBuffer() {
|
||||
const w = this.canvas.width;
|
||||
const h = this.canvas.height;
|
||||
this._baseCanvas = document.createElement("canvas");
|
||||
this._baseCanvas.width = w;
|
||||
this._baseCanvas.height = h;
|
||||
this._baseCanvas.getContext("2d").drawImage(this.canvas, 0, 0);
|
||||
this._strokeCanvas = document.createElement("canvas");
|
||||
this._strokeCanvas.width = w;
|
||||
this._strokeCanvas.height = h;
|
||||
this._strokeCtx = this._strokeCanvas.getContext("2d");
|
||||
}
|
||||
|
||||
_clearStrokeBuffer() {
|
||||
this._baseCanvas = null;
|
||||
this._strokeCanvas = null;
|
||||
this._strokeCtx = null;
|
||||
}
|
||||
|
||||
_mergeStroke() {
|
||||
const ctx = this.ctx;
|
||||
const w = this.canvas.width;
|
||||
const h = this.canvas.height;
|
||||
ctx.clearRect(0, 0, w, h);
|
||||
ctx.drawImage(this._baseCanvas, 0, 0);
|
||||
ctx.globalCompositeOperation = this.mode === "erase" ? "destination-out" : "lighten";
|
||||
ctx.drawImage(this._strokeCanvas, 0, 0);
|
||||
ctx.globalCompositeOperation = "source-over";
|
||||
}
|
||||
|
||||
_paintToStroke(x, y) {
|
||||
const saved = this.ctx;
|
||||
this.ctx = this._strokeCtx;
|
||||
|
||||
if (this.sizeJitter || this.rotationJitter) {
|
||||
const savedSize = this.brushSize;
|
||||
const savedAngle = this.angle;
|
||||
const savedStamp = this._imgStamp;
|
||||
const savedStampSize = this._imgStampSize;
|
||||
if (this.sizeJitter) {
|
||||
this.brushSize = Math.max(1, savedSize * (1 - Math.random() * this.sizeJitterAmount));
|
||||
}
|
||||
if (this.rotationJitter) {
|
||||
this.angle = Math.random() * 360;
|
||||
}
|
||||
this._paintImageBrush(x, y);
|
||||
this.brushSize = savedSize;
|
||||
this.angle = savedAngle;
|
||||
this._imgStamp = savedStamp;
|
||||
this._imgStampSize = savedStampSize;
|
||||
} else {
|
||||
this._paintImageBrush(x, y);
|
||||
}
|
||||
|
||||
this.ctx = saved;
|
||||
}
|
||||
|
||||
_paintLineToStroke(x0, y0, x1, y1) {
|
||||
const dist = Math.hypot(x1 - x0, y1 - y0);
|
||||
const step = Math.max(1, this.brushSize * this.spacing);
|
||||
const steps = Math.ceil(dist / step);
|
||||
for (let i = 1; i <= steps; i++) {
|
||||
const t = i / steps;
|
||||
this._paintToStroke(x0 + (x1 - x0) * t, y0 + (y1 - y0) * t);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Circle brush ─────────────────────────────────────────────────
|
||||
|
||||
_getStamp() {
|
||||
if (
|
||||
this._stamp &&
|
||||
@@ -121,4 +242,83 @@ export class MaskTool {
|
||||
this._paint(x0 + (x1 - x0) * t, y0 + (y1 - y0) * t);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Image brush ──────────────────────────────────────────────────
|
||||
|
||||
_getImageStamp(size) {
|
||||
size = Math.max(1, size);
|
||||
if (
|
||||
this._imgStamp &&
|
||||
this._imgStampSize === size &&
|
||||
this._imgStampImg === this.brushImage
|
||||
) return this._imgStamp;
|
||||
|
||||
const img = this.brushImage;
|
||||
const srcW = img.naturalWidth || img.width;
|
||||
const srcH = img.naturalHeight || img.height;
|
||||
const aspect = (srcW > 0 && srcH > 0) ? srcW / srcH : 1;
|
||||
|
||||
const stampH = size;
|
||||
const stampW = Math.max(1, Math.round(size * aspect));
|
||||
|
||||
const sc = document.createElement("canvas");
|
||||
sc.width = stampW;
|
||||
sc.height = stampH;
|
||||
const stx = sc.getContext("2d");
|
||||
stx.drawImage(img, 0, 0, stampW, stampH);
|
||||
|
||||
const imgData = stx.getImageData(0, 0, stampW, stampH);
|
||||
const d = imgData.data;
|
||||
|
||||
// Detect alpha channel (ABR-exported PNGs carry alpha = brush density)
|
||||
let hasAlpha = false;
|
||||
for (let i = 3; i < d.length; i += 4) {
|
||||
if (d[i] < 250) { hasAlpha = true; break; }
|
||||
}
|
||||
|
||||
let invertLum = false;
|
||||
if (!hasAlpha) {
|
||||
const corners = [0, stampW - 1, stampW * (stampH - 1), stampW * stampH - 1];
|
||||
let bgLum = 0;
|
||||
for (const ci of corners) {
|
||||
const ii = ci * 4;
|
||||
bgLum += (d[ii] * 0.299 + d[ii + 1] * 0.587 + d[ii + 2] * 0.114) / 255;
|
||||
}
|
||||
invertLum = (bgLum / corners.length) > 0.5;
|
||||
}
|
||||
|
||||
// Convert to white pixels; alpha = brush density
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
let alpha;
|
||||
if (hasAlpha) {
|
||||
alpha = d[i + 3] / 255;
|
||||
} else {
|
||||
const lum = (d[i] * 0.299 + d[i + 1] * 0.587 + d[i + 2] * 0.114) / 255;
|
||||
alpha = invertLum ? 1 - lum : lum;
|
||||
}
|
||||
d[i] = d[i + 1] = d[i + 2] = 255;
|
||||
d[i + 3] = Math.round(alpha * 255);
|
||||
}
|
||||
stx.putImageData(imgData, 0, 0);
|
||||
|
||||
this._imgStamp = sc;
|
||||
this._imgStampSize = size;
|
||||
this._imgStampImg = this.brushImage;
|
||||
return sc;
|
||||
}
|
||||
|
||||
_paintImageBrush(x, y) {
|
||||
const stamp = this._getImageStamp(Math.round(this.brushSize));
|
||||
this.ctx.globalCompositeOperation = "source-over";
|
||||
if (this.angle) {
|
||||
this.ctx.save();
|
||||
this.ctx.translate(Math.round(x), Math.round(y));
|
||||
this.ctx.rotate((this.angle * Math.PI) / 180);
|
||||
this.ctx.drawImage(stamp, -stamp.width / 2, -stamp.height / 2);
|
||||
this.ctx.restore();
|
||||
} else {
|
||||
this.ctx.drawImage(stamp, Math.round(x - stamp.width / 2), Math.round(y - stamp.height / 2));
|
||||
}
|
||||
this.ctx.globalCompositeOperation = "source-over";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1323,8 +1323,8 @@
|
||||
<li id="wfm-help-imageedit-6">Text (T): click on the canvas to place a text input overlay; configure font family, size, bold/italic, align, color in the Tool Options bar; click OK to place the text as an exact-size Text layer; double-click an existing text layer with the Select tool to re-edit</li>
|
||||
<li id="wfm-help-imageedit-7">Shape (S): draw geometric shapes onto the canvas; each committed shape becomes an independent draw layer; Tool Options: Shape type (Rect / Ellipse / Line / FreeLine), Rounded checkbox (Rect / Ellipse only), Fill color + None toggle (hidden for Line / FreeLine), Stroke color + width + None toggle (None hidden for Line / FreeLine where stroke is always active), Opacity slider, ↩ Undo button; drag to draw — a blue dashed outline previews the shape; release to commit</li>
|
||||
<li id="wfm-help-imageedit-7b">Blur (≈): apply Gaussian blur or mosaic to the active layer — whole-layer or region-based (drag a rectangle); see the Blur Tool card below for details</li>
|
||||
<li id="wfm-help-imageedit-7c">BG Remove (⬚): remove the background from the active layer using Lightweight (@imgly, runs in browser) or BiRefNet (Python backend, coming soon); see the BG Remove Tool card below for details</li>
|
||||
<li id="wfm-help-imageedit-7d">Mask (🎭): paint a white mask on the canvas; click "M" in the Layers header to add a mask layer — the Mask tool activates automatically; the mask is shown as a colored semi-transparent overlay; the Properties pane (left of the Layers panel) shows Paint controls; see the Mask Tool card below for details</li>
|
||||
<li id="wfm-help-imageedit-7c">BG Remove (⬚): remove the background from the active layer using Lightweight (@imgly, runs in browser) or BiRefNet (requires Mask Editor One + birefnet.safetensors in ComfyUI/models/background_removal/); see the BG Remove Tool card below for details</li>
|
||||
<li id="wfm-help-imageedit-7d">Mask (🎭): paint a white mask on the canvas with Paint mode or use SAM3 text-prompt segmentation (requires Mask Editor One); click "M" in the Layers header to add a mask layer — the Mask tool activates automatically; the mask is shown as a colored semi-transparent overlay; see the Mask Tool card below for details</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="wfm-help-card">
|
||||
@@ -1354,7 +1354,7 @@
|
||||
<h3 id="wfm-help-imageedit-bgremove-title">BG Remove Tool (⬚)</h3>
|
||||
<ul>
|
||||
<li id="wfm-help-imageedit-bgremove-1">Model — Lightweight (@imgly): runs entirely in the browser using the @imgly/background-removal library loaded from CDN; no server required; first use downloads the model (~40 MB) and caches it for the session</li>
|
||||
<li id="wfm-help-imageedit-bgremove-2">Model — BiRefNet: high-quality background removal using the BiRefNet model via the Workflow Studio Python backend; requires birefnet.safetensors placed in ComfyUI/models/background_removal/ (coming soon)</li>
|
||||
<li id="wfm-help-imageedit-bgremove-2">Model — BiRefNet: high-quality background removal using the BiRefNet model; requires Mask Editor One to be installed and birefnet.safetensors placed in ComfyUI/models/background_removal/</li>
|
||||
<li id="wfm-help-imageedit-bgremove-3">New Layer (checked by default): the result is added as a new layer above the active layer at the same position and display size — the original layer is preserved</li>
|
||||
<li id="wfm-help-imageedit-bgremove-4">When New Layer is unchecked, the active layer's canvas is replaced in-place with the background-removed result</li>
|
||||
<li id="wfm-help-imageedit-bgremove-5">Click Remove BG to start processing; status text shows Loading model → Processing → Done; supports Undo (Ctrl+Z)</li>
|
||||
@@ -1365,9 +1365,12 @@
|
||||
<ul>
|
||||
<li id="wfm-help-imageedit-mask-1">Add a mask layer: click the "M" button in the Layers panel header; the new mask layer is inserted above the active layer and the Mask tool activates automatically</li>
|
||||
<li id="wfm-help-imageedit-mask-2">Clicking a mask layer in the layer list automatically switches to the Mask tool</li>
|
||||
<li id="wfm-help-imageedit-mask-3">Tool Options bar (Paint / Invert / Overlay / Blur): Paint button toggles the Paint sub-tool; Invert checkbox inverts the overlay preview (shows color where mask is absent); Overlay color picker changes the preview color (default red); Blur slider (0–50 px) softens the overlay edge</li>
|
||||
<li id="wfm-help-imageedit-mask-4">Properties pane (left of the Layers panel, visible when Mask tool is active): Size (1–200 px), Hardness (0–100%), Mode — Add button draws white (mask present) / Erase button removes to transparent (mask absent); the active mode is highlighted in blue</li>
|
||||
<li id="wfm-help-imageedit-mask-3">Tool Options bar (Paint / SAM3 / Invert / Overlay / Blur): Paint/SAM3 buttons switch sub-tools; Invert checkbox inverts the overlay preview (shows color where mask is absent); Overlay color picker changes the preview color (default red); Blur slider (0–50 px) softens the overlay edge; SAM3 button is disabled when Mask Editor One is not installed</li>
|
||||
<li id="wfm-help-imageedit-mask-4">Properties pane — Paint mode: Mode (Add / Erase), Size (1–200 px), Hardness (0–100%); MASK EDITOR ONE section (visible when Mask Editor One is installed): Select button opens the ABR brush library — choosing a brush replaces the default circle brush; ✕ clears the brush back to Circle; when an image brush is active, Hardness is disabled and additional controls appear: Spacing (stamp interval 5–100%), Angle (rotation 0–359°), Sz Jitter (random size reduction per stamp 0–100%), Rot. Jitter (random rotation per stamp on/off)</li>
|
||||
<li id="wfm-help-imageedit-mask-5">✂ button on a mask layer row: toggles the layer as a clipping mask — when enabled (blue), the mask clips the layer directly below it so only the painted area is visible; clipping is applied when saving PNG / Gallery / ComfyUI</li>
|
||||
<li id="wfm-help-imageedit-mask-6">SAM3 (Mask Editor One required): text-prompt segmentation powered by the SAM3 model; enter a description of the object to segment (e.g. "cat", "person"), set Max (maximum mask candidates: 3/6/9/12), then click Segment</li>
|
||||
<li id="wfm-help-imageedit-mask-7">SAM3 workflow: after Segment, candidate masks appear as thumbnails in the Properties pane — click to select (blue border + ✓); multiple masks can be selected; click Apply Selected (N) to apply them all; Mode (Add / Erase) controls how masks are merged into the current mask layer; a new mask layer is created automatically if the active layer is not a mask</li>
|
||||
<li id="wfm-help-imageedit-mask-8">ABR Brush Library (Mask Editor One required, Paint mode only): click Select in the MASK EDITOR ONE section to open the brush picker — browse folders on the left, click a thumbnail to apply; "Round Brush (default)" restores the circle brush; brushes are shared with Mask Editor One and stored in its brushes/ folder</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="wfm-help-card">
|
||||
|
||||
@@ -611,27 +611,55 @@ app.registerExtension({
|
||||
{ tooltip: NODE_SETS_TOOLTIP, className: "wfm-node-sets-btn", getIcon: getNodeSetsIcon, styles: null },
|
||||
];
|
||||
|
||||
const replaceButtonIcons = () => {
|
||||
const applyIconToButton = (btn, cfg) => {
|
||||
// Skip if the SVG icon is already in place
|
||||
if (btn.querySelector("svg")) return;
|
||||
btn.classList.add(cfg.className);
|
||||
btn.innerHTML = cfg.getIcon();
|
||||
btn.style.borderRadius = "4px";
|
||||
btn.style.padding = "6px";
|
||||
if (cfg.styles) Object.assign(btn.style, cfg.styles);
|
||||
const svg = btn.querySelector("svg");
|
||||
if (svg) {
|
||||
svg.style.width = "20px";
|
||||
svg.style.height = "20px";
|
||||
}
|
||||
};
|
||||
|
||||
// Initial application — retry until buttons are rendered by Vue
|
||||
const pollUntilFound = () => {
|
||||
let foundAny = false;
|
||||
for (const cfg of buttonConfigs) {
|
||||
document.querySelectorAll(`button[aria-label="${cfg.tooltip}"]`).forEach((btn) => {
|
||||
foundAny = true;
|
||||
btn.classList.add(cfg.className);
|
||||
btn.innerHTML = cfg.getIcon();
|
||||
btn.style.borderRadius = "4px";
|
||||
btn.style.padding = "6px";
|
||||
if (cfg.styles) Object.assign(btn.style, cfg.styles);
|
||||
const svg = btn.querySelector("svg");
|
||||
if (svg) {
|
||||
svg.style.width = "20px";
|
||||
svg.style.height = "20px";
|
||||
}
|
||||
applyIconToButton(btn, cfg);
|
||||
});
|
||||
}
|
||||
if (!foundAny) {
|
||||
requestAnimationFrame(replaceButtonIcons);
|
||||
requestAnimationFrame(pollUntilFound);
|
||||
}
|
||||
};
|
||||
requestAnimationFrame(replaceButtonIcons);
|
||||
requestAnimationFrame(pollUntilFound);
|
||||
|
||||
// MutationObserver: re-apply icons after Vue re-renders the action bar
|
||||
// (e.g. when the Properties Panel is toggled inside a subgraph)
|
||||
if (typeof MutationObserver !== "undefined") {
|
||||
const observer = new MutationObserver(() => {
|
||||
for (const cfg of buttonConfigs) {
|
||||
document.querySelectorAll(`button[aria-label="${cfg.tooltip}"]`).forEach((btn) => {
|
||||
// Only re-apply when Vue has reset innerHTML back to <i>
|
||||
if (btn.querySelector("i")) {
|
||||
applyIconToButton(btn, cfg);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
const watchNode =
|
||||
document.querySelector("[data-testid='action-bar-buttons']") ||
|
||||
document.querySelector(".actionbar-container") ||
|
||||
document.body;
|
||||
observer.observe(watchNode, { childList: true, subtree: true });
|
||||
window.__wfmIconObserver = observer;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user