@pixerate/editor 0.206.0 → 0.207.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/image-editor/index.cjs +487 -84
- package/dist/image-editor/index.js +409 -6
- package/dist/image-editor/selection/index.d.cts +1 -0
- package/dist/image-editor/selection/index.d.ts +1 -0
- package/dist/image-editor/selection/refine-edits.d.cts +13 -4
- package/dist/image-editor/selection/refine-edits.d.ts +13 -4
- package/dist/image-editor/selection/select-and-mask.d.cts +126 -0
- package/dist/image-editor/selection/select-and-mask.d.ts +126 -0
- package/package.json +1 -1
- package/skills/pixerate-image-editor/SKILL.md +1 -1
- package/skills/pixerate-image-selection-masking/SKILL.md +4 -2
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Select and Mask workspace without a UI: its settings, strokes, preview and view modes, shared
|
|
3
|
+
* by the React and Svelte workspaces. Everything it holds is plain data (the strokes are
|
|
4
|
+
* `RefineEdit`s), and OK runs the same `refineSelectionTo` call an agent makes with `edits`, so
|
|
5
|
+
* the workspace and an agent produce the same result in one undo step.
|
|
6
|
+
*
|
|
7
|
+
* The preview is computed on a copy reduced to {@link PREVIEW_SIZE} px (or at full size with High
|
|
8
|
+
* Quality Preview) and drawn as RGBA in the chosen view mode.
|
|
9
|
+
*/
|
|
10
|
+
import type { ImageEditorController, RefineOutput, RefineOutputResult } from '../controller.cjs';
|
|
11
|
+
import type { ImagePoint } from '../types.cjs';
|
|
12
|
+
import { type RefineEdgeParams } from './refine.cjs';
|
|
13
|
+
import { type RefineEdit } from './refine-edits.cjs';
|
|
14
|
+
export type SelectAndMaskView = 'onion-skin' | 'marching-ants' | 'overlay' | 'on-black' | 'on-white' | 'black-white' | 'on-layers';
|
|
15
|
+
export type SelectAndMaskTool = 'quick-select' | 'refine-brush' | 'brush' | 'object' | 'lasso' | 'hand' | 'zoom';
|
|
16
|
+
/** The view modes with Photoshop's keys, in menu order. */
|
|
17
|
+
export declare const SELECT_AND_MASK_VIEWS: readonly {
|
|
18
|
+
id: SelectAndMaskView;
|
|
19
|
+
label: string;
|
|
20
|
+
key: string;
|
|
21
|
+
opacity: number;
|
|
22
|
+
}[];
|
|
23
|
+
/** The workspace tools with Photoshop's keys. */
|
|
24
|
+
export declare const SELECT_AND_MASK_TOOLS: readonly {
|
|
25
|
+
id: SelectAndMaskTool;
|
|
26
|
+
label: string;
|
|
27
|
+
key: string;
|
|
28
|
+
}[];
|
|
29
|
+
export interface SelectAndMaskSettings {
|
|
30
|
+
params: Required<RefineEdgeParams>;
|
|
31
|
+
output: RefineOutput;
|
|
32
|
+
/** Decontaminate Colors amount 0..100 (new-layer outputs). */
|
|
33
|
+
decontaminate: number;
|
|
34
|
+
refineMode: 'color' | 'object';
|
|
35
|
+
view: SelectAndMaskView;
|
|
36
|
+
/** How strongly the view shows what is not selected, 0..1. */
|
|
37
|
+
opacity: number;
|
|
38
|
+
/** Show only the area the refinement changes. */
|
|
39
|
+
showEdge: boolean;
|
|
40
|
+
/** Show the selection as it was, before the workspace. */
|
|
41
|
+
showOriginal: boolean;
|
|
42
|
+
/** Update the preview while painting (otherwise on release). */
|
|
43
|
+
realTime: boolean;
|
|
44
|
+
/** Preview at full size instead of a reduced copy. */
|
|
45
|
+
highQuality: boolean;
|
|
46
|
+
/** Keep these settings for the next time the workspace opens. */
|
|
47
|
+
remember: boolean;
|
|
48
|
+
tool: SelectAndMaskTool;
|
|
49
|
+
/** Brush diameter in natural pixels. */
|
|
50
|
+
brushSize: number;
|
|
51
|
+
brushMode: 'add' | 'subtract';
|
|
52
|
+
}
|
|
53
|
+
export declare const DEFAULT_SELECT_AND_MASK_SETTINGS: SelectAndMaskSettings;
|
|
54
|
+
/** Long side of the reduced preview. */
|
|
55
|
+
export declare const PREVIEW_SIZE = 1024;
|
|
56
|
+
export declare class SelectAndMaskSession {
|
|
57
|
+
readonly controller: ImageEditorController;
|
|
58
|
+
private settingsValue;
|
|
59
|
+
private readonly editsList;
|
|
60
|
+
/** The edit being painted, shown in the preview but not yet in `edits`. */
|
|
61
|
+
private live;
|
|
62
|
+
private dragStart;
|
|
63
|
+
private pixels;
|
|
64
|
+
private previewPixels;
|
|
65
|
+
private base;
|
|
66
|
+
private previewMask;
|
|
67
|
+
private baseMask;
|
|
68
|
+
private readonly listeners;
|
|
69
|
+
/** Why the preview could not be made (no pixels), for the UI. */
|
|
70
|
+
error: string | null;
|
|
71
|
+
/** A note for the UI, such as object aware refinement applying only on OK. */
|
|
72
|
+
note: string | null;
|
|
73
|
+
/** Bumped each time the preview changes, so a UI can redraw. */
|
|
74
|
+
revision: number;
|
|
75
|
+
constructor(controller: ImageEditorController);
|
|
76
|
+
get settings(): SelectAndMaskSettings;
|
|
77
|
+
get edits(): readonly RefineEdit[];
|
|
78
|
+
/** Reads the image and makes the first preview. Resolves to false when the pixels are unavailable. */
|
|
79
|
+
open(): Promise<boolean>;
|
|
80
|
+
subscribe(listener: () => void): () => void;
|
|
81
|
+
private emit;
|
|
82
|
+
/** Preview size and the scale from natural pixels to it. */
|
|
83
|
+
get previewSize(): {
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
scale: number;
|
|
87
|
+
};
|
|
88
|
+
/** Changes settings; the preview follows. Choosing a view also sets its usual opacity. */
|
|
89
|
+
update(changes: Partial<SelectAndMaskSettings>): void;
|
|
90
|
+
private rescale;
|
|
91
|
+
/** Recomputes the preview mask from the base selection, the strokes and the settings. */
|
|
92
|
+
recompute(): void;
|
|
93
|
+
/** Coverage 0..1 of the preview at (x, y) in preview pixels (for tests and hover readouts). */
|
|
94
|
+
coverageAt(x: number, y: number): number;
|
|
95
|
+
/** The preview drawn in the current view mode: RGBA at {@link previewSize}. */
|
|
96
|
+
render(): Uint8ClampedArray;
|
|
97
|
+
/**
|
|
98
|
+
* Pointer down at `point` (natural pixels) with the current tool: starts a stroke (Quick
|
|
99
|
+
* Selection, brushes, lasso) or a box (Object Selection). Alt (or the subtract mode) removes.
|
|
100
|
+
* Hand and Zoom are the UI's own; they return false here.
|
|
101
|
+
*/
|
|
102
|
+
begin(point: ImagePoint, modifiers?: {
|
|
103
|
+
altKey?: boolean;
|
|
104
|
+
}): boolean;
|
|
105
|
+
/** Pointer move while a stroke is down. */
|
|
106
|
+
move(point: ImagePoint): void;
|
|
107
|
+
/** Pointer up: the stroke becomes an edit (one step of the workspace's own undo). */
|
|
108
|
+
end(): void;
|
|
109
|
+
/** Removes the last stroke (Ctrl/⌘+Z in the workspace). Returns false when there is none. */
|
|
110
|
+
undoEdit(): boolean;
|
|
111
|
+
/** Clears the strokes and goes back to the default settings (Reset). */
|
|
112
|
+
reset(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Photoshop's keys in the workspace: a view letter, F (next view), X (all views off and on:
|
|
115
|
+
* Show Original), J (Show Edge), P (Show Original), a tool letter, [ and ] (brush size).
|
|
116
|
+
* Returns true when the key was used.
|
|
117
|
+
*/
|
|
118
|
+
handleKey(key: string): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* OK: applies the strokes and settings to the image as one undo step (the same call an agent
|
|
121
|
+
* makes) and remembers the settings when asked to.
|
|
122
|
+
*/
|
|
123
|
+
commit(): Promise<RefineOutputResult>;
|
|
124
|
+
}
|
|
125
|
+
/** Forgets the remembered workspace settings. */
|
|
126
|
+
export declare function forgetSelectAndMaskSettings(): void;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Select and Mask workspace without a UI: its settings, strokes, preview and view modes, shared
|
|
3
|
+
* by the React and Svelte workspaces. Everything it holds is plain data (the strokes are
|
|
4
|
+
* `RefineEdit`s), and OK runs the same `refineSelectionTo` call an agent makes with `edits`, so
|
|
5
|
+
* the workspace and an agent produce the same result in one undo step.
|
|
6
|
+
*
|
|
7
|
+
* The preview is computed on a copy reduced to {@link PREVIEW_SIZE} px (or at full size with High
|
|
8
|
+
* Quality Preview) and drawn as RGBA in the chosen view mode.
|
|
9
|
+
*/
|
|
10
|
+
import type { ImageEditorController, RefineOutput, RefineOutputResult } from '../controller.js';
|
|
11
|
+
import type { ImagePoint } from '../types.js';
|
|
12
|
+
import { type RefineEdgeParams } from './refine.js';
|
|
13
|
+
import { type RefineEdit } from './refine-edits.js';
|
|
14
|
+
export type SelectAndMaskView = 'onion-skin' | 'marching-ants' | 'overlay' | 'on-black' | 'on-white' | 'black-white' | 'on-layers';
|
|
15
|
+
export type SelectAndMaskTool = 'quick-select' | 'refine-brush' | 'brush' | 'object' | 'lasso' | 'hand' | 'zoom';
|
|
16
|
+
/** The view modes with Photoshop's keys, in menu order. */
|
|
17
|
+
export declare const SELECT_AND_MASK_VIEWS: readonly {
|
|
18
|
+
id: SelectAndMaskView;
|
|
19
|
+
label: string;
|
|
20
|
+
key: string;
|
|
21
|
+
opacity: number;
|
|
22
|
+
}[];
|
|
23
|
+
/** The workspace tools with Photoshop's keys. */
|
|
24
|
+
export declare const SELECT_AND_MASK_TOOLS: readonly {
|
|
25
|
+
id: SelectAndMaskTool;
|
|
26
|
+
label: string;
|
|
27
|
+
key: string;
|
|
28
|
+
}[];
|
|
29
|
+
export interface SelectAndMaskSettings {
|
|
30
|
+
params: Required<RefineEdgeParams>;
|
|
31
|
+
output: RefineOutput;
|
|
32
|
+
/** Decontaminate Colors amount 0..100 (new-layer outputs). */
|
|
33
|
+
decontaminate: number;
|
|
34
|
+
refineMode: 'color' | 'object';
|
|
35
|
+
view: SelectAndMaskView;
|
|
36
|
+
/** How strongly the view shows what is not selected, 0..1. */
|
|
37
|
+
opacity: number;
|
|
38
|
+
/** Show only the area the refinement changes. */
|
|
39
|
+
showEdge: boolean;
|
|
40
|
+
/** Show the selection as it was, before the workspace. */
|
|
41
|
+
showOriginal: boolean;
|
|
42
|
+
/** Update the preview while painting (otherwise on release). */
|
|
43
|
+
realTime: boolean;
|
|
44
|
+
/** Preview at full size instead of a reduced copy. */
|
|
45
|
+
highQuality: boolean;
|
|
46
|
+
/** Keep these settings for the next time the workspace opens. */
|
|
47
|
+
remember: boolean;
|
|
48
|
+
tool: SelectAndMaskTool;
|
|
49
|
+
/** Brush diameter in natural pixels. */
|
|
50
|
+
brushSize: number;
|
|
51
|
+
brushMode: 'add' | 'subtract';
|
|
52
|
+
}
|
|
53
|
+
export declare const DEFAULT_SELECT_AND_MASK_SETTINGS: SelectAndMaskSettings;
|
|
54
|
+
/** Long side of the reduced preview. */
|
|
55
|
+
export declare const PREVIEW_SIZE = 1024;
|
|
56
|
+
export declare class SelectAndMaskSession {
|
|
57
|
+
readonly controller: ImageEditorController;
|
|
58
|
+
private settingsValue;
|
|
59
|
+
private readonly editsList;
|
|
60
|
+
/** The edit being painted, shown in the preview but not yet in `edits`. */
|
|
61
|
+
private live;
|
|
62
|
+
private dragStart;
|
|
63
|
+
private pixels;
|
|
64
|
+
private previewPixels;
|
|
65
|
+
private base;
|
|
66
|
+
private previewMask;
|
|
67
|
+
private baseMask;
|
|
68
|
+
private readonly listeners;
|
|
69
|
+
/** Why the preview could not be made (no pixels), for the UI. */
|
|
70
|
+
error: string | null;
|
|
71
|
+
/** A note for the UI, such as object aware refinement applying only on OK. */
|
|
72
|
+
note: string | null;
|
|
73
|
+
/** Bumped each time the preview changes, so a UI can redraw. */
|
|
74
|
+
revision: number;
|
|
75
|
+
constructor(controller: ImageEditorController);
|
|
76
|
+
get settings(): SelectAndMaskSettings;
|
|
77
|
+
get edits(): readonly RefineEdit[];
|
|
78
|
+
/** Reads the image and makes the first preview. Resolves to false when the pixels are unavailable. */
|
|
79
|
+
open(): Promise<boolean>;
|
|
80
|
+
subscribe(listener: () => void): () => void;
|
|
81
|
+
private emit;
|
|
82
|
+
/** Preview size and the scale from natural pixels to it. */
|
|
83
|
+
get previewSize(): {
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
scale: number;
|
|
87
|
+
};
|
|
88
|
+
/** Changes settings; the preview follows. Choosing a view also sets its usual opacity. */
|
|
89
|
+
update(changes: Partial<SelectAndMaskSettings>): void;
|
|
90
|
+
private rescale;
|
|
91
|
+
/** Recomputes the preview mask from the base selection, the strokes and the settings. */
|
|
92
|
+
recompute(): void;
|
|
93
|
+
/** Coverage 0..1 of the preview at (x, y) in preview pixels (for tests and hover readouts). */
|
|
94
|
+
coverageAt(x: number, y: number): number;
|
|
95
|
+
/** The preview drawn in the current view mode: RGBA at {@link previewSize}. */
|
|
96
|
+
render(): Uint8ClampedArray;
|
|
97
|
+
/**
|
|
98
|
+
* Pointer down at `point` (natural pixels) with the current tool: starts a stroke (Quick
|
|
99
|
+
* Selection, brushes, lasso) or a box (Object Selection). Alt (or the subtract mode) removes.
|
|
100
|
+
* Hand and Zoom are the UI's own; they return false here.
|
|
101
|
+
*/
|
|
102
|
+
begin(point: ImagePoint, modifiers?: {
|
|
103
|
+
altKey?: boolean;
|
|
104
|
+
}): boolean;
|
|
105
|
+
/** Pointer move while a stroke is down. */
|
|
106
|
+
move(point: ImagePoint): void;
|
|
107
|
+
/** Pointer up: the stroke becomes an edit (one step of the workspace's own undo). */
|
|
108
|
+
end(): void;
|
|
109
|
+
/** Removes the last stroke (Ctrl/⌘+Z in the workspace). Returns false when there is none. */
|
|
110
|
+
undoEdit(): boolean;
|
|
111
|
+
/** Clears the strokes and goes back to the default settings (Reset). */
|
|
112
|
+
reset(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Photoshop's keys in the workspace: a view letter, F (next view), X (all views off and on:
|
|
115
|
+
* Show Original), J (Show Edge), P (Show Original), a tool letter, [ and ] (brush size).
|
|
116
|
+
* Returns true when the key was used.
|
|
117
|
+
*/
|
|
118
|
+
handleKey(key: string): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* OK: applies the strokes and settings to the image as one undo step (the same call an agent
|
|
121
|
+
* makes) and remembers the settings when asked to.
|
|
122
|
+
*/
|
|
123
|
+
commit(): Promise<RefineOutputResult>;
|
|
124
|
+
}
|
|
125
|
+
/** Forgets the remembered workspace settings. */
|
|
126
|
+
export declare function forgetSelectAndMaskSettings(): void;
|
package/package.json
CHANGED
|
@@ -269,7 +269,7 @@ in the source frame at the document's bit depth, colour mode and profile. Read
|
|
|
269
269
|
| `grow_selection` | Select › Grow: add connected pixels within `tolerance` (default 32) of a selected colour; follows colour, not distance. `sample`, `sampleMerged`. Fails when nothing is selected. Returns the summary. |
|
|
270
270
|
| `select_similar` | Select › Similar: add every pixel in the image within `tolerance` of a selected colour, connected or not. Fails when nothing is selected. Returns the summary. |
|
|
271
271
|
| `reselect` | Bring back the last selection `deselect` cleared (one undo step). Fails when there is none. Returns the summary. |
|
|
272
|
-
| `refine_selection` | Select and Mask: snap the selection edge to image edges within `radius` px (0..64, default 8), with `smartRadius`, `smooth` 0..100, `feather` px, `contrast` 0..100 and `shiftEdge` -100..100 %, then `output` to `selection` (default), `layer-mask`, `new-layer` or `new-layer-with-mask` (on `layerId`, default active; new layers hide the source), with `decontaminate` 0..100 for new layers. `edits` (`quick-select`, `brush` add/subtract
|
|
272
|
+
| `refine_selection` | Select and Mask: snap the selection edge to image edges within `radius` px (0..64, default 8), with `smartRadius`, `smooth` 0..100, `feather` px, `contrast` 0..100 and `shiftEdge` -100..100 %, then `output` to `selection` (default), `layer-mask`, `new-layer` or `new-layer-with-mask` (on `layerId`, default active; new layers hide the source), with `decontaminate` 0..100 for new layers. `edits` (`quick-select`, `brush`, `lasso`, `object` add/subtract; `refine-brush` over hair) apply first; `refineMode: "object"` uses the host model. One step; returns `refineMode`, `layerId` / `newLayerId`. Use on hair, fur, foliage or a coarse AI mask. |
|
|
273
273
|
| `update_adjustment_layer` | Change a layer's `enabled` (false hides it without deleting), `blend`, `opacity` (0..1) or `name` in one undo step. Returns the layer. Its parameters change with `set_adjustments`. Toggle `enabled` to compare a layer's effect before and after. |
|
|
274
274
|
| `move_adjustment_layer` | Move a layer to index `to` (0 = bottom, applied first; past the top means top). Order matters: a curves layer above a hue/saturation layer works on its output. Fails when the layer is already there. Returns the ids bottom to top. |
|
|
275
275
|
| `remove_adjustment_layer` | Delete a layer and its mask. Prefer hiding it with `update_adjustment_layer` when the user may want it back. Returns the remaining ids. |
|
|
@@ -59,8 +59,10 @@ This skill is the method. `pixerate-image-editor` has the full tool reference.
|
|
|
59
59
|
- `refine_selection` snaps to real edges: radius 2–4 for hard edges, 8–20 for hair and fur;
|
|
60
60
|
`smartRadius: true` for mixed edges. For flyaway hair beyond the radius, add `edits` with a
|
|
61
61
|
`refine-brush` stroke along it (size covering the strands); fix misses and leaks in the same
|
|
62
|
-
call with `quick-select` or `
|
|
63
|
-
|
|
62
|
+
call with `quick-select`, `brush` or `lasso` strokes, or an `object` box (`mode:
|
|
63
|
+
"subtract"` to remove). These are the Select and Mask workspace's own tools, so a person
|
|
64
|
+
can open the same edits in the workspace. With a host model, `refineMode: "object"`
|
|
65
|
+
refines from the model's outline.
|
|
64
66
|
- `shiftEdge` −10..−30 % tightens a refined edge that picked up background.
|
|
65
67
|
**Check:** `percent` changed by roughly what you intended (a few percent at most for a
|
|
66
68
|
cleanup).
|