@pixerate/editor 0.272.1 → 0.273.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.
@@ -18,6 +18,7 @@ import { type LayerLocks } from '../raster/layers.js';
18
18
  import { type LayerEffect, type LayerEffectKind, type LayerEffects } from '../raster/effects/model.js';
19
19
  import type { EffectPattern } from '../raster/effects/patterns.js';
20
20
  import { TiledSurface, type RasterRect, type Tile } from '../raster/surface.js';
21
+ import { type FillRegionPoint, type FillRegionSummary, type UnfilledRegion } from '../raster/fill.js';
21
22
  import { type PaintBrushInput, type PaintBrush } from './brushes.js';
22
23
  import { type BrushLibrary, type BrushLibraryFile } from '../brushes/library.js';
23
24
  import { type BrushPatch, type UnsettableBrushFacet } from '../brushes/patch.js';
@@ -297,6 +298,75 @@ export interface FillLayerOptions {
297
298
  pressure?: number;
298
299
  blend?: BlendMode;
299
300
  }
301
+ export type FillReference = 'layer' | 'all' | 'composite' | (string & {});
302
+ export interface FillRegionOptions {
303
+ /** Seed x in document pixels (pass `x` and `y`, or `points`). */
304
+ x?: number;
305
+ /** Seed y in document pixels (pass `x` and `y`, or `points`). */
306
+ y?: number;
307
+ /** Multiple seed points in document pixels (filled together as one undo step). */
308
+ points?: ReadonlyArray<FillRegionPoint>;
309
+ /** Target layer id from `listLayers` (default the active layer). */
310
+ layerId?: string;
311
+ /**
312
+ * Which pixels define the region boundaries:
313
+ * - `'layer'` (default): the target layer itself.
314
+ * - `'all'` or `'composite'`: all visible layers composited (without paper).
315
+ * - a layer id from `listLayers`: that layer (e.g. an ink line-art layer above a flats layer).
316
+ */
317
+ reference?: FillReference;
318
+ /** Fill colour #rrggbb (default the editor's paint colour). */
319
+ color?: string;
320
+ /** Opacity 0..1 (default 1). */
321
+ opacity?: number;
322
+ /** Blend mode (default `'normal'`). */
323
+ blend?: BlendMode;
324
+ /** Alias for `blend`. */
325
+ blendMode?: BlendMode;
326
+ /** Colour/alpha similarity tolerance 0..255 (default 32). */
327
+ tolerance?: number;
328
+ /** Close small gaps in line art up to this width in pixels, 0..32 (default 0). */
329
+ closeGap?: number;
330
+ /** Expand (> 0, bleed under lines) or contract (< 0) the filled region in pixels, -16..16 (default 0). */
331
+ expand?: number;
332
+ /** Soften boundary edges (default true). */
333
+ antialias?: boolean;
334
+ /** Paper grain response 0..1 (default 0: flat fill). */
335
+ grain?: number;
336
+ /** With grain: pressure 0..1, how far the fill reaches into the valleys (default 0.5). */
337
+ pressure?: number;
338
+ /** Pour a wet watercolour wash into the region on the layer's wet layer (default false). */
339
+ wet?: boolean;
340
+ }
341
+ export interface FillRegionResult {
342
+ layerId: string;
343
+ bounds: RasterRect | null;
344
+ pixelCount: number;
345
+ leaked: boolean;
346
+ regions: FillRegionSummary[];
347
+ wet?: boolean;
348
+ }
349
+ export interface FindUnfilledRegionsOptions {
350
+ /** Target layer id from `listLayers` (when given, regions already painted on it are excluded). */
351
+ layerId?: string;
352
+ /**
353
+ * Which pixels define the line-art barriers:
354
+ * - `'all'` or `'composite'` (default): all visible layers composited (without paper).
355
+ * - `'layer'`: the target (or active) layer itself.
356
+ * - a layer id from `listLayers`: that layer (e.g. an ink line-art layer).
357
+ */
358
+ reference?: FillReference;
359
+ /** Alpha/colour threshold 0..255 above which a reference pixel is treated as line art (default 32). */
360
+ tolerance?: number;
361
+ /** Close small gaps in line art up to this width in pixels, 0..32 (default 0). */
362
+ closeGap?: number;
363
+ /** Ignore regions smaller than this many pixels (default 16). */
364
+ minArea?: number;
365
+ /** Include regions that touch the canvas border (default false: only enclosed shapes). */
366
+ includeEdge?: boolean;
367
+ /** Maximum number of regions to return, sorted largest first (default 100). */
368
+ maxRegions?: number;
369
+ }
300
370
  /** Pixels to add on each side of the canvas (whole numbers, 0 or more; missing = 0). */
301
371
  export interface PaintCanvasExtension {
302
372
  left?: number;
@@ -653,6 +723,22 @@ export declare class PaintEditorController {
653
723
  layerId: string;
654
724
  bounds: RasterRect;
655
725
  };
726
+ /**
727
+ * Flood-fills one or more contiguous regions on a pixel layer (one undo step), sampling boundaries
728
+ * from the layer itself (`reference: 'layer'`), all visible layers (`'all'` / `'composite'`), or a
729
+ * specific reference layer id (e.g. an ink line-art layer above a flats layer). Closes line-art gaps
730
+ * up to `closeGap` px and expands (`> 0`, bleeding under lines) or contracts (`< 0`) by `expand` px.
731
+ * With `wet: true`, pours a watercolour wash into the region on the layer's wet layer.
732
+ */
733
+ fillRegion(options: FillRegionOptions): FillRegionResult;
734
+ /**
735
+ * Finds enclosed unfilled regions from a reference layer or the visible composite (without paper),
736
+ * closing line-art gaps up to `closeGap` px and returning each region's interior seed `point`,
737
+ * `centroid`, `bounds`, `pixelCount`, and `touchesEdge` flag.
738
+ */
739
+ findUnfilledRegions(options?: FindUnfilledRegionsOptions): {
740
+ regions: UnfilledRegion[];
741
+ };
656
742
  private applyCoverage;
657
743
  /** The registered effects provider, or `null`. */
658
744
  get effectsProvider(): EffectProvider | null;
@@ -69,7 +69,7 @@ export interface PaintDocumentState {
69
69
  /** A change a replay repeats besides strokes, recorded with how many strokes came before it. */
70
70
  export interface PaintEvent {
71
71
  at: number;
72
- kind: 'fill' | 'clear' | 'flatten' | 'stickers' | 'live-strokes';
72
+ kind: 'fill' | 'fill-region' | 'clear' | 'flatten' | 'stickers' | 'live-strokes';
73
73
  layerId: string;
74
74
  /** The fill's options (colour, opacity, grain, pressure, blend), or the layer's stickers or live strokes after an edit. */
75
75
  data?: Record<string, unknown>;
@@ -69,7 +69,7 @@ export interface PaintDocumentState {
69
69
  /** A change a replay repeats besides strokes, recorded with how many strokes came before it. */
70
70
  export interface PaintEvent {
71
71
  at: number;
72
- kind: 'fill' | 'clear' | 'flatten' | 'stickers' | 'live-strokes';
72
+ kind: 'fill' | 'fill-region' | 'clear' | 'flatten' | 'stickers' | 'live-strokes';
73
73
  layerId: string;
74
74
  /** The fill's options (colour, opacity, grain, pressure, blend), or the layer's stickers or live strokes after an edit. */
75
75
  data?: Record<string, unknown>;