@pixerate/editor 0.196.0 → 0.197.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/controller.d.cts +18 -0
- package/dist/image-editor/controller.d.ts +18 -0
- package/dist/image-editor/index.cjs +978 -300
- package/dist/image-editor/index.js +684 -6
- package/dist/image-editor/selection/gesture.d.cts +6 -0
- package/dist/image-editor/selection/gesture.d.ts +6 -0
- 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/segment/index.d.cts +2 -0
- package/dist/image-editor/selection/segment/index.d.ts +2 -0
- package/dist/image-editor/selection/segment/maxflow.d.cts +30 -0
- package/dist/image-editor/selection/segment/maxflow.d.ts +30 -0
- package/dist/image-editor/selection/segment/quick.d.cts +47 -0
- package/dist/image-editor/selection/segment/quick.d.ts +47 -0
- package/dist/image-editor/selection/tool-options.d.cts +7 -1
- package/dist/image-editor/selection/tool-options.d.ts +7 -1
- package/package.json +1 -1
|
@@ -27,6 +27,9 @@ export declare function snapTo45(from: ImagePoint, point: ImagePoint): ImagePoin
|
|
|
27
27
|
* last anchor to the pointer (snapped to the strongest edge within the width) and places
|
|
28
28
|
* anchors as it goes (frequency); a click adds one, and closing and the keys are as the
|
|
29
29
|
* polygonal lasso's. The first click reads the pixels (async).
|
|
30
|
+
* - Quick Selection: drag (or click) a brush stroke; on `end` it grows into the region painted on,
|
|
31
|
+
* out to its edges (async: await {@link settled}). With the New mode and a selection already
|
|
32
|
+
* there, strokes add, as in Photoshop; Alt subtracts.
|
|
30
33
|
* - Single row / column: a click selects a 1 px line across the image.
|
|
31
34
|
*
|
|
32
35
|
* Shift adds, Alt subtracts, both intersect (overriding the options bar mode). While dragging,
|
|
@@ -48,8 +51,11 @@ export declare class SelectionGesture {
|
|
|
48
51
|
closeRadius: number;
|
|
49
52
|
/** The last error (e.g. pixels unavailable for the wand), for the UI to show. */
|
|
50
53
|
error: string | null;
|
|
54
|
+
private pending;
|
|
51
55
|
constructor(controller: ImageEditorController, getOptions: () => SelectionToolOptions);
|
|
52
56
|
get active(): boolean;
|
|
57
|
+
/** Resolves once a Quick Selection stroke has been applied. */
|
|
58
|
+
get settled(): Promise<void>;
|
|
53
59
|
/** The anchors of a Magnetic Lasso being drawn (empty otherwise). */
|
|
54
60
|
get magneticAnchors(): ImagePoint[];
|
|
55
61
|
/** The outline of the shape being drawn, or `null`. */
|
|
@@ -27,6 +27,9 @@ export declare function snapTo45(from: ImagePoint, point: ImagePoint): ImagePoin
|
|
|
27
27
|
* last anchor to the pointer (snapped to the strongest edge within the width) and places
|
|
28
28
|
* anchors as it goes (frequency); a click adds one, and closing and the keys are as the
|
|
29
29
|
* polygonal lasso's. The first click reads the pixels (async).
|
|
30
|
+
* - Quick Selection: drag (or click) a brush stroke; on `end` it grows into the region painted on,
|
|
31
|
+
* out to its edges (async: await {@link settled}). With the New mode and a selection already
|
|
32
|
+
* there, strokes add, as in Photoshop; Alt subtracts.
|
|
30
33
|
* - Single row / column: a click selects a 1 px line across the image.
|
|
31
34
|
*
|
|
32
35
|
* Shift adds, Alt subtracts, both intersect (overriding the options bar mode). While dragging,
|
|
@@ -48,8 +51,11 @@ export declare class SelectionGesture {
|
|
|
48
51
|
closeRadius: number;
|
|
49
52
|
/** The last error (e.g. pixels unavailable for the wand), for the UI to show. */
|
|
50
53
|
error: string | null;
|
|
54
|
+
private pending;
|
|
51
55
|
constructor(controller: ImageEditorController, getOptions: () => SelectionToolOptions);
|
|
52
56
|
get active(): boolean;
|
|
57
|
+
/** Resolves once a Quick Selection stroke has been applied. */
|
|
58
|
+
get settled(): Promise<void>;
|
|
53
59
|
/** The anchors of a Magnetic Lasso being drawn (empty otherwise). */
|
|
54
60
|
get magneticAnchors(): ImagePoint[];
|
|
55
61
|
/** The outline of the shape being drawn, or `null`. */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Max-flow / min-cut on a 4-connected pixel grid (Boykov & Kolmogorov, "An Experimental
|
|
3
|
+
* Comparison of Min-Cut/Max-Flow Algorithms for Energy Minimization in Vision", 2004): two search
|
|
4
|
+
* trees grown from the source and the sink, reused between augmentations. The graph segmentations
|
|
5
|
+
* (Quick Selection, Object Selection) label each pixel by the side of the cut it ends up on.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A `width × height` grid graph. Each node has an edge to its right, lower, left and upper
|
|
9
|
+
* neighbour (directions 0..3; the reverse of `d` is `d ^ 2`) and a terminal capacity. Use whole
|
|
10
|
+
* numbers for capacities: with fractions, rounding leaves residuals a hair above zero and the
|
|
11
|
+
* search slows to a crawl on near-empty paths.
|
|
12
|
+
*/
|
|
13
|
+
export declare class GridGraph {
|
|
14
|
+
readonly width: number;
|
|
15
|
+
readonly height: number;
|
|
16
|
+
/** Residual capacity of the edge leaving node `p` in direction `d`, at `p * 4 + d`. */
|
|
17
|
+
readonly cap: Float64Array;
|
|
18
|
+
/** Net terminal capacity: above 0 to the source, below 0 to the sink. */
|
|
19
|
+
readonly tr: Float64Array;
|
|
20
|
+
private readonly tree;
|
|
21
|
+
constructor(width: number, height: number);
|
|
22
|
+
/** Sets the capacity of the edge between `p` and its neighbour in direction `d`, both ways. */
|
|
23
|
+
setEdge(p: number, d: 0 | 1, capacity: number): void;
|
|
24
|
+
/** Adds `source` (cost of putting `p` on the sink side) and `sink` (the other way) to `p`. */
|
|
25
|
+
addTerminal(p: number, source: number, sink: number): void;
|
|
26
|
+
/** Whether `p` is on the source side of the minimum cut (after {@link maxflow}). */
|
|
27
|
+
inSource(p: number): boolean;
|
|
28
|
+
/** Runs max-flow and returns the flow (the cut's cost, less the constant terminal parts). */
|
|
29
|
+
maxflow(): number;
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Max-flow / min-cut on a 4-connected pixel grid (Boykov & Kolmogorov, "An Experimental
|
|
3
|
+
* Comparison of Min-Cut/Max-Flow Algorithms for Energy Minimization in Vision", 2004): two search
|
|
4
|
+
* trees grown from the source and the sink, reused between augmentations. The graph segmentations
|
|
5
|
+
* (Quick Selection, Object Selection) label each pixel by the side of the cut it ends up on.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A `width × height` grid graph. Each node has an edge to its right, lower, left and upper
|
|
9
|
+
* neighbour (directions 0..3; the reverse of `d` is `d ^ 2`) and a terminal capacity. Use whole
|
|
10
|
+
* numbers for capacities: with fractions, rounding leaves residuals a hair above zero and the
|
|
11
|
+
* search slows to a crawl on near-empty paths.
|
|
12
|
+
*/
|
|
13
|
+
export declare class GridGraph {
|
|
14
|
+
readonly width: number;
|
|
15
|
+
readonly height: number;
|
|
16
|
+
/** Residual capacity of the edge leaving node `p` in direction `d`, at `p * 4 + d`. */
|
|
17
|
+
readonly cap: Float64Array;
|
|
18
|
+
/** Net terminal capacity: above 0 to the source, below 0 to the sink. */
|
|
19
|
+
readonly tr: Float64Array;
|
|
20
|
+
private readonly tree;
|
|
21
|
+
constructor(width: number, height: number);
|
|
22
|
+
/** Sets the capacity of the edge between `p` and its neighbour in direction `d`, both ways. */
|
|
23
|
+
setEdge(p: number, d: 0 | 1, capacity: number): void;
|
|
24
|
+
/** Adds `source` (cost of putting `p` on the sink side) and `sink` (the other way) to `p`. */
|
|
25
|
+
addTerminal(p: number, source: number, sink: number): void;
|
|
26
|
+
/** Whether `p` is on the source side of the minimum cut (after {@link maxflow}). */
|
|
27
|
+
inSource(p: number): boolean;
|
|
28
|
+
/** Runs max-flow and returns the flow (the cut's cost, less the constant terminal parts). */
|
|
29
|
+
maxflow(): number;
|
|
30
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quick Selection: a brush stroke grows into the region it is painted on, out to that region's
|
|
3
|
+
* edges. Graph cut (Boykov & Jolly, "Interactive Graph Cuts", 2001) on a reduced copy of the
|
|
4
|
+
* image: the pixels under the brush are fixed to the selection, colour models of the stroke and of
|
|
5
|
+
* the surroundings pull every other pixel one way or the other, and cutting between dissimilar
|
|
6
|
+
* neighbours is cheap, so the cut runs along edges. The search starts in a window around the
|
|
7
|
+
* stroke and widens while the region reaches its border. The result is scaled back up and its
|
|
8
|
+
* edge pixels anti-aliased at full size from the colours either side of the edge.
|
|
9
|
+
*/
|
|
10
|
+
import type { ImagePoint } from '../../types.cjs';
|
|
11
|
+
import { type PixelBuffer, type SelectionMask } from '../mask.cjs';
|
|
12
|
+
/** The reduced image the segmentations work on (sRGB, 0..255 per channel). */
|
|
13
|
+
export interface WorkImage {
|
|
14
|
+
/** Natural size of the image it was made from. */
|
|
15
|
+
sourceWidth: number;
|
|
16
|
+
sourceHeight: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
/** Reduced pixels per natural pixel (≤ 1). */
|
|
20
|
+
scale: number;
|
|
21
|
+
/** RGB, 3 values per pixel. */
|
|
22
|
+
rgb: Float32Array;
|
|
23
|
+
}
|
|
24
|
+
/** Long side of the work image (the issue's 512²). */
|
|
25
|
+
export declare const WORK_SIZE = 512;
|
|
26
|
+
/**
|
|
27
|
+
* `pixels` reduced to at most {@link WORK_SIZE} px on the long side by area averaging (alpha
|
|
28
|
+
* composited over white). Cached per pixel buffer.
|
|
29
|
+
*/
|
|
30
|
+
export declare function workImage(pixels: PixelBuffer, maxSide?: number): WorkImage;
|
|
31
|
+
export interface QuickSelectOptions {
|
|
32
|
+
/** Brush diameter in natural pixels (default 30). */
|
|
33
|
+
size?: number;
|
|
34
|
+
/**
|
|
35
|
+
* The current selection: with `grow` its pixels near the stroke count as part of what is being
|
|
36
|
+
* selected (Add), so the new region joins on to it.
|
|
37
|
+
*/
|
|
38
|
+
selection?: SelectionMask | null;
|
|
39
|
+
grow?: boolean;
|
|
40
|
+
/** Smoother, less blocky edges (Photoshop's Auto-Enhance). Default false. */
|
|
41
|
+
enhanceEdge?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The region one Quick Selection stroke selects over `pixels`, as a selection of the whole image
|
|
45
|
+
* (not yet combined with the current one). `stroke` is the brush's path in natural pixels.
|
|
46
|
+
*/
|
|
47
|
+
export declare function quickSelectStroke(pixels: PixelBuffer, stroke: readonly ImagePoint[], options?: QuickSelectOptions): SelectionMask;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quick Selection: a brush stroke grows into the region it is painted on, out to that region's
|
|
3
|
+
* edges. Graph cut (Boykov & Jolly, "Interactive Graph Cuts", 2001) on a reduced copy of the
|
|
4
|
+
* image: the pixels under the brush are fixed to the selection, colour models of the stroke and of
|
|
5
|
+
* the surroundings pull every other pixel one way or the other, and cutting between dissimilar
|
|
6
|
+
* neighbours is cheap, so the cut runs along edges. The search starts in a window around the
|
|
7
|
+
* stroke and widens while the region reaches its border. The result is scaled back up and its
|
|
8
|
+
* edge pixels anti-aliased at full size from the colours either side of the edge.
|
|
9
|
+
*/
|
|
10
|
+
import type { ImagePoint } from '../../types.js';
|
|
11
|
+
import { type PixelBuffer, type SelectionMask } from '../mask.js';
|
|
12
|
+
/** The reduced image the segmentations work on (sRGB, 0..255 per channel). */
|
|
13
|
+
export interface WorkImage {
|
|
14
|
+
/** Natural size of the image it was made from. */
|
|
15
|
+
sourceWidth: number;
|
|
16
|
+
sourceHeight: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
/** Reduced pixels per natural pixel (≤ 1). */
|
|
20
|
+
scale: number;
|
|
21
|
+
/** RGB, 3 values per pixel. */
|
|
22
|
+
rgb: Float32Array;
|
|
23
|
+
}
|
|
24
|
+
/** Long side of the work image (the issue's 512²). */
|
|
25
|
+
export declare const WORK_SIZE = 512;
|
|
26
|
+
/**
|
|
27
|
+
* `pixels` reduced to at most {@link WORK_SIZE} px on the long side by area averaging (alpha
|
|
28
|
+
* composited over white). Cached per pixel buffer.
|
|
29
|
+
*/
|
|
30
|
+
export declare function workImage(pixels: PixelBuffer, maxSide?: number): WorkImage;
|
|
31
|
+
export interface QuickSelectOptions {
|
|
32
|
+
/** Brush diameter in natural pixels (default 30). */
|
|
33
|
+
size?: number;
|
|
34
|
+
/**
|
|
35
|
+
* The current selection: with `grow` its pixels near the stroke count as part of what is being
|
|
36
|
+
* selected (Add), so the new region joins on to it.
|
|
37
|
+
*/
|
|
38
|
+
selection?: SelectionMask | null;
|
|
39
|
+
grow?: boolean;
|
|
40
|
+
/** Smoother, less blocky edges (Photoshop's Auto-Enhance). Default false. */
|
|
41
|
+
enhanceEdge?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The region one Quick Selection stroke selects over `pixels`, as a selection of the whole image
|
|
45
|
+
* (not yet combined with the current one). `stroke` is the brush's path in natural pixels.
|
|
46
|
+
*/
|
|
47
|
+
export declare function quickSelectStroke(pixels: PixelBuffer, stroke: readonly ImagePoint[], options?: QuickSelectOptions): SelectionMask;
|
|
@@ -2,7 +2,7 @@ import { type SelectionMask, type SelectionMode } from './mask.cjs';
|
|
|
2
2
|
import type { ColorDistance, ColorRangePreset } from './wand.cjs';
|
|
3
3
|
import type { RefineEdgeParams } from './refine.cjs';
|
|
4
4
|
/** Selection tools of the image editor UI. */
|
|
5
|
-
export type SelectionToolKind = 'wand' | 'rect' | 'ellipse' | 'row' | 'column' | 'lasso' | 'polygon' | 'magnetic' | 'range' | 'type' | 'type-vertical';
|
|
5
|
+
export type SelectionToolKind = 'wand' | 'rect' | 'ellipse' | 'row' | 'column' | 'lasso' | 'polygon' | 'magnetic' | 'quick' | 'range' | 'type' | 'type-vertical';
|
|
6
6
|
export declare const SELECTION_TOOLS: readonly {
|
|
7
7
|
id: SelectionToolKind;
|
|
8
8
|
label: string;
|
|
@@ -37,6 +37,12 @@ export interface SelectionToolOptions {
|
|
|
37
37
|
magneticContrast?: number;
|
|
38
38
|
/** Magnetic Lasso: how often anchors are placed as the pointer moves (0..100, default 57). */
|
|
39
39
|
magneticFrequency?: number;
|
|
40
|
+
/** Quick Selection: brush diameter in natural pixels (default 30). */
|
|
41
|
+
quickSize?: number;
|
|
42
|
+
/** Quick Selection: read every layer (default true) or only the active pixel layer. */
|
|
43
|
+
quickSampleAll?: boolean;
|
|
44
|
+
/** Quick Selection: smoother, less blocky edges (Auto-Enhance; default false). */
|
|
45
|
+
quickEnhance?: boolean;
|
|
40
46
|
/** Type Mask: the text to select (default "Type"). A click places its first baseline. */
|
|
41
47
|
typeText?: string;
|
|
42
48
|
/** Type Mask: font size in px (default 72). */
|
|
@@ -2,7 +2,7 @@ import { type SelectionMask, type SelectionMode } from './mask.js';
|
|
|
2
2
|
import type { ColorDistance, ColorRangePreset } from './wand.js';
|
|
3
3
|
import type { RefineEdgeParams } from './refine.js';
|
|
4
4
|
/** Selection tools of the image editor UI. */
|
|
5
|
-
export type SelectionToolKind = 'wand' | 'rect' | 'ellipse' | 'row' | 'column' | 'lasso' | 'polygon' | 'magnetic' | 'range' | 'type' | 'type-vertical';
|
|
5
|
+
export type SelectionToolKind = 'wand' | 'rect' | 'ellipse' | 'row' | 'column' | 'lasso' | 'polygon' | 'magnetic' | 'quick' | 'range' | 'type' | 'type-vertical';
|
|
6
6
|
export declare const SELECTION_TOOLS: readonly {
|
|
7
7
|
id: SelectionToolKind;
|
|
8
8
|
label: string;
|
|
@@ -37,6 +37,12 @@ export interface SelectionToolOptions {
|
|
|
37
37
|
magneticContrast?: number;
|
|
38
38
|
/** Magnetic Lasso: how often anchors are placed as the pointer moves (0..100, default 57). */
|
|
39
39
|
magneticFrequency?: number;
|
|
40
|
+
/** Quick Selection: brush diameter in natural pixels (default 30). */
|
|
41
|
+
quickSize?: number;
|
|
42
|
+
/** Quick Selection: read every layer (default true) or only the active pixel layer. */
|
|
43
|
+
quickSampleAll?: boolean;
|
|
44
|
+
/** Quick Selection: smoother, less blocky edges (Auto-Enhance; default false). */
|
|
45
|
+
quickEnhance?: boolean;
|
|
40
46
|
/** Type Mask: the text to select (default "Type"). A click places its first baseline. */
|
|
41
47
|
typeText?: string;
|
|
42
48
|
/** Type Mask: font size in px (default 72). */
|