@overtone-art/canvas-editor-core 0.3.0 → 0.3.2

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/index.d.mts CHANGED
@@ -47,6 +47,18 @@ declare class LayerManager {
47
47
  setLocked(id: string, locked: boolean): void;
48
48
  setOpacity(id: string, opacity: number): void;
49
49
  setName(id: string, name: string): void;
50
+ /**
51
+ * Patch a layer's host metadata. A key whose value is `undefined` is removed.
52
+ *
53
+ * `meta` is part of `LayerData` and is serialized, so a host that assigns
54
+ * `layer.meta.x` directly gets neither of the two things every other setter
55
+ * here provides: `layers:changed` (so `useLayers()` keeps returning the old
56
+ * meta) and the history checkpoint (so an undo silently reverts the write —
57
+ * the state IS versioned, it was just never committed at the moment it
58
+ * changed). Going through this method is what makes metadata behave like
59
+ * every other layer property.
60
+ */
61
+ setMeta(id: string, patch: LayerMeta): void;
50
62
  clear(): void;
51
63
  count(): number;
52
64
  private emitChanged;
@@ -347,6 +359,47 @@ declare function renderTextureMask(id: TextureMaskId): HTMLCanvasElement;
347
359
  /** Drop memoized textures — used by tests and by long-lived editors on dispose. */
348
360
  declare function clearTextureMaskCache(): void;
349
361
 
362
+ /**
363
+ * Look of the selection frame and its resize handles.
364
+ *
365
+ * Every measurement is in **screen** pixels. Zoom is a display transform (the
366
+ * view layer CSS-scales the canvas element), so a handle drawn at its nominal
367
+ * size would grow and shrink with the zoom level; `applySelectionStyle`
368
+ * counter-scales by 1/zoom so the frame stays the same size on screen whatever
369
+ * the zoom.
370
+ */
371
+ interface SelectionStyle {
372
+ /** Colour of the frame around the selection. */
373
+ borderColor: string;
374
+ /** Fill of the resize handles. */
375
+ cornerColor: string;
376
+ /** Outline drawn around each handle. */
377
+ cornerStrokeColor: string;
378
+ /** Handle diameter, in screen pixels. */
379
+ cornerSize: number;
380
+ /** Round handles (as in the design tools) or square ones. */
381
+ cornerStyle: 'circle' | 'rect';
382
+ /** Frame line width, in screen pixels. */
383
+ borderWidth: number;
384
+ /** Dash pattern for the frame, in screen pixels. Null = solid. */
385
+ borderDashArray: number[] | null;
386
+ /** Gap between the object bounds and the frame, in screen pixels. */
387
+ padding: number;
388
+ /** Fill of the drag-to-select marquee. */
389
+ marqueeFill: string;
390
+ }
391
+ declare const DEFAULT_SELECTION_STYLE: SelectionStyle;
392
+ /** Applies the style to ONE object at the given display zoom. */
393
+ declare function applyObjectSelectionStyle(object: FabricObject, style: SelectionStyle, zoom: number): void;
394
+ /**
395
+ * Applies the style to every object on the canvas plus the active selection.
396
+ *
397
+ * The active selection is a transient group that `getObjects()` does not list,
398
+ * so it is styled separately — otherwise a multi-object selection would keep
399
+ * fabric's default blue squares.
400
+ */
401
+ declare function applySelectionStyle(canvas: Canvas, style: SelectionStyle, zoom: number): void;
402
+
350
403
  declare class UnitConverter {
351
404
  private unit;
352
405
  private dpi;
@@ -508,6 +561,7 @@ declare class CanvasEditor {
508
561
  private fileAdapter?;
509
562
  private imageProvider?;
510
563
  private zoomLevel;
564
+ private selectionStyle;
511
565
  private mockup;
512
566
  private designBackground;
513
567
  private designBackgroundImage;
@@ -630,6 +684,14 @@ declare class CanvasEditor {
630
684
  clearMockup(): void;
631
685
  getMockup(): MockupConfig | null;
632
686
  dispose(): void;
687
+ /** Current look of the selection frame and its handles. */
688
+ getSelectionStyle(): SelectionStyle;
689
+ /**
690
+ * Restyles the selection frame and resize handles. Sizes are in screen
691
+ * pixels and stay constant across zoom levels (see `SelectionStyle`).
692
+ */
693
+ setSelectionStyle(style: Partial<SelectionStyle>): void;
694
+ private refreshSelectionStyle;
633
695
  private setupCanvasEvents;
634
696
  }
635
697
 
@@ -758,4 +820,4 @@ declare class AnnotationOverlay {
758
820
  */
759
821
  declare function displaceRgba(source: Uint8ClampedArray, map: Uint8ClampedArray, width: number, height: number, options: Omit<MockupDisplacement, 'image'>): Uint8ClampedArray;
760
822
 
761
- export { AnnotationOverlay, type AnnotationPrimitive, BackgroundImageOptions, CANVAS_SIZE_PRESETS, CanvasEditor, CanvasSizePreset, type CoverPlacement, CropController, DEFAULT_LAYER_SHADOW, DEFAULT_TEXT_CURVE, DpiIssue, EditorConfig, EditorEvents, EditorState, EventEmitter, FileAdapter, FontDefinition, FontRegistry, HistoryManager, ImageAdjustments, ImageProvider, ImageProviderResult, ImageSearchOptions, ImageSearchResult, Layer, LayerData, LayerManager, LayerMeta, LayerShadowConfig, LayerType, LicenseConfig, LicenseManager, LicenseStatus, MaskBrushOptions, MaskController, type MaskPerformanceSample, MaskPoint, MaskPresetId, MaskPresetManager, MaskRefinementError, type MaskRefinementErrorCode, MaskRefinementPrompt, MaskRefinementProvider, MaskRefinementResult, MockupConfig, MockupDisplacement, MockupPrintArea, NormalizedLayerPosition, PatternConfig, PatternLocks, PatternManager, PatternSourceResolver, type PngExportOptions, PositioningAdapter, PrintifyPositioning, ProjectManager, ProjectState, ResizeOptions, SHAPE_MASK_BOX, SHAPE_MASK_IDS, SemanticExportOptions, SerializedBackgroundImageOptions, SerializedLayer, ShapeMaskPresetId, ShapePlugin, SnapManager, SvgExportOptions, TEXTURE_MASK_IDS, TEXTURE_MASK_SIZE, TemplateDefinition, TextCurveConfig, TextCurveManager, TextureMaskPresetId, type TilePlacement, Unit, UnitConverter, type ViewportTransform, applyAspectLock, applyLayerShadow, applyPatternLocks, buildCurvePathData, buildPatternDataURL, captureLocks, clamp, clearPatternImageCache, clearTextureMaskCache, computeCoverPlacement, computePrintAreaClip, computeTilePositions, deserializeEditor, displaceRgba, drawTiles, escapeXml, exportDataURL, exportMockup, exportPNG, exportPrintArea, exportSVG, generateId, isCssColor, isMaskPresetId, isShapeMaskId, isTextureMaskId, loadPatternImage, readLayerShadow, renderTextureMask, resetTransform, restoreLocks, round2, sanitizeSvg, serializeEditor, shapeMaskPathData };
823
+ export { AnnotationOverlay, type AnnotationPrimitive, BackgroundImageOptions, CANVAS_SIZE_PRESETS, CanvasEditor, CanvasSizePreset, type CoverPlacement, CropController, DEFAULT_LAYER_SHADOW, DEFAULT_SELECTION_STYLE, DEFAULT_TEXT_CURVE, DpiIssue, EditorConfig, EditorEvents, EditorState, EventEmitter, FileAdapter, FontDefinition, FontRegistry, HistoryManager, ImageAdjustments, ImageProvider, ImageProviderResult, ImageSearchOptions, ImageSearchResult, Layer, LayerData, LayerManager, LayerMeta, LayerShadowConfig, LayerType, LicenseConfig, LicenseManager, LicenseStatus, MaskBrushOptions, MaskController, type MaskPerformanceSample, MaskPoint, MaskPresetId, MaskPresetManager, MaskRefinementError, type MaskRefinementErrorCode, MaskRefinementPrompt, MaskRefinementProvider, MaskRefinementResult, MockupConfig, MockupDisplacement, MockupPrintArea, NormalizedLayerPosition, PatternConfig, PatternLocks, PatternManager, PatternSourceResolver, type PngExportOptions, PositioningAdapter, PrintifyPositioning, ProjectManager, ProjectState, ResizeOptions, SHAPE_MASK_BOX, SHAPE_MASK_IDS, type SelectionStyle, SemanticExportOptions, SerializedBackgroundImageOptions, SerializedLayer, ShapeMaskPresetId, ShapePlugin, SnapManager, SvgExportOptions, TEXTURE_MASK_IDS, TEXTURE_MASK_SIZE, TemplateDefinition, TextCurveConfig, TextCurveManager, TextureMaskPresetId, type TilePlacement, Unit, UnitConverter, type ViewportTransform, applyAspectLock, applyLayerShadow, applyObjectSelectionStyle, applyPatternLocks, applySelectionStyle, buildCurvePathData, buildPatternDataURL, captureLocks, clamp, clearPatternImageCache, clearTextureMaskCache, computeCoverPlacement, computePrintAreaClip, computeTilePositions, deserializeEditor, displaceRgba, drawTiles, escapeXml, exportDataURL, exportMockup, exportPNG, exportPrintArea, exportSVG, generateId, isCssColor, isMaskPresetId, isShapeMaskId, isTextureMaskId, loadPatternImage, readLayerShadow, renderTextureMask, resetTransform, restoreLocks, round2, sanitizeSvg, serializeEditor, shapeMaskPathData };
package/dist/index.d.ts CHANGED
@@ -47,6 +47,18 @@ declare class LayerManager {
47
47
  setLocked(id: string, locked: boolean): void;
48
48
  setOpacity(id: string, opacity: number): void;
49
49
  setName(id: string, name: string): void;
50
+ /**
51
+ * Patch a layer's host metadata. A key whose value is `undefined` is removed.
52
+ *
53
+ * `meta` is part of `LayerData` and is serialized, so a host that assigns
54
+ * `layer.meta.x` directly gets neither of the two things every other setter
55
+ * here provides: `layers:changed` (so `useLayers()` keeps returning the old
56
+ * meta) and the history checkpoint (so an undo silently reverts the write —
57
+ * the state IS versioned, it was just never committed at the moment it
58
+ * changed). Going through this method is what makes metadata behave like
59
+ * every other layer property.
60
+ */
61
+ setMeta(id: string, patch: LayerMeta): void;
50
62
  clear(): void;
51
63
  count(): number;
52
64
  private emitChanged;
@@ -347,6 +359,47 @@ declare function renderTextureMask(id: TextureMaskId): HTMLCanvasElement;
347
359
  /** Drop memoized textures — used by tests and by long-lived editors on dispose. */
348
360
  declare function clearTextureMaskCache(): void;
349
361
 
362
+ /**
363
+ * Look of the selection frame and its resize handles.
364
+ *
365
+ * Every measurement is in **screen** pixels. Zoom is a display transform (the
366
+ * view layer CSS-scales the canvas element), so a handle drawn at its nominal
367
+ * size would grow and shrink with the zoom level; `applySelectionStyle`
368
+ * counter-scales by 1/zoom so the frame stays the same size on screen whatever
369
+ * the zoom.
370
+ */
371
+ interface SelectionStyle {
372
+ /** Colour of the frame around the selection. */
373
+ borderColor: string;
374
+ /** Fill of the resize handles. */
375
+ cornerColor: string;
376
+ /** Outline drawn around each handle. */
377
+ cornerStrokeColor: string;
378
+ /** Handle diameter, in screen pixels. */
379
+ cornerSize: number;
380
+ /** Round handles (as in the design tools) or square ones. */
381
+ cornerStyle: 'circle' | 'rect';
382
+ /** Frame line width, in screen pixels. */
383
+ borderWidth: number;
384
+ /** Dash pattern for the frame, in screen pixels. Null = solid. */
385
+ borderDashArray: number[] | null;
386
+ /** Gap between the object bounds and the frame, in screen pixels. */
387
+ padding: number;
388
+ /** Fill of the drag-to-select marquee. */
389
+ marqueeFill: string;
390
+ }
391
+ declare const DEFAULT_SELECTION_STYLE: SelectionStyle;
392
+ /** Applies the style to ONE object at the given display zoom. */
393
+ declare function applyObjectSelectionStyle(object: FabricObject, style: SelectionStyle, zoom: number): void;
394
+ /**
395
+ * Applies the style to every object on the canvas plus the active selection.
396
+ *
397
+ * The active selection is a transient group that `getObjects()` does not list,
398
+ * so it is styled separately — otherwise a multi-object selection would keep
399
+ * fabric's default blue squares.
400
+ */
401
+ declare function applySelectionStyle(canvas: Canvas, style: SelectionStyle, zoom: number): void;
402
+
350
403
  declare class UnitConverter {
351
404
  private unit;
352
405
  private dpi;
@@ -508,6 +561,7 @@ declare class CanvasEditor {
508
561
  private fileAdapter?;
509
562
  private imageProvider?;
510
563
  private zoomLevel;
564
+ private selectionStyle;
511
565
  private mockup;
512
566
  private designBackground;
513
567
  private designBackgroundImage;
@@ -630,6 +684,14 @@ declare class CanvasEditor {
630
684
  clearMockup(): void;
631
685
  getMockup(): MockupConfig | null;
632
686
  dispose(): void;
687
+ /** Current look of the selection frame and its handles. */
688
+ getSelectionStyle(): SelectionStyle;
689
+ /**
690
+ * Restyles the selection frame and resize handles. Sizes are in screen
691
+ * pixels and stay constant across zoom levels (see `SelectionStyle`).
692
+ */
693
+ setSelectionStyle(style: Partial<SelectionStyle>): void;
694
+ private refreshSelectionStyle;
633
695
  private setupCanvasEvents;
634
696
  }
635
697
 
@@ -758,4 +820,4 @@ declare class AnnotationOverlay {
758
820
  */
759
821
  declare function displaceRgba(source: Uint8ClampedArray, map: Uint8ClampedArray, width: number, height: number, options: Omit<MockupDisplacement, 'image'>): Uint8ClampedArray;
760
822
 
761
- export { AnnotationOverlay, type AnnotationPrimitive, BackgroundImageOptions, CANVAS_SIZE_PRESETS, CanvasEditor, CanvasSizePreset, type CoverPlacement, CropController, DEFAULT_LAYER_SHADOW, DEFAULT_TEXT_CURVE, DpiIssue, EditorConfig, EditorEvents, EditorState, EventEmitter, FileAdapter, FontDefinition, FontRegistry, HistoryManager, ImageAdjustments, ImageProvider, ImageProviderResult, ImageSearchOptions, ImageSearchResult, Layer, LayerData, LayerManager, LayerMeta, LayerShadowConfig, LayerType, LicenseConfig, LicenseManager, LicenseStatus, MaskBrushOptions, MaskController, type MaskPerformanceSample, MaskPoint, MaskPresetId, MaskPresetManager, MaskRefinementError, type MaskRefinementErrorCode, MaskRefinementPrompt, MaskRefinementProvider, MaskRefinementResult, MockupConfig, MockupDisplacement, MockupPrintArea, NormalizedLayerPosition, PatternConfig, PatternLocks, PatternManager, PatternSourceResolver, type PngExportOptions, PositioningAdapter, PrintifyPositioning, ProjectManager, ProjectState, ResizeOptions, SHAPE_MASK_BOX, SHAPE_MASK_IDS, SemanticExportOptions, SerializedBackgroundImageOptions, SerializedLayer, ShapeMaskPresetId, ShapePlugin, SnapManager, SvgExportOptions, TEXTURE_MASK_IDS, TEXTURE_MASK_SIZE, TemplateDefinition, TextCurveConfig, TextCurveManager, TextureMaskPresetId, type TilePlacement, Unit, UnitConverter, type ViewportTransform, applyAspectLock, applyLayerShadow, applyPatternLocks, buildCurvePathData, buildPatternDataURL, captureLocks, clamp, clearPatternImageCache, clearTextureMaskCache, computeCoverPlacement, computePrintAreaClip, computeTilePositions, deserializeEditor, displaceRgba, drawTiles, escapeXml, exportDataURL, exportMockup, exportPNG, exportPrintArea, exportSVG, generateId, isCssColor, isMaskPresetId, isShapeMaskId, isTextureMaskId, loadPatternImage, readLayerShadow, renderTextureMask, resetTransform, restoreLocks, round2, sanitizeSvg, serializeEditor, shapeMaskPathData };
823
+ export { AnnotationOverlay, type AnnotationPrimitive, BackgroundImageOptions, CANVAS_SIZE_PRESETS, CanvasEditor, CanvasSizePreset, type CoverPlacement, CropController, DEFAULT_LAYER_SHADOW, DEFAULT_SELECTION_STYLE, DEFAULT_TEXT_CURVE, DpiIssue, EditorConfig, EditorEvents, EditorState, EventEmitter, FileAdapter, FontDefinition, FontRegistry, HistoryManager, ImageAdjustments, ImageProvider, ImageProviderResult, ImageSearchOptions, ImageSearchResult, Layer, LayerData, LayerManager, LayerMeta, LayerShadowConfig, LayerType, LicenseConfig, LicenseManager, LicenseStatus, MaskBrushOptions, MaskController, type MaskPerformanceSample, MaskPoint, MaskPresetId, MaskPresetManager, MaskRefinementError, type MaskRefinementErrorCode, MaskRefinementPrompt, MaskRefinementProvider, MaskRefinementResult, MockupConfig, MockupDisplacement, MockupPrintArea, NormalizedLayerPosition, PatternConfig, PatternLocks, PatternManager, PatternSourceResolver, type PngExportOptions, PositioningAdapter, PrintifyPositioning, ProjectManager, ProjectState, ResizeOptions, SHAPE_MASK_BOX, SHAPE_MASK_IDS, type SelectionStyle, SemanticExportOptions, SerializedBackgroundImageOptions, SerializedLayer, ShapeMaskPresetId, ShapePlugin, SnapManager, SvgExportOptions, TEXTURE_MASK_IDS, TEXTURE_MASK_SIZE, TemplateDefinition, TextCurveConfig, TextCurveManager, TextureMaskPresetId, type TilePlacement, Unit, UnitConverter, type ViewportTransform, applyAspectLock, applyLayerShadow, applyObjectSelectionStyle, applyPatternLocks, applySelectionStyle, buildCurvePathData, buildPatternDataURL, captureLocks, clamp, clearPatternImageCache, clearTextureMaskCache, computeCoverPlacement, computePrintAreaClip, computeTilePositions, deserializeEditor, displaceRgba, drawTiles, escapeXml, exportDataURL, exportMockup, exportPNG, exportPrintArea, exportSVG, generateId, isCssColor, isMaskPresetId, isShapeMaskId, isTextureMaskId, loadPatternImage, readLayerShadow, renderTextureMask, resetTransform, restoreLocks, round2, sanitizeSvg, serializeEditor, shapeMaskPathData };