@pixerate/editor 0.197.0 → 0.199.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.
@@ -1,6 +1,7 @@
1
1
  import { AdjustmentKind, AdjustmentLayer, AdjustmentParamsMap, Annotation, CreateAnnotationPayload, AspectRatio, CropBox, DepthMaskOptions, ExportOptions, ImageAdjustments, ImageDimensions, ImageEditorFit, ImageEditorOptions, ImageEditorState, ImageEditorTool, ImageTransform, ImagePoint, SerializedImageEditorState } from './types.cjs';
2
2
  import { type PathToSelectionOptions, type SelectionToPathOptions } from './selection/path.cjs';
3
3
  import { type MagneticEdgeOptions } from './selection/magnetic.cjs';
4
+ import { type ObjectTarget } from './selection/segment/grabcut.cjs';
4
5
  import { RenderOptions } from './renderer.cjs';
5
6
  import { type BlendMode } from './blend.cjs';
6
7
  import type { ImageHistogram } from './histogram.cjs';
@@ -151,6 +152,15 @@ export interface QuickSelectCommandOptions {
151
152
  /** Smoother, less blocky edges (Photoshop's Auto-Enhance). Default false. */
152
153
  enhanceEdge?: boolean;
153
154
  }
155
+ /** Options of {@link ImageEditorController.selectObject}. */
156
+ export interface SelectObjectCommandOptions {
157
+ /** How the object combines with the selection (default `replace`). */
158
+ mode?: SelectionMode;
159
+ /** Sample every layer (default true) or only the active pixel layer. */
160
+ sampleAllLayers?: boolean;
161
+ /** Smoother, less blocky edges (Auto-Enhance). Default false. */
162
+ enhanceEdge?: boolean;
163
+ }
154
164
  /** A new adjustment layer: its kind plus optional initial values and position. */
155
165
  export interface AdjustmentLayerInit<K extends AdjustmentKind = AdjustmentKind> extends AdjustmentLayerUpdate<K> {
156
166
  kind: K;
@@ -664,7 +674,7 @@ export declare class ImageEditorController {
664
674
  * or those drawn while a result was rendering, once it is in. A cache refresh: no undo step.
665
675
  */
666
676
  private refreshEffectSurfaces;
667
- /** The registered segmentation provider, or `null` (then `selectSubject` is unavailable). */
677
+ /** The registered segmentation provider, or `null` (then `selectSubject` finds the most salient subject without a model). */
668
678
  get segmentationProvider(): SegmentationProvider | null;
669
679
  /** Registers (or with `null` removes) the segmentation provider. Not an edit: no undo step. */
670
680
  setSegmentationProvider(provider: SegmentationProvider | null): void;
@@ -1523,6 +1533,13 @@ export declare class ImageEditorController {
1523
1533
  * one undo step. Resolves to the resulting selection.
1524
1534
  */
1525
1535
  quickSelect(strokes: ImagePoint[][], options?: QuickSelectCommandOptions): Promise<SelectionMask | null>;
1536
+ /**
1537
+ * Object Selection: the object inside `target.rect` (natural pixels; what is outside the box is
1538
+ * background) or under `target.point`, found by GrabCut (colour models of object and background
1539
+ * plus a graph cut along edges), combined with the selection by `mode` as one undo step.
1540
+ * Resolves to the resulting selection.
1541
+ */
1542
+ selectObject(target: ObjectTarget, options?: SelectObjectCommandOptions): Promise<SelectionMask | null>;
1526
1543
  /**
1527
1544
  * Supplies the pixels the selection tools sample (natural size RGBA), e.g. decoded in a worker
1528
1545
  * or in a test; `null` goes back to reading the source image. Without a canvas (Node, workers)
@@ -1596,19 +1613,25 @@ export declare class ImageEditorController {
1596
1613
  * Select › Subject: asks the segmentation provider for the objects matching `target` ("the
1597
1614
  * dog", "the sky") in the flattened image and selects their shapes, combined with the
1598
1615
  * selection by `mode`, as one undo step. Returns what was found (labels and bounds in natural
1599
- * pixels); an empty list leaves the selection as it was. Throws without a provider.
1616
+ * pixels); an empty list leaves the selection as it was. Without a provider, the subject that
1617
+ * stands out most is found classically (superpixels, saliency, Otsu, GrabCut): `target` can't
1618
+ * choose it, and `method: 'saliency'` and a `note` say so.
1600
1619
  */
1601
- selectSubject(target: string, options?: SelectionCommandOptions & {
1620
+ selectSubject(target?: string, options?: SelectionCommandOptions & {
1602
1621
  maxSegments?: number;
1603
1622
  signal?: AbortSignal;
1604
1623
  /** Called with the outlines found (image pixels; a mask-only result's bounds) before the selection changes, e.g. to trace them with an agent's cursor. */
1605
1624
  beforeApply?: (outlines: ImagePoint[][]) => void | Promise<void>;
1625
+ /** Without a model: smoother, less blocky edges (Auto-Enhance). */
1626
+ enhanceEdge?: boolean;
1606
1627
  }): Promise<{
1607
1628
  segments: {
1608
1629
  label: string;
1609
1630
  bounds: CropBox | null;
1610
1631
  score?: number;
1611
1632
  }[];
1633
+ method: 'model' | 'saliency';
1634
+ note?: string;
1612
1635
  }>;
1613
1636
  /** Quick Mask view (tints the unselected area). View state: no undo step. */
1614
1637
  setQuickMask(on: boolean): void;
@@ -1,6 +1,7 @@
1
1
  import { AdjustmentKind, AdjustmentLayer, AdjustmentParamsMap, Annotation, CreateAnnotationPayload, AspectRatio, CropBox, DepthMaskOptions, ExportOptions, ImageAdjustments, ImageDimensions, ImageEditorFit, ImageEditorOptions, ImageEditorState, ImageEditorTool, ImageTransform, ImagePoint, SerializedImageEditorState } from './types.js';
2
2
  import { type PathToSelectionOptions, type SelectionToPathOptions } from './selection/path.js';
3
3
  import { type MagneticEdgeOptions } from './selection/magnetic.js';
4
+ import { type ObjectTarget } from './selection/segment/grabcut.js';
4
5
  import { RenderOptions } from './renderer.js';
5
6
  import { type BlendMode } from './blend.js';
6
7
  import type { ImageHistogram } from './histogram.js';
@@ -151,6 +152,15 @@ export interface QuickSelectCommandOptions {
151
152
  /** Smoother, less blocky edges (Photoshop's Auto-Enhance). Default false. */
152
153
  enhanceEdge?: boolean;
153
154
  }
155
+ /** Options of {@link ImageEditorController.selectObject}. */
156
+ export interface SelectObjectCommandOptions {
157
+ /** How the object combines with the selection (default `replace`). */
158
+ mode?: SelectionMode;
159
+ /** Sample every layer (default true) or only the active pixel layer. */
160
+ sampleAllLayers?: boolean;
161
+ /** Smoother, less blocky edges (Auto-Enhance). Default false. */
162
+ enhanceEdge?: boolean;
163
+ }
154
164
  /** A new adjustment layer: its kind plus optional initial values and position. */
155
165
  export interface AdjustmentLayerInit<K extends AdjustmentKind = AdjustmentKind> extends AdjustmentLayerUpdate<K> {
156
166
  kind: K;
@@ -664,7 +674,7 @@ export declare class ImageEditorController {
664
674
  * or those drawn while a result was rendering, once it is in. A cache refresh: no undo step.
665
675
  */
666
676
  private refreshEffectSurfaces;
667
- /** The registered segmentation provider, or `null` (then `selectSubject` is unavailable). */
677
+ /** The registered segmentation provider, or `null` (then `selectSubject` finds the most salient subject without a model). */
668
678
  get segmentationProvider(): SegmentationProvider | null;
669
679
  /** Registers (or with `null` removes) the segmentation provider. Not an edit: no undo step. */
670
680
  setSegmentationProvider(provider: SegmentationProvider | null): void;
@@ -1523,6 +1533,13 @@ export declare class ImageEditorController {
1523
1533
  * one undo step. Resolves to the resulting selection.
1524
1534
  */
1525
1535
  quickSelect(strokes: ImagePoint[][], options?: QuickSelectCommandOptions): Promise<SelectionMask | null>;
1536
+ /**
1537
+ * Object Selection: the object inside `target.rect` (natural pixels; what is outside the box is
1538
+ * background) or under `target.point`, found by GrabCut (colour models of object and background
1539
+ * plus a graph cut along edges), combined with the selection by `mode` as one undo step.
1540
+ * Resolves to the resulting selection.
1541
+ */
1542
+ selectObject(target: ObjectTarget, options?: SelectObjectCommandOptions): Promise<SelectionMask | null>;
1526
1543
  /**
1527
1544
  * Supplies the pixels the selection tools sample (natural size RGBA), e.g. decoded in a worker
1528
1545
  * or in a test; `null` goes back to reading the source image. Without a canvas (Node, workers)
@@ -1596,19 +1613,25 @@ export declare class ImageEditorController {
1596
1613
  * Select › Subject: asks the segmentation provider for the objects matching `target` ("the
1597
1614
  * dog", "the sky") in the flattened image and selects their shapes, combined with the
1598
1615
  * selection by `mode`, as one undo step. Returns what was found (labels and bounds in natural
1599
- * pixels); an empty list leaves the selection as it was. Throws without a provider.
1616
+ * pixels); an empty list leaves the selection as it was. Without a provider, the subject that
1617
+ * stands out most is found classically (superpixels, saliency, Otsu, GrabCut): `target` can't
1618
+ * choose it, and `method: 'saliency'` and a `note` say so.
1600
1619
  */
1601
- selectSubject(target: string, options?: SelectionCommandOptions & {
1620
+ selectSubject(target?: string, options?: SelectionCommandOptions & {
1602
1621
  maxSegments?: number;
1603
1622
  signal?: AbortSignal;
1604
1623
  /** Called with the outlines found (image pixels; a mask-only result's bounds) before the selection changes, e.g. to trace them with an agent's cursor. */
1605
1624
  beforeApply?: (outlines: ImagePoint[][]) => void | Promise<void>;
1625
+ /** Without a model: smoother, less blocky edges (Auto-Enhance). */
1626
+ enhanceEdge?: boolean;
1606
1627
  }): Promise<{
1607
1628
  segments: {
1608
1629
  label: string;
1609
1630
  bounds: CropBox | null;
1610
1631
  score?: number;
1611
1632
  }[];
1633
+ method: 'model' | 'saliency';
1634
+ note?: string;
1612
1635
  }>;
1613
1636
  /** Quick Mask view (tints the unselected area). View state: no undo step. */
1614
1637
  setQuickMask(on: boolean): void;