Compare commits

...
1 Commits
Author SHA1 Message Date
ketle-manandClaude Sonnet 4.6 0d8ae03c7b feat: v0.3.59 — Image Edit Mask Tool 実装・Draw/Mask 描画バグ修正・クリッピング保存対応
- Mask Tool (🎭) 新規実装: マスクレイヤー追加(M ボタン)・プロパティペイン(Size/Hardness/Add-Erase)・ツールオプションバー(Paint/Invert/Overlay/Blur)・マスクオーバーレイ表示
- クリッピングマスク機能: ✂ ボタンで直下レイヤーをマスク範囲でクリッピング;PNG保存・Gallery・ComfyUI送信に反映
- Draw/Mask 描画バグ修正: layer.canvas 直接描画により描画中も全レイヤーが常時表示
- レイヤーパネル幅 190→220px (✂ ボタン追加による見切れ解消)
- ヘルプ更新 (EN/JA/ZH): Mask Tool カード追加・Add/Erase ボタン・✂ ボタン説明

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-27 12:39:34 +09:00
11 changed files with 680 additions and 45 deletions
+77
View File
@@ -1,5 +1,82 @@
# DEVLOG - ComfyUI-Workflow-Studio
## 2026-06-27: v0.3.59 — Image Edit Mask Tool 実装・Draw/Mask 描画バグ修正・クリッピング保存対応
**変更ファイル**: `static/js/image-edit-tab.js`, `static/js/image-edit/MaskTool.js`, `static/js/image-edit/DrawTool.js`, `static/js/image-edit/LayerManager.js`, `templates/index.html`, `static/css/image-edit-tab.css`, `static/js/i18n.js`, `static/js/app.js`
### 概要
Image Edit タブに Mask Tool (🎭) を追加した。マスクレイヤーへの白描画・消去・クリッピングマスク機能を実装。併せて Draw / Mask 描画中に他レイヤーが消えるバグ、およびクリッピング有効時に保存へ反映されないバグを修正した。
---
### Mask Tool 新規実装
#### MaskTool.js(新規)
- 白ペイント / destination-out 消去の soft round brush
- DrawTool と同アーキテクチャ(stamp キャッシュ・`_paintLine` 補間)
- paint モード: 白ラジアルグラデーション stamp
- erase モード: 黒 stamp + `destination-out` globalCompositeOperation
#### image-edit-tab.js
- `TOOL_DEFS` の mask エントリを `ready: true` に変更しツールを有効化
- `_maskSubtool`, `_maskInverted`, `_maskOverlayColor`, `_maskBlur` を状態として保持
- **ツールオプションバー(mask)**: Paint ボタン、Invert チェックボックス、Overlay カラーピッカー、Blur スライダー
- **プロパティペイン** (`ie-props-pane`): Mask ツール選択時に表示;Size・Hardness・Mode(Add/Erase ボタン)
- `_renderMaskLayerOverlay()`: overlayColor fill → `destination-in`/`destination-out` でマスクを適用 → 半透明合成
- `ie-add-mask-btn` ハンドラ: マスクレイヤー追加 → Mask ツール自動切り替え
- レイヤーリストでマスクレイヤーをクリックすると自動的に Mask ツールに切り替え
#### templates/index.html
- `ie-props-pane` ペイン追加(レイヤーパネル左隣)
- レイヤーヘッダーに "M" ボタン追加
#### image-edit-tab.css
- `.ie-props-pane` / `.ie-props-header` / `.ie-props-body` / `.ie-props-row` スタイル追加
- マスクレイヤー行の ⬚ アイコンを赤で強調
---
### クリッピングマスク機能
#### LayerManager.js
- `Layer` クラスに `maskApply` プロパティ追加(`toJSON` / `fromJSON` 対応)
- `LayerManager.toggleMaskApply(id)` メソッド追加
#### image-edit-tab.js
- レイヤーリストのマスクレイヤー行に ✂ ボタン追加(`data-action="mask-apply"`);有効時は青色
- `_updateCompositeView`: `maskApply=true` のマスクレイヤー直下(back 側、配列 `i+1`)のレイヤーを tmp canvas でクリッピング合成
- `_renderMaskedLayer(ctx, canvas, maskLayer, targetLayer, showOverlay)` 新メソッド
- `_buildCompositeCanvas`: `LayerManager.composite()` から `_compositeForExport()` に変更
- `_compositeForExport()` 新メソッド: クリッピングを適用しつつマスクオーバーレイは除外して保存用合成を行う
#### image-edit-tab.css
- レイヤーパネル幅 190px → 220px(✂ ボタン追加による見切れを解消)
---
### Draw / Mask 描画バグ修正
**問題**: DrawTool / MaskTool が `drawCanvas` に描いていたため `_loadActiveLayerToCanvas()` がコンポジット表示を上書きし、描画中に他レイヤーが消えていた。
**修正**:
- DrawTool / MaskTool を `layer.canvas` に直接描画するよう変更
- `_onToolMouseDown`(draw/mask): `_loadActiveLayerToCanvas()` を除去し `setCanvas(activeLayer.canvas)` + `_updateCompositeView()` に変更
- `_onToolMouseMove`(draw/mask): `_drawing` フラグが立っている間 `_updateCompositeView()` を都度呼び出し、全レイヤーを常時合成表示
- DrawTool / MaskTool の `onChange`: `_syncActiveLayerFromCanvas()` を除去(layer.canvas 直接描画のため不要)
- `_activateCurrentTool`(draw/mask): `setCanvas(activeLayer.canvas)` を呼ぶよう変更
- DrawTool.js: constructor / `activate()` / `deactivate()` に null ガード追加(`canvas=null` 初期化に対応)
---
### ヘルプ更新(3点セット)
- `templates/index.html`: Mask Tool カード追加(mask-title/1〜5)、`helpImageEdit1`(Mask 追記)、`helpImageEdit7d`・`8b`・`12`(⬚ アイコン)追加
- `static/js/i18n.js`: EN/JA/ZH 全3言語に上記キーを追加;`helpImageEditMask4`(Add/Erase ボタン)・`helpImageEditMask5`(✂ ボタン説明)を更新
- `static/js/app.js`: helpIdMap に `7d`・`8b`・`mask-title`・`mask-1〜5` を追加
---
## 2026-06-27: v0.3.58 — GenerateUI Model タブ GGUF対応拡張(Diffusion Model / Text Encoder)
**変更ファイル**: `static/js/comfyui-workflow.js`, `static/js/comfyui-client.js`, `static/js/comfyui-editor.js`, `static/js/models-tab.js`, `templates/index.html`, `static/js/i18n.js`
+14 -6
View File
@@ -18,7 +18,7 @@ A comprehensive workflow, asset management, and generation UI plugin for [ComfyU
- Built-in AI tools (translation and more)
![Workflow Studio](https://img.shields.io/badge/ComfyUI-Custom_Node-blue)
![Version](https://img.shields.io/badge/version-0.3.58-green)
![Version](https://img.shields.io/badge/version-0.3.59-green)
## Screenshots
@@ -209,18 +209,19 @@ 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.53)
- **Layer-based image editor** — compose images with multiple layers (Image, Text, Draw types) and export the composite as PNG
### Image Edit Tab (v0.3.59)
- **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
- **Tools** — Select (V), Draw (B), Text (T), Shape (S), Blur (≈), BG Remove (⬚); tool options bar updates per active tool
- **Tools** — Select (V), Draw (B), Text (T), Shape (S), Mask (🎭), Blur (≈), BG Remove (⬚); tool options bar updates per active tool
- **Select** — click to select; drag to move; drag corner handles to resize; drag circle handle to rotate; Flip H / Flip V / Rotate angle in the options bar; double-click a text layer to re-edit its content
- **Draw** — freehand brush; options: color, brush size, blend mode
- **Draw** — freehand brush; options: color, brush size, blend mode; paints directly onto the active draw layer while all other layers remain visible
- **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
- **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
- **Layer panel** — layer list with visibility (👁/🚫) and lock (🔒/🔓) toggles; opacity slider; type icons (🖼 image / T text / ✏ draw); Layer 1 is automatically locked on first image load
- **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
- **Text quality** — text layers are rendered at their measured bounding-box size; resizing with the Select tool regenerates the canvas at the new display resolution so text stays sharp
- **Export** — Save PNG (download composite locally); **Save to Gallery** (saves to Gallery root folder with a timestamped default name `wfs-image-YYYYMMDDHHmmss`); **Send to ComfyUI** (uploads to ComfyUI input folder for use in Load Image nodes)
@@ -353,6 +354,13 @@ Click the **camera icon** (next to the W button) in ComfyUI's top bar to capture
## Changelog
### v0.3.59
- **Image Edit — Mask Tool** — new Mask tool (🎭) in the Image Edit sidebar; click **M** in the Layers header to add a mask layer (Mask tool activates automatically); clicking a mask layer in the layer list also switches to the Mask tool; **Tool Options bar**: Paint button, Invert checkbox (inverts overlay preview), Overlay color picker (default red), Blur slider (0–50 px) for overlay edge softening; **Properties pane** (left of the Layers panel, shown when Mask tool is active): Size (1–200 px), Hardness (0–100%), Mode — **Add** / **Erase** toggle buttons (active mode highlighted in blue)
- **Image Edit — Clipping mask (✂ button)** — each mask layer row shows a ✂ toggle; when enabled (blue), the mask clips the layer directly below it so only the painted area is visible; clipping is applied to PNG save / Save to Gallery / Send to ComfyUI exports
- **Image Edit — Draw & Mask paint bugfix** — Draw and Mask tools now paint directly onto `layer.canvas`; all other layers remain fully visible during brush strokes (previously the composite view was replaced by the active layer only while painting)
- **Image Edit — Layer panel width** — increased from 190 px to 220 px to accommodate the additional ✂ button on mask layer rows
- **Help — Mask Tool section** — added Mask Tool card with full i18n support (English / Japanese / Chinese); updated Tools list, layer type icon list, and Layer panel "M button" description
### v0.3.58
- **GenerateUI Model tab — Diffusion Model GGUF support** — `LoaderGGUF` and `LoaderGGUFAdvanced` nodes are now recognized alongside `UNETLoader` / `UnetLoaderGGUF`; the correct input key (`gguf_name` vs `unet_name`) is selected automatically on Apply; the Models tab "GenUI Model" button also applies correctly to `LoaderGGUF` workflows
- **GenerateUI Model tab — Text Encoder expanded (CLIPLoader / DualCLIPLoader / GGUF variants)** — the Text Encoder section now renders a node-type-aware UI: **single CLIP** (`CLIPLoader` / `ClipLoaderGGUF`) shows one clip selector + **type** dropdown + **device** (GGUF only); **Dual CLIP** (`DualCLIPLoader` / `DualClipLoaderGGUF`) shows two clip selectors (clip_name1 / clip_name2) + **type** dropdown + **device** (GGUF only); type options are fetched dynamically from `/object_info`; filter applies to the first selector only
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui-workflow-studio"
description = "A comprehensive workflow, asset management, and generation UI plugin for ComfyUI. Manage workflows, models, images, and prompts; batch generation and Image Feeder in the GenerateUI tab; library side panel with canvas drag & drop and AI tools."
version = "0.3.58"
version = "0.3.59"
license = "MIT"
requires-python = ">= 3.10"
dependencies = ["jinja2"]
+64 -1
View File
@@ -232,12 +232,75 @@
color: var(--wfm-text);
}
/* =============================================
Properties Pane (left of Layers panel)
============================================= */
.ie-props-pane {
width: 160px;
flex-shrink: 0;
display: flex;
flex-direction: column;
border-left: 1px solid var(--wfm-border);
background: var(--wfm-surface);
overflow: hidden;
}
.ie-props-header {
display: flex;
align-items: center;
padding: 5px 8px;
border-bottom: 1px solid var(--wfm-border);
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.4px;
color: var(--wfm-text-secondary);
flex-shrink: 0;
}
.ie-props-body {
flex: 1;
overflow-y: auto;
padding: 8px 6px;
display: flex;
flex-direction: column;
gap: 10px;
}
.ie-props-row {
display: flex;
flex-direction: column;
gap: 4px;
font-size: 11px;
}
.ie-props-row label {
color: var(--wfm-text-secondary);
white-space: nowrap;
}
.ie-props-row input[type="range"] {
width: 100%;
}
.ie-props-row span {
font-size: 11px;
color: var(--wfm-text);
text-align: right;
}
/* Mask layer item highlight */
.ie-layer-item[data-type="mask"] .ie-layer-type-icon {
color: #e25252;
}
/* =============================================
Right Panel (Layers)
============================================= */
.ie-right-panel {
width: 190px;
width: 220px;
flex-shrink: 0;
display: flex;
flex-direction: column;
+6
View File
@@ -442,6 +442,8 @@ function applyI18nToHtml() {
"wfm-help-imageedit-28": "helpImageEdit28", "wfm-help-imageedit-29": "helpImageEdit29",
"wfm-help-imageedit-30": "helpImageEdit30",
"wfm-help-imageedit-7b": "helpImageEdit7b", "wfm-help-imageedit-7c": "helpImageEdit7c",
"wfm-help-imageedit-7d": "helpImageEdit7d",
"wfm-help-imageedit-8b": "helpImageEdit8b",
"wfm-help-imageedit-blur-title": "helpImageEditBlurTitle",
"wfm-help-imageedit-blur-1": "helpImageEditBlur1", "wfm-help-imageedit-blur-2": "helpImageEditBlur2",
"wfm-help-imageedit-blur-3": "helpImageEditBlur3", "wfm-help-imageedit-blur-4": "helpImageEditBlur4",
@@ -450,6 +452,10 @@ function applyI18nToHtml() {
"wfm-help-imageedit-bgremove-1": "helpImageEditBgRemove1", "wfm-help-imageedit-bgremove-2": "helpImageEditBgRemove2",
"wfm-help-imageedit-bgremove-3": "helpImageEditBgRemove3", "wfm-help-imageedit-bgremove-4": "helpImageEditBgRemove4",
"wfm-help-imageedit-bgremove-5": "helpImageEditBgRemove5",
"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-tabkbd-title": "helpImageEditTabKbdTitle",
"wfm-help-imageedit-tabkbd-1": "helpImageEdit22", "wfm-help-imageedit-tabkbd-2": "helpImageEdit23",
"wfm-help-imageedit-tabkbd-3": "helpImageEdit24", "wfm-help-imageedit-tabkbd-4": "helpImageEdit25",
+30 -5
View File
@@ -735,7 +735,7 @@ const LANGUAGES = {
helpAi5: "Settings pane: choose backend (Ollama / LM Studio), set API URL, test connection, select model, configure Free language names for translation",
helpAi6: "Settings are saved to localStorage and shared with the Library panel's A tab",
helpImageEditTitle: "Image Edit Tab",
helpImageEdit1: "Layer-based image editor — compose images with multiple layers (Image, Text, Draw types) and export the composite",
helpImageEdit1: "Layer-based image editor — compose images with multiple layers (Image, Text, Draw, Mask types) and export the composite",
helpImageEdit2: "Loading images: drag & drop onto the canvas, Upload button, or send from the Gallery tab via the Image Edit button in the Gallery toolbar; the first image becomes Layer 1 (auto-locked); subsequent images are added as new layers scaled to fit the canvas",
helpImageEdit3: "New button: create a blank canvas — prompts for WxH size (e.g. 512x768); clears all existing layers",
helpImageEditToolsTitle: "Tools",
@@ -772,6 +772,15 @@ const LANGUAGES = {
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",
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",
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",
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",
@@ -1671,7 +1680,7 @@ const LANGUAGES = {
helpAi5: "設定ペイン:バックエンド(Ollama / LM Studio)・API URL・接続テスト・モデル選択・Free 言語名を設定",
helpAi6: "設定は localStorage に保存され、Library パネルの A タブと共有される",
helpImageEditTitle: "Image Edit タブ",
helpImageEdit1: "レイヤーベースの画像エディタ — 複数のレイヤー(画像・テキスト・描画)を重ね合わせて画像を合成・エクスポート",
helpImageEdit1: "レイヤーベースの画像エディタ — 複数のレイヤー(画像・テキスト・描画・マスク)を重ね合わせて画像を合成・エクスポート",
helpImageEdit2: "画像の読み込み:キャンバスへのドラッグ&ドロップ、Uploadボタン、またはGalleryタブのImage Editボタンから送信;最初の画像はLayer 1として自動ロック;以降の画像はキャンバスサイズに合わせてスケールされ新規レイヤーとして追加",
helpImageEdit3: "Newボタン:空白キャンバスを作成 — W×Hサイズを入力(例: 512x768);既存レイヤーは全て削除",
helpImageEditToolsTitle: "ツール",
@@ -1684,7 +1693,7 @@ const LANGUAGES = {
helpImageEdit9: "👁 / 🚫 ボタン:レイヤーの表示/非表示を切り替え",
helpImageEdit10: "🔒 / 🔓 ボタン:レイヤーロックの切り替え — ロック中は移動・リサイズ・回転不可(オレンジのバウンディングボックスで表示);最初の画像読み込み時にLayer 1が自動ロックされ誤操作を防止",
helpImageEdit11: "下部の不透明度スライダーでアクティブレイヤーの透明度を調整",
helpImageEdit12: "タイプアイコン:🖼 = 画像レイヤー、T = テキストレイヤー、✏ = 描画レイヤー",
helpImageEdit12: "タイプアイコン:🖼 = 画像レイヤー、T = テキストレイヤー、✏ = 描画レイヤー、⬚ = マスクレイヤー",
helpImageEdit13: "Deleteキー:選択レイヤーを削除(2枚以上のレイヤーがある場合のみ)",
helpImageEditTextTitle: "テキストの品質",
helpImageEdit14: "テキストレイヤーはテキストのバウンディングボックスに合わせて正確なサイズに設定 — 余白なし",
@@ -1708,6 +1717,14 @@ const LANGUAGES = {
helpImageEdit30: "ダブルクリック(Selectツールでテキストレイヤー):テキストを再編集",
helpImageEdit7b: "Blur (≈):アクティブレイヤーにガウスぼかしまたはモザイクを適用 — 全体またはドラッグで矩形範囲指定;詳細は下の「Blur Tool」カードを参照",
helpImageEdit7c: "BG Remove (⬚):Lightweight(@imgly、ブラウザ内処理)またはBiRefNet(Pythonバックエンド、近日追加)でアクティブレイヤーの背景を除去;詳細は下の「BG Remove Tool」カードを参照",
helpImageEdit7d: "Mask (🎭):キャンバス上に白いマスクを描画;レイヤーヘッダーの「M」ボタンでマスクレイヤーを追加すると自動的にMaskツールに切り替わる;マスクはカラーの半透明オーバーレイとして表示;プロパティペイン(レイヤーパネル左隣)にPaintサブツールのコントロール;詳細は下の「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が青くハイライト",
helpImageEditMask5: "マスクレイヤー行の ✂ ボタン:クリッピングマスクとして機能させるon/off切り替え — 有効(青)のとき、直下のレイヤーをマスクの描画範囲でクリッピングして表示;クリッピングはPNG保存 / Gallery / ComfyUI送信にも反映される",
helpImageEditBlurTitle: "Blur ツール (≈)",
helpImageEditBlur1: "Whole Blur:アクティブレイヤー全体にガウスぼかしを適用 — 強度スライダー(1〜50 px)で調整してApplyをクリック",
helpImageEditBlur2: "Whole Mosaic:アクティブレイヤー全体にピクセル化モザイクを適用 — ブロックサイズスライダー(5〜100 px)で調整してApplyをクリック",
@@ -2607,7 +2624,7 @@ const LANGUAGES = {
helpAi5: "设置面板:选择后端(Ollama / LM Studio)、设置 API URL、测试连接、选择模型、配置 Free 语言名称",
helpAi6: "设置保存至 localStorage,并与 Library 面板的 A 标签共享",
helpImageEditTitle: "图像编辑选项卡",
helpImageEdit1: "基于图层的图像编辑器 — 通过多个图层(图像、文字、绘制类型)合成图像并导出",
helpImageEdit1: "基于图层的图像编辑器 — 通过多个图层(图像、文字、绘制、遮罩类型)合成图像并导出",
helpImageEdit2: "加载图像:拖放到画布、点击Upload按钮、或通过Gallery标签工具栏的Image Edit按钮发送;第一张图像成为图层1(自动锁定);后续图像缩放至画布大小作为新图层添加",
helpImageEdit3: "New按钮:创建空白画布 — 输入宽高(如512x768);清除所有现有图层",
helpImageEditToolsTitle: "工具",
@@ -2620,7 +2637,7 @@ const LANGUAGES = {
helpImageEdit9: "👁 / 🚫 按钮:切换图层可见性",
helpImageEdit10: "🔒 / 🔓 按钮:切换图层锁定 — 锁定图层无法移动、缩放或旋转(显示橙色边框);加载第一张图像时图层1自动锁定以防止误操作",
helpImageEdit11: "底部的不透明度滑块调整当前图层的透明度",
helpImageEdit12: "类型图标:🖼 = 图像图层,T = 文字图层,✏ = 绘制图层",
helpImageEdit12: "类型图标:🖼 = 图像图层,T = 文字图层,✏ = 绘制图层,⬚ = 遮罩图层",
helpImageEdit13: "Delete键:删除选中图层(需要2个及以上图层)",
helpImageEditTextTitle: "文字质量",
helpImageEdit14: "文字图层按测量的文字边界框精确调整大小 — 无多余空白",
@@ -2644,6 +2661,14 @@ const LANGUAGES = {
helpImageEdit30: "双击(Select工具点击文字图层):重新编辑文字",
helpImageEdit7b: "Blur (≈):对活动图层应用高斯模糊或马赛克 — 整层或拖动矩形区域;详细内容参见下方「Blur Tool」卡片",
helpImageEdit7c: "BG Remove (⬚):使用Lightweight(@imgly,在浏览器中运行)或BiRefNet(Python后端,即将推出)去除活动图层背景;详细内容参见下方「BG Remove Tool」卡片",
helpImageEdit7d: "Mask (🎭):在画布上绘制白色遮罩;点击图层标题栏的「M」按钮添加遮罩图层,自动切换至Mask工具;遮罩以彩色半透明叠加方式显示;属性面板(图层面板左侧)显示Paint子工具控件;详细内容参见下方「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按钮(擦除至透明/遮罩缺失);当前激活模式以蓝色高亮显示",
helpImageEditMask5: "遮罩图层行的 ✂ 按钮:切换是否作为剪贴蒙版使用 — 启用(蓝色)时,遮罩将裁剪其正下方图层,仅显示已绘制区域;剪贴效果在保存PNG / Gallery / 发送至ComfyUI时均会生效",
helpImageEditBlurTitle: "Blur 工具 (≈)",
helpImageEditBlur1: "Whole Blur:对整个活动图层应用高斯模糊 — 调整强度滑块(1–50 px),点击Apply",
helpImageEditBlur2: "Whole Mosaic:对整个活动图层应用像素化马赛克 — 调整块大小滑块(5–100 px),点击Apply",
+323 -20
View File
@@ -9,6 +9,7 @@ import { DrawTool } from "./image-edit/DrawTool.js";
import { TextTool, TEXT_FONTS } from "./image-edit/TextTool.js";
import { SelectTool } from "./image-edit/SelectTool.js";
import { ShapeTool } from "./image-edit/ShapeTool.js";
import { MaskTool } from "./image-edit/MaskTool.js";
import { showToast } from "./app.js";
const TOOL_DEFS = [
@@ -16,7 +17,7 @@ const TOOL_DEFS = [
{ id: "draw", icon: "✏", label: "Draw", ready: true },
{ id: "text", icon: "T", label: "Text", ready: true },
{ id: "shape", icon: "□", label: "Shape", ready: true },
{ id: "mask", icon: "🎭", label: "Mask", ready: false },
{ id: "mask", icon: "🎭", label: "Mask", ready: true },
{ id: "blur", icon: "≈", label: "Blur", ready: true },
{ id: "filter", icon: "★", label: "Filter", ready: false },
{ id: "bgremove", icon: "⬚", label: "BG Remove", ready: true },
@@ -74,6 +75,12 @@ class ImageEditTab {
this._blurDragging = false;
this._blurDragStart = null;
this._blurDragCur = null;
// Mask ツール
this._maskTool = null;
this._maskSubtool = "paint";
this._maskInverted = false;
this._maskOverlayColor = "#ff0000";
this._maskBlur = 0;
}
// ── 初期化 ────────────────────────────────────
@@ -105,6 +112,7 @@ class ImageEditTab {
if (this._activeTool === "text") this._textTool?.deactivate();
if (this._activeTool === "select") this._selectTool?.deactivate();
if (this._activeTool === "shape") this._shapeTool?.deactivate();
if (this._activeTool === "mask") this._maskTool?.deactivate();
if (this._activeTool === "blur") {
this._blurRectMode = null;
this._blurDragging = false;
@@ -114,6 +122,11 @@ class ImageEditTab {
overlay.getContext("2d").clearRect(0, 0, overlay.width, overlay.height);
}
}
// マスク以外に切り替えたらプロパティペインを非表示
if (toolId !== "mask") {
const pane = document.getElementById("ie-props-pane");
if (pane) pane.style.display = "none";
}
this._activeTool = toolId;
@@ -130,7 +143,8 @@ class ImageEditTab {
if (!drawCanvas || !this._layerMgr) return;
if (this._activeTool === "draw" && this._drawTool) {
this._drawTool.setCanvas(drawCanvas);
const activeLayer = this._layerMgr?.activeLayer;
if (activeLayer) this._drawTool.setCanvas(activeLayer.canvas);
this._drawTool.activate();
} else if (this._activeTool === "text" && this._textTool) {
this._textTool.setCanvas(drawCanvas);
@@ -142,6 +156,12 @@ class ImageEditTab {
this._shapeTool.setCanvas(overlayCanvas);
this._shapeTool.activate();
if (overlayCanvas) overlayCanvas.style.cursor = "crosshair";
} else if (this._activeTool === "mask" && this._maskTool) {
const activeLayer = this._layerMgr?.activeLayer;
if (activeLayer?.type === "mask") {
this._maskTool.setCanvas(activeLayer.canvas);
}
this._maskTool.activate();
} else if (this._activeTool === "blur") {
if (overlayCanvas) overlayCanvas.style.cursor = this._blurRectMode ? "crosshair" : "default";
}
@@ -385,6 +405,48 @@ class ImageEditTab {
});
document.getElementById("ie-shape-undo-btn")?.addEventListener("click", () => this._undo());
} else if (toolId === "mask") {
const sub = this._maskSubtool ?? "paint";
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>
</div>
<div style="width:1px;height:22px;background:var(--wfm-border);margin:0 4px;flex-shrink:0;"></div>
<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
</label>
</div>
<div class="ie-opt-group">
<label style="font-size:11px;color:var(--wfm-text-secondary);">Overlay</label>
<input type="color" id="ie-mask-overlay-color" value="${this._maskOverlayColor}"
style="width:28px;height:22px;padding:0;border:1px solid var(--wfm-border);cursor:pointer;border-radius:3px;">
</div>
<div class="ie-opt-group">
<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>
`;
document.getElementById("ie-mask-paint-btn")?.addEventListener("click", () => {
this._maskSubtool = "paint";
this._renderToolOptions("mask");
});
document.getElementById("ie-mask-invert")?.addEventListener("change", e => {
this._maskInverted = e.target.checked;
this._updateCompositeView();
});
document.getElementById("ie-mask-overlay-color")?.addEventListener("input", e => {
this._maskOverlayColor = e.target.value;
this._updateCompositeView();
});
document.getElementById("ie-mask-blur")?.addEventListener("input", e => {
this._maskBlur = parseInt(e.target.value);
document.getElementById("ie-mask-blur-val").textContent = e.target.value;
this._updateCompositeView();
});
this._renderMaskProps(sub);
} else if (toolId === "blur") {
const blurOn = this._blurRectMode === "blur";
const mosaicOn = this._blurRectMode === "mosaic";
@@ -483,6 +545,88 @@ class ImageEditTab {
}
}
_renderMaskProps(sub) {
const pane = document.getElementById("ie-props-pane");
const body = document.getElementById("ie-props-body");
const title = document.getElementById("ie-props-title");
if (!pane || !body) return;
pane.style.display = "flex";
if (title) title.textContent = sub.charAt(0).toUpperCase() + sub.slice(1);
if (sub === "paint" && this._maskTool) {
const t = this._maskTool;
body.innerHTML = `
<div class="ie-props-row">
<label>Mode</label>
<div style="display:flex;gap:4px;">
<button class="wfm-btn wfm-btn-sm${t.mode === "paint" ? " ie-opt-active" : ""}" id="ie-mask-mode-add" style="flex:1;">Add</button>
<button class="wfm-btn wfm-btn-sm${t.mode === "erase" ? " ie-opt-active" : ""}" id="ie-mask-mode-erase" style="flex:1;">Erase</button>
</div>
</div>
<div class="ie-props-row">
<label>Size</label>
<input type="range" id="ie-mask-size" min="1" max="200" value="${t.brushSize}">
<span id="ie-mask-size-lbl">${t.brushSize}px</span>
</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)}">
<span id="ie-mask-hard-lbl">${Math.round(t.hardness * 100)}%</span>
</div>
`;
document.getElementById("ie-mask-mode-add")?.addEventListener("click", () => {
this._maskTool.mode = "paint";
this._maskTool._stamp = null;
this._renderMaskProps("paint");
});
document.getElementById("ie-mask-mode-erase")?.addEventListener("click", () => {
this._maskTool.mode = "erase";
this._maskTool._stamp = null;
this._renderMaskProps("paint");
});
document.getElementById("ie-mask-size")?.addEventListener("input", e => {
this._maskTool.brushSize = parseInt(e.target.value);
document.getElementById("ie-mask-size-lbl").textContent = e.target.value + "px";
this._maskTool._stamp = null;
});
document.getElementById("ie-mask-hard")?.addEventListener("input", e => {
this._maskTool.hardness = parseInt(e.target.value) / 100;
document.getElementById("ie-mask-hard-lbl").textContent = e.target.value + "%";
this._maskTool._stamp = null;
});
} else {
body.innerHTML = `<span style="font-size:11px;color:var(--wfm-text-secondary);">No options</span>`;
}
}
_renderMaskLayerOverlay(ctx, maskLayer) {
const overlayColor = this._maskOverlayColor;
const blurPx = this._maskBlur;
const inverted = this._maskInverted;
const mw = maskLayer.canvas.width;
const mh = maskLayer.canvas.height;
const tmp = document.createElement("canvas");
tmp.width = mw;
tmp.height = mh;
const tc = tmp.getContext("2d");
tc.fillStyle = overlayColor;
tc.fillRect(0, 0, mw, mh);
tc.globalCompositeOperation = inverted ? "destination-out" : "destination-in";
tc.drawImage(maskLayer.canvas, 0, 0);
tc.globalCompositeOperation = "source-over";
ctx.save();
ctx.globalAlpha = 0.55 * maskLayer.opacity;
if (blurPx > 0) ctx.filter = `blur(${blurPx}px)`;
Layer.applyTransform(ctx, maskLayer);
ctx.drawImage(tmp, -mw / 2, -mh / 2);
ctx.restore();
if (blurPx > 0) ctx.filter = "none";
}
// ── アクションバー ─────────────────────────────
_setupActionBar() {
@@ -572,9 +716,23 @@ class ImageEditTab {
const pos = DrawTool.getCanvasPos(refCanvas, e);
if (this._activeTool === "draw" && this._drawTool) {
const activeLayer = this._layerMgr.activeLayer;
if (!activeLayer) return;
this._saveUndo();
this._loadActiveLayerToCanvas();
this._drawTool.setCanvas(activeLayer.canvas);
this._drawTool.onMouseDown(pos.x, pos.y);
this._updateCompositeView();
} else if (this._activeTool === "mask" && this._maskTool) {
const activeLayer = this._layerMgr.activeLayer;
if (!activeLayer || activeLayer.type !== "mask") {
showToast("Select a mask layer first", "info");
return;
}
this._saveUndo();
this._maskTool.setCanvas(activeLayer.canvas);
this._maskTool.onMouseDown(pos.x, pos.y);
this._updateCompositeView();
} else if (this._activeTool === "shape" && this._shapeTool) {
this._shapeTool.onMouseDown(pos.x, pos.y);
@@ -602,7 +760,14 @@ class ImageEditTab {
_onToolMouseMove(e, refCanvas) {
if (!this._layerMgr) return;
const pos = DrawTool.getCanvasPos(refCanvas, e);
if (this._activeTool === "draw") this._drawTool?.onMouseMove(pos.x, pos.y);
if (this._activeTool === "draw") {
this._drawTool?.onMouseMove(pos.x, pos.y);
if (this._drawTool?._drawing) this._updateCompositeView();
}
if (this._activeTool === "mask") {
this._maskTool?.onMouseMove(pos.x, pos.y);
if (this._maskTool?._drawing) this._updateCompositeView();
}
if (this._activeTool === "shape") this._shapeTool?.onMouseMove(pos.x, pos.y);
if (this._activeTool === "select") this._selectTool?.onMouseMove(pos.x, pos.y);
if (this._activeTool === "blur" && this._blurDragging) {
@@ -614,6 +779,7 @@ class ImageEditTab {
_onToolMouseUp(e) {
if (!this._layerMgr || e.button !== 0) return;
if (this._activeTool === "draw") this._drawTool?.onMouseUp();
if (this._activeTool === "mask") this._maskTool?.onMouseUp();
if (this._activeTool === "shape") this._shapeTool?.onMouseUp();
if (this._activeTool === "select") this._selectTool?.onMouseUp();
if (this._activeTool === "blur" && this._blurDragging) {
@@ -626,6 +792,7 @@ class ImageEditTab {
_onToolMouseLeave() {
if (this._activeTool === "draw") this._drawTool?.onMouseLeave();
if (this._activeTool === "mask") this._maskTool?.onMouseLeave();
if (this._activeTool === "shape") this._shapeTool?.onMouseLeave();
if (this._activeTool === "select") this._selectTool?.onMouseLeave();
if (this._activeTool === "blur" && this._blurDragging) {
@@ -746,9 +913,9 @@ class ImageEditTab {
this._layerMgr = new LayerManager(this._canvasW, this._canvasH);
this._layerMgr.on("change", () => this._refreshLayerList());
this._drawTool = new DrawTool(drawCanvas);
this._drawTool = new DrawTool(null);
this._drawTool.onChange(() => {
this._syncActiveLayerFromCanvas();
// layer.canvas に直接描くため sync 不要
this._updateCompositeView();
this._refreshLayerList();
});
@@ -835,6 +1002,13 @@ class ImageEditTab {
this._updateCompositeView();
});
this._maskTool = new MaskTool(null);
this._maskTool.onChange(() => {
// layer.canvas に直接描くため sync 不要
this._updateCompositeView();
this._refreshLayerList();
});
this._compositeMode = false;
}
@@ -876,19 +1050,74 @@ class ImageEditTab {
if (!drawCanvas || !this._layerMgr) return;
const ctx = drawCanvas.getContext("2d");
ctx.clearRect(0, 0, drawCanvas.width, drawCanvas.height);
for (let i = this._layerMgr.layers.length - 1; i >= 0; i--) {
const layer = this._layerMgr.layers[i];
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); // 直下のレイヤーを先にスキップ
}
}
for (let i = layers.length - 1; i >= 0; i--) {
const layer = layers[i];
if (!layer.visible) continue;
ctx.save();
ctx.globalAlpha = layer.opacity;
ctx.globalCompositeOperation = layer.blendMode;
Layer.applyTransform(ctx, layer);
ctx.drawImage(layer.canvas, -layer.canvas.width / 2, -layer.canvas.height / 2);
ctx.restore();
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);
}
} else {
ctx.save();
ctx.globalAlpha = layer.opacity;
ctx.globalCompositeOperation = layer.blendMode;
Layer.applyTransform(ctx, layer);
ctx.drawImage(layer.canvas, -layer.canvas.width / 2, -layer.canvas.height / 2);
ctx.restore();
}
}
this._compositeMode = true;
}
_renderMaskedLayer(ctx, drawCanvas, maskLayer, targetLayer, showOverlay = true) {
const W = drawCanvas.width;
const H = drawCanvas.height;
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.save();
tc.globalCompositeOperation = this._maskInverted ? "destination-out" : "destination-in";
Layer.applyTransform(tc, maskLayer);
tc.drawImage(maskLayer.canvas, -maskLayer.canvas.width / 2, -maskLayer.canvas.height / 2);
tc.restore();
ctx.save();
ctx.drawImage(tmp, 0, 0);
ctx.restore();
if (showOverlay) {
this._renderMaskLayerOverlay(ctx, maskLayer);
}
}
// ── ズーム・パン ──────────────────────────────
_fitToView() {
@@ -931,6 +1160,25 @@ class ImageEditTab {
this._activateCurrentTool();
});
document.getElementById("ie-add-mask-btn")?.addEventListener("click", () => {
if (!this._layerMgr) { showToast("Open an image first", "info"); return; }
this._syncActiveLayerFromCanvas();
this._saveUndo();
const maskCount = this._layerMgr.layers.filter(l => l.type === "mask").length + 1;
const layer = this._layerMgr.addLayer("mask", `Mask ${maskCount}`);
layer.displayW = this._canvasW;
layer.displayH = this._canvasH;
layer.x = 0;
layer.y = 0;
this._layerMgr.setActive(layer.id);
this._setActiveTool("mask");
this._loadActiveLayerToCanvas();
this._updateCompositeView();
this._refreshLayerList();
document.getElementById("ie-placeholder").style.display = "none";
showToast("Mask layer added", "success");
});
document.getElementById("ie-del-layer-btn")?.addEventListener("click", () => {
if (!this._layerMgr || this._layerMgr.layers.length <= 1) return;
this._saveUndo();
@@ -971,14 +1219,23 @@ class ImageEditTab {
el.innerHTML = this._layerMgr.layers.map((layer, i) => {
const isActive = i === this._layerMgr.activeIndex;
const typeIcon = layer.type === "image" ? "🖼" : layer.type === "text" ? "T" : "✏";
const typeIcon = layer.type === "image" ? "🖼"
: layer.type === "text" ? "T"
: layer.type === "mask" ? "⬚"
: "✏";
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>`
: "";
return `
<div class="ie-layer-item ${isActive ? "active" : ""}" data-id="${layer.id}" data-action="select">
<div class="ie-layer-item ${isActive ? "active" : ""}" data-id="${layer.id}" data-action="select" data-type="${layer.type}">
<button class="ie-layer-vis-btn" data-id="${layer.id}" data-action="vis"
title="${layer.visible ? "Hide" : "Show"}">${layer.visible ? "👁" : "🚫"}</button>
<button class="ie-layer-vis-btn" data-id="${layer.id}" data-action="lock"
title="${layer.locked ? "Unlock" : "Lock"}"
style="color:${layer.locked ? "#e2a04a" : "inherit"}">${layer.locked ? "🔒" : "🔓"}</button>
${maskApplyBtn}
<img class="ie-layer-thumb" src="${layer.getThumbnailDataURL()}" draggable="false">
<span class="ie-layer-type-icon" style="font-size:10px;opacity:0.7;flex-shrink:0;">${typeIcon}</span>
<span class="ie-layer-name">${layer.name}</span>
@@ -994,6 +1251,10 @@ class ImageEditTab {
if (action === "vis") {
this._layerMgr.toggleVisible(id);
this._updateCompositeView();
} else if (action === "mask-apply") {
this._layerMgr.toggleMaskApply(id);
this._updateCompositeView();
this._refreshLayerList();
} else if (action === "lock") {
this._layerMgr.toggleLocked(id);
// ロック変更はSelectToolのオーバーレイを再描画
@@ -1004,10 +1265,21 @@ class ImageEditTab {
this._syncActiveLayerFromCanvas();
this._layerMgr.setActive(id);
const layer = this._layerMgr.activeLayer;
if (this._activeTool === "select" && layer) {
if (layer?.type === "mask") {
if (this._activeTool !== "mask") {
this._setActiveTool("mask");
} else {
// すでにマスクツール選択中 → canvas だけ切り替え
this._maskTool?.setCanvas(layer.canvas);
this._maskTool?.activate();
}
this._updateCompositeView();
} else if (this._activeTool === "draw" && layer) {
this._drawTool?.setCanvas(layer.canvas);
this._updateCompositeView();
} else if (this._activeTool === "select" && layer) {
this._selectTool?.setLayer(layer);
} else {
this._loadActiveLayerToCanvas();
this._updateCompositeView();
}
this._refreshLayerList();
@@ -1062,11 +1334,42 @@ class ImageEditTab {
const canvas = document.createElement("canvas");
canvas.width = this._canvasW;
canvas.height = this._canvasH;
this._syncActiveLayerFromCanvas();
if (this._layerMgr) this._layerMgr.composite(canvas);
if (!this._layerMgr) return canvas;
this._compositeForExport(canvas);
return canvas;
}
// 保存用合成: maskApply=true のクリッピングを適用、マスクオーバーレイは除外
_compositeForExport(target) {
const ctx = target.getContext("2d");
ctx.clearRect(0, 0, target.width, target.height);
const layers = this._layerMgr.layers;
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);
}
}
for (let i = layers.length - 1; i >= 0; i--) {
const layer = layers[i];
if (!layer.visible) continue;
if (maskedIndices.has(i)) continue;
if (layer.type === "mask") {
if (layer.maskApply && i + 1 < layers.length) {
this._renderMaskedLayer(ctx, target, layer, layers[i + 1], false);
}
// maskApply=false のマスクはエクスポートに含めない
} else {
ctx.save();
ctx.globalAlpha = layer.opacity;
ctx.globalCompositeOperation = layer.blendMode;
Layer.applyTransform(ctx, layer);
ctx.drawImage(layer.canvas, -layer.canvas.width / 2, -layer.canvas.height / 2);
ctx.restore();
}
}
}
_savePng() {
if (!this._layerMgr) { showToast("No image loaded", "error"); return; }
const canvas = this._buildCompositeCanvas();
+3 -3
View File
@@ -7,7 +7,7 @@
export class DrawTool {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.ctx = canvas?.getContext("2d") ?? null;
this.brushSize = 20;
this.hardness = 0.8; // 0.0 = very soft, 1.0 = hard edge
this.opacity = 1.0;
@@ -36,12 +36,12 @@ export class DrawTool {
onChange(fn) { this._onChange = fn; }
activate() {
this.canvas.style.cursor = "crosshair";
if (this.canvas) this.canvas.style.cursor = "crosshair";
}
deactivate() {
this._drawing = false;
this.canvas.style.cursor = "";
if (this.canvas) this.canvas.style.cursor = "";
}
onMouseDown(x, y) {
+14 -6
View File
@@ -25,8 +25,9 @@ export class Layer {
this.rotation = 0; // 度
this.flipX = false;
this.flipY = false;
this.textProps = null; // テキストレイヤー用プロパティ(再編集・再描画に使用)
this.locked = false; // ロック中は SelectTool の変形を禁止
this.textProps = null; // テキストレイヤー用プロパティ(再編集・再描画に使用)
this.locked = false; // ロック中は SelectTool の変形を禁止
this.maskApply = false; // マスクレイヤー: true=クリッピングマスクとして機能
}
clear() {
@@ -55,8 +56,9 @@ export class Layer {
visible: this.visible, opacity: this.opacity, blendMode: this.blendMode,
x: this.x, y: this.y, displayW: this.displayW, displayH: this.displayH,
rotation: this.rotation, flipX: this.flipX, flipY: this.flipY,
textProps: this.textProps ?? null,
locked: this.locked ?? false,
textProps: this.textProps ?? null,
locked: this.locked ?? false,
maskApply: this.maskApply ?? false,
};
}
@@ -75,8 +77,9 @@ export class Layer {
layer.rotation = json.rotation ?? 0;
layer.flipX = json.flipX ?? false;
layer.flipY = json.flipY ?? false;
layer.textProps = json.textProps ?? null;
layer.locked = json.locked ?? false;
layer.textProps = json.textProps ?? null;
layer.locked = json.locked ?? false;
layer.maskApply = json.maskApply ?? false;
if (json.imageData) {
return new Promise(resolve => {
@@ -174,6 +177,11 @@ export class LayerManager {
if (layer) { layer.locked = !layer.locked; this._emit("change"); }
}
toggleMaskApply(id) {
const layer = this.layers.find(l => l.id === id);
if (layer && layer.type === "mask") { layer.maskApply = !layer.maskApply; 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"); }
+124
View File
@@ -0,0 +1,124 @@
/**
* Image Edit Tab - Mask Tool
* White-paint / erase brush for mask layers.
* paint mode: draws white (opaque) = mask present
* erase mode: destination-out (transparent) = mask absent
*/
export class MaskTool {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas?.getContext("2d");
this.brushSize = 30;
this.hardness = 0.85;
this.mode = "paint"; // "paint" | "erase"
this._drawing = false;
this._lastX = 0;
this._lastY = 0;
this._stamp = null;
this._stampSize = 0;
this._stampHard = 0;
this._stampMode = null;
this._onChange = null;
}
setCanvas(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this._stamp = null;
}
onChange(fn) { this._onChange = fn; }
activate() {
if (this.canvas) this.canvas.style.cursor = "crosshair";
}
deactivate() {
this._drawing = false;
if (this.canvas) this.canvas.style.cursor = "";
}
onMouseDown(x, y) {
this._drawing = true;
this._lastX = x;
this._lastY = y;
this._paint(x, y);
}
onMouseMove(x, y) {
if (!this._drawing) return;
this._paintLine(this._lastX, this._lastY, x, y);
this._lastX = x;
this._lastY = y;
}
onMouseUp() {
if (this._drawing) {
this._drawing = false;
if (this._onChange) this._onChange();
}
}
onMouseLeave() {
if (this._drawing) this.onMouseUp();
}
_getStamp() {
if (
this._stamp &&
this._stampSize === this.brushSize &&
this._stampHard === this.hardness &&
this._stampMode === this.mode
) return this._stamp;
const size = Math.max(1, Math.round(this.brushSize));
const sc = document.createElement("canvas");
sc.width = size;
sc.height = size;
const sctx = sc.getContext("2d");
const cx = size / 2, cy = size / 2, r = size / 2;
const color = this.mode === "paint" ? "#ffffff" : "#000000";
const colorAlpha = this.mode === "paint" ? "rgba(255,255,255,0)" : "rgba(0,0,0,0)";
const innerR = r * (1 - Math.min(this.hardness, 0.99)) * 0.95;
const grd = sctx.createRadialGradient(cx, cy, innerR, cx, cy, r);
grd.addColorStop(0, color);
grd.addColorStop(1, colorAlpha);
sctx.fillStyle = grd;
sctx.beginPath();
sctx.arc(cx, cy, r, 0, Math.PI * 2);
sctx.fill();
this._stamp = sc;
this._stampSize = size;
this._stampHard = this.hardness;
this._stampMode = this.mode;
return sc;
}
_paint(x, y) {
const stamp = this._getStamp();
const s = stamp.width;
this.ctx.save();
if (this.mode === "erase") {
this.ctx.globalCompositeOperation = "destination-out";
}
this.ctx.drawImage(stamp, x - s / 2, y - s / 2);
this.ctx.restore();
}
_paintLine(x0, y0, x1, y1) {
const dist = Math.hypot(x1 - x0, y1 - y0);
const spacing = Math.max(1, this.brushSize * 0.2);
const steps = Math.max(1, Math.ceil(dist / spacing));
for (let i = 1; i <= steps; i++) {
const t = i / steps;
this._paint(x0 + (x1 - x0) * t, y0 + (y1 - y0) * t);
}
}
}
+24 -3
View File
@@ -1280,7 +1280,7 @@
<div class="wfm-help-card">
<h3 id="wfm-help-imageedit-title">Image Edit Tab</h3>
<ul>
<li id="wfm-help-imageedit-1">Layer-based image editor — compose images with multiple layers (Image, Text, Draw types) and export the composite</li>
<li id="wfm-help-imageedit-1">Layer-based image editor — compose images with multiple layers (Image, Text, Draw, Mask types) and export the composite</li>
<li id="wfm-help-imageedit-2">Loading images: drag &amp; drop onto the canvas, Upload button, or send from the Gallery tab via the Image Edit button in the Gallery toolbar; the first image becomes Layer 1 (auto-locked); subsequent images are added as new layers scaled to fit the canvas</li>
<li id="wfm-help-imageedit-3">New button: create a blank canvas — prompts for WxH size (e.g. 512x768); clears all existing layers</li>
</ul>
@@ -1294,16 +1294,18 @@
<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>
</ul>
</div>
<div class="wfm-help-card">
<h3 id="wfm-help-imageedit-layer-title">Layer Panel</h3>
<ul>
<li id="wfm-help-imageedit-8">Layers are listed from front (top) to back (bottom); click a layer row to make it active</li>
<li id="wfm-help-imageedit-8b">"M" button in the Layers header: adds a new mask layer above the current layer and automatically switches to the Mask tool</li>
<li id="wfm-help-imageedit-9">👁 / 🚫 button: toggle layer visibility</li>
<li id="wfm-help-imageedit-10">🔒 / 🔓 button: toggle layer lock — a locked layer cannot be moved, resized, or rotated (orange bounding box is shown); Layer 1 is locked automatically when the first image is loaded to prevent accidental moves</li>
<li id="wfm-help-imageedit-11">Opacity slider at the bottom adjusts the active layer's transparency</li>
<li id="wfm-help-imageedit-12">Type icons: 🖼 = image layer, T = text layer, ✏ = draw layer</li>
<li id="wfm-help-imageedit-12">Type icons: 🖼 = image layer, T = text layer, ✏ = draw layer, ⬚ = mask layer</li>
<li id="wfm-help-imageedit-13">Delete key: removes the selected layer (only when 2+ layers exist)</li>
</ul>
</div>
@@ -1328,6 +1330,16 @@
<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>
</ul>
</div>
<div class="wfm-help-card">
<h3 id="wfm-help-imageedit-mask-title">Mask Tool (🎭)</h3>
<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-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>
</ul>
</div>
<div class="wfm-help-card">
<h3 id="wfm-help-imageedit-text-title">Text Object Quality</h3>
<ul>
@@ -1577,7 +1589,7 @@
<button class="ie-tool-btn" data-tool="draw" title="Draw (B)">✏</button>
<button class="ie-tool-btn" data-tool="text" title="Text (T)">T</button>
<button class="ie-tool-btn" data-tool="shape" title="Shape (S)">□</button>
<button class="ie-tool-btn ie-tool-placeholder" data-tool="mask" title="Mask">🎭</button>
<button class="ie-tool-btn" data-tool="mask" title="Mask">🎭</button>
<button class="ie-tool-btn" data-tool="blur" title="Blur">≈</button>
<button class="ie-tool-btn ie-tool-placeholder" data-tool="filter" title="Filter">★</button>
<button class="ie-tool-btn" data-tool="bgremove" title="BG Remove">⬚</button>
@@ -1626,11 +1638,20 @@
</div>
</div>
<!-- Properties Pane (mask tool etc.) -->
<div class="ie-props-pane" id="ie-props-pane" style="display:none;">
<div class="ie-props-header">
<span id="ie-props-title">Properties</span>
</div>
<div class="ie-props-body" id="ie-props-body"></div>
</div>
<!-- Right Panel (Layers) -->
<div class="ie-right-panel">
<div class="ie-layers-header">
<span>Layers</span>
<button class="wfm-btn wfm-btn-sm" id="ie-add-layer-btn" title="Add layer">+</button>
<button class="wfm-btn wfm-btn-sm" id="ie-add-mask-btn" title="Add mask layer" style="font-weight:700;color:var(--wfm-accent,#4682e6);">M</button>
<button class="wfm-btn wfm-btn-sm" id="ie-del-layer-btn" title="Delete layer">−</button>
<button class="wfm-btn wfm-btn-sm" id="ie-layer-up-btn" title="Move up">↑</button>
<button class="wfm-btn wfm-btn-sm" id="ie-layer-down-btn" title="Move down">↓</button>