Class Group

Fires

object:added

Fires

object:removed

Fires

layout once layout completes

Hierarchy

Constructors

Properties

Accessors

Methods

__objectMonitor __objectSelectionMonitor __serializeObjects _adjustObjectPosition _animate _applyLayoutStrategy _applyPatternForTransformedGradient _applyPatternGradientTransform _calculateCurrentDimensions _constrainScale _createBaseClipPathSVGMarkup _createBaseSVGMarkup _createCacheCanvas _createSVGBgRect _drawBorders _drawClipPath _enterGroup _exitGroup _filterObjectsBeforeEnteringGroup _findCenterFromElement _findTargetCorner _getCacheCanvasDimensions _getLeftTopCoords _getNonTransformedDimensions _getTransformedDimensions _limitCacheSize _onAfterObjectsChange _onObjectAdded _onObjectRemoved _onRelativeObjectAdded _onStackOrderChanged _removeCacheCanvas _removeDefaultValues _removeShadow _render _renderBackground _renderControls _renderFill _renderPaintInOrder _renderStroke _set _setClippingProperties _setFillStyles _setLineDash _setObject _setOpacity _setOptions _setShadow _setStrokeStyles _setupCompositeOperation _shouldSetNestedCoords _toSVG _updateCacheCanvas _watchObject add addPaintOrder animate bringObjectForward bringObjectToFront calcACoords calcLineCoords calcOCoords calcOwnMatrix calcTransformMatrix canDrop canEnterGroup clearContextTop clone cloneAsImage collectObjects complexity contains containsPoint dispose drawBorders drawCacheOnCanvas drawClipPathOnCache drawControls drawControlsConnectingLines drawObject drawSelectionBackground enterGroup exitGroup findCommonAncestors findNewLowerIndex findNewUpperIndex fire forEachControl forEachObject get getActiveControl getAncestors getBoundingRect getCanvasRetinaScaling getCenterPoint getCoords getLayoutStrategyResult getObjectOpacity getObjectScaling getObjects getObjectsBoundingBox getParent getPointByOrigin getRelativeCenterPoint getRelativeX getRelativeXY getRelativeY getScaledHeight getScaledWidth getSvgCommons getSvgFilter getSvgStyles getSvgTransform getTotalAngle getTotalObjectScaling getViewportTransform getX getXY getY hasCommonAncestors hasFill hasStroke insertAt intersectsWithObject intersectsWithRect isCacheDirty isContainedWithinObject isContainedWithinRect isControlVisible isDescendantOf isEmpty isInFrontOf isNotVisible isOnACache isOnScreen isOverlapping isPartiallyOnScreen isType item moveObjectTo needsItsOwnCache off on onDeselect onLayout onSelect once prepareBoundingBox prepareInitialBoundingBox remove removeAll render renderCache renderDragSourceEffect renderDropTargetEffect rotate scale scaleToHeight scaleToWidth sendObjectBackwards sendObjectToBack set setControlVisible setControlsVisibility setCoords setOnGroup setOptions setPositionByOrigin setRelativeX setRelativeXY setRelativeY setX setXY setY shouldCache size strokeBorders toCanvasElement toClipPathSVG toDataURL toDatalessObject toJSON toObject toSVG toString toggle transform transformMatrixKey translateToCenterPoint translateToGivenOrigin translateToOriginPoint triggerLayout willDrawShadow _fromObject fromObject getDefaults

Constructors

Properties

__corner?: string

keeps the value of the last hovered corner during mouse move. 0 is no corner, or 'mt', 'ml', 'mtr' etc.. It should be private, but there is no harm in using it as a read-only property. this isn't cleaned automatically. Non selected objects may have wrong values

__objectSelectionDisposer: ((ev) => void)

Type declaration

__objectSelectionTracker: ((ev) => void)

Type declaration

__owningGroup?: Group

A reference to the parent of the object Used to keep the original parent ref when the object has been added to an ActiveSelection, hence loosing the group ref

Used internally to optimize performance Once an object is selected, instance is rendered without the selected object. This way instance is cached only once for the entire interaction with the selected object.

_cacheCanvas?: HTMLCanvasElement

A reference to the HTMLCanvasElement that is used to contain the cache of the object this canvas element is resized and cleared as needed Is marked private, you can read it, don't use it since it is handled by fabric since 1.7.0

Default

undefined
@private
_cacheContext: null | CanvasRenderingContext2D = null

Quick access for the _cacheCanvas rendering context This is part of the objectCaching feature since 1.7.0

Default

undefined
@private
_controlsVisibility: Record<string, boolean>

a map of control visibility for this object. this was left when controls were introduced to not break the api too much this takes priority over the generic control visibility

_firstLayoutDone: boolean = false

TODO

needs to end up in the constructor too

_scaling?: boolean

A boolean used from the gesture module to keep tracking of a scaling action when there is no scaling transform in place. This is an edge case and is used twice in all codebase. Probably added to keep track of some performance issues

TODO

use git blame to investigate why it was added DON'T USE IT. WE WILL TRY TO REMOVE IT

_transformDone?: boolean

Private. indicates if the object inside a group is on a transformed context or not or is part of a larger cache for many object ( a group for example)

Default

undefined
@private
aCoords: TCornerPoint

Describe object's corner position in canvas object absolute coordinates properties are tl,tr,bl,br and describe the four main corner. each property is an object with x, y, instance of Fabric.Point. The coordinates depends from this properties: width, height, scaleX, scaleY skewX, skewY, angle, strokeWidth, top, left. Those coordinates are useful to understand where an object is. They get updated with lineCoords or oCoords in interactive cases but they do not need to be updated when zoom or panning change. The coordinates get updated with

Method

setCoords. You can calculate them without updating with

Method

calcACoords();

absolutePositioned: boolean
activeOn: "down" | "up"
angle: TDegree
backgroundColor: string
borderColor: string
borderDashArray: null | number[]
borderOpacityWhenMoving: number
borderScaleFactor: number
cacheHeight?: number

Size of the cache canvas, height since 1.7.0

Default

undefined
@private
cacheTranslationX?: number

zoom level used on the cacheCanvas to draw the cache, Y axe since 1.7.0

Default

undefined
@private
cacheTranslationY?: number

translation of the cacheCanvas away from the center, for subpixel accuracy and crispness since 1.7.0

Default

undefined
@private
cacheWidth?: number

Size of the cache canvas, width since 1.7.0

Default

undefined
@private
canvas?: Canvas
centeredRotation: boolean
centeredScaling: boolean
clipPath?: FabricObject<Partial<ObjectProps>, SerializedObjectProps, ObjectEvents>
clipPathId?: string

When an object is being exported as SVG as a clippath, a reference inside the SVG is needed. This reference is a UID in the fabric namespace and is temporary stored here.

colorProperties: string[]

List of properties to consider for animating colors.

controls: TControlSet

holds the controls for the object. controls are added by default_controls.js

cornerColor: string
cornerDashArray: null | number[]
cornerSize: number
cornerStrokeColor: string
cornerStyle: "circle" | "rect"
dirty: boolean

When set to true, object's cache will be rerendered next render call. since 1.7.0

Default

true
evented: boolean
excludeFromExport: boolean
fill: null | string | TFiller
fillRule: CanvasFillRule
flipX: boolean
flipY: boolean
globalCompositeOperation: GlobalCompositeOperation
group?: Group

A reference to the parent of the object, usually a Group

Default

undefined
@private
hasBorders: boolean
hasControls: boolean
height: number
hoverCursor: null | string
includeDefaultValues: boolean
interactive: boolean

Used to allow targeting of object inside groups. set to true if you want to select an object inside a group.
REQUIRES subTargetCheck set to true

Default


inverted: boolean
isMoving?: boolean

internal boolean to signal the code that the object is part of the move action.

Specifies the layout strategy for instance Used by getLayoutStrategyResult to calculate layout fit-content, fit-content-lazy, fixed, clip-path are supported out of the box

Default


left: number
lineCoords: TCornerPoint

Describe object's corner position in canvas element coordinates. includes padding. Used of object detection. set and refreshed with setCoords. Those could go away

Todo

investigate how to get rid of those

lockMovementX: boolean
lockMovementY: boolean
lockRotation: boolean
lockScalingFlip: boolean
lockScalingX: boolean
lockScalingY: boolean
lockSkewingX: boolean
lockSkewingY: boolean
matrixCache?: TMatrixCache

storage cache for object full transform matrix

minScaleLimit: number
moveCursor: null | string
noScaleCache: boolean
oCoords: Record<string, TOCoord>

Describe object's corner position in canvas element coordinates. properties are depending on control keys and padding the main controls. each property is an object with x, y and corner. The corner property contains in a similar manner the 4 points of the interactive area of the corner. The coordinates depends from the controls positionHandler and are used to draw and locate controls

objectCaching: boolean
opacity: number
originX: TOriginX
originY: TOriginY
ownCaching?: boolean

Indicate if the object is sitting on a cache dedicated to it or is part of a larger cache for many object ( a group for example)

Default

undefined
@private
ownMatrixCache?: TMatrixCache

storage cache for object transform matrix

padding: number
paintFirst: "fill" | "stroke"
perPixelTargetFind: boolean
scaleX: number
scaleY: number
selectable: boolean
selectionBackgroundColor: string
shadow: null | Shadow
skewX: number
skewY: number
snapAngle?: TDegree
snapThreshold?: TDegree
stroke: null | string | TFiller
strokeDashArray: null | number[]
strokeDashOffset: number
strokeLineCap: CanvasLineCap
strokeLineJoin: CanvasLineJoin
strokeMiterLimit: number
strokeUniform: boolean
strokeWidth: number
subTargetCheck: boolean

Used to optimize performance set to false if you don't need contained objects to be targets of events

Default


top: number
touchCornerSize: number
transparentCorners: boolean
visible: boolean
width: number
zoomX?: number

zoom level used on the cacheCanvas to draw the cache, X axe since 1.7.0

Default

undefined
@private
zoomY?: number

zoom level used on the cacheCanvas to draw the cache, Y axe since 1.7.0

Default

undefined
@private
cacheProperties: string[] = cacheProperties

List of properties to consider when checking if cache needs refresh Those properties are checked by calls to Object.set(key, value). If the key is in this list, the object is marked as dirty and refreshed at the next render

ownDefaults: Record<string, any> = groupDefaultValues
stateProperties: string[] = ...
type: string = 'Group'

Accessors

  • get type(): string
  • Legacy identifier of the class. Prefer using utils like isType or instanceOf Will be removed in fabric 7 or 8. The setter exists because is very hard to catch all the ways in which a type value could be set in the instance

    Returns string

    TODO

    add sustainable warning message

    Deprecated

  • set type(value): void
  • Parameters

    • value: string

    Returns void

Methods

  • Private

    keeps track of the selected objects

    Type Parameters

    • T extends boolean

    Parameters

    • selected: T
    • __namedParameters: ObjectEvents[T extends true
          ? "selected"
          : "deselected"]

    Returns void

  • Private

    Parameters

    • Optional method: "toObject" | "toDatalessObject"
    • Optional propertiesToInclude: string[]

      Any properties that you might want to additionally include in the output

    Returns any[]

    serialized objects

  • Private

    initial layout logic: calculate bbox of objects (if necessary) and translate it according to options received from the constructor (left, top, width, height) so it is placed in the center of the bbox received from the constructor

    Parameters

    Returns void

  • Private

    This function try to patch the missing gradientTransform on canvas gradients. transforming a context to transform the gradient, is going to transform the stroke too. we want to transform the gradient but not the stroke operation, so we create a transformed gradient on a pattern and then we use the pattern instead of the gradient. this method has drawbacks: is slow, is in low resolution, needs a patch for when the size is limited.

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    • filler: TFiller

    Returns void

  • Private

    Parameters

    Returns {
        offsetX: number;
        offsetY: number;
    }

    • offsetX: number
    • offsetY: number
  • Private

    Calculate object dimensions for controls box, including padding and canvas zoom. and active selection

    Parameters

    • Optional options: any

      transform options

    Returns Point

    dimensions

  • Private

    Makes sure the scale is valid and modifies it if necessary @todo: this is a control action issue, not a geometry one

    Parameters

    • value: number

    Returns number

    constrained value;

  • Private

    Parameters

    • this: FabricObjectSVGExportMixin & FabricObject<Partial<FabricObjectProps>, SerializedObjectProps, ObjectEvents>
    • objectMarkup: string[]
    • __namedParameters: {
          additionalTransform?: string;
          noStyle?: boolean;
          reviver?: TSVGReviver;
          withShadow?: boolean;
      } = {}
      • Optional additionalTransform?: string
      • Optional noStyle?: boolean
      • Optional reviver?: TSVGReviver
      • Optional withShadow?: boolean

    Returns string

  • Private

    Create a the canvas used to keep the cached copy of the object

    Returns void

  • Private

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to draw on

    • size: Point
    • styleOverride: TStyleOverride = {}

      object to override the object style

    Returns void

  • Prepare clipPath state and cache and draw it on instance's cache

    Parameters

    Returns void

  • Private

    This function is an helper for svg import. it returns the center of the object in the svg untransformed coordinates

    Returns Point

    center point from element coordinates

  • Private

    Determines which corner is under the mouse cursor, represented by pointer. This function is return a corner only if the object is the active one. This is done to avoid selecting corner of non active object and activating transformations rather than drag action. The default behavior of fabricJS is that if you want to transform an object, first you select it to show the control set

    Parameters

    • pointer: Point

      The pointer indicating the mouse position

    • forTouch: boolean = false

      indicates if we are looking for interaction area with a touch action

    Returns string

    corner code (tl, tr, bl, br, etc.), or 0 if nothing is found.

  • Private

    Return the dimension and the zoom level needed to create a cache canvas big enough to host the object to be cached.

    Returns TCacheCanvasDimensions

    .x width of object to be cached

  • Private

    Calculate object dimensions from its properties

    Returns Point

    dimensions

  • Private

    Calculate object bounding box dimensions from its properties scale, skew.

    Parameters

    • Optional options: any = {}

    Returns Point

    dimensions

  • Limit the cache dimensions so that X * Y do not cross config.perfLimitSizeTotal and each side do not cross fabric.cacheSideLimit those numbers are configurable so that you can get as much detail as you want making bargain with performances.

    Parameters

    • dims: any

    Returns any

    .width width of canvas

  • Private

    Parameters

    Returns void

  • Returns void

  • Remove cacheCanvas and its dimensions from the objects

    Returns void

  • Private

    Type Parameters

    • T extends object

    Parameters

    • object: T

    Returns Partial<T>

  • Private

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    Returns void

  • Private

    function that actually render something on the context. empty here to allow Obects to work on tests to benchmark fabric functionalites not related to rendering

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    Returns void

  • Private

    Draws a background for the object big as its untransformed dimensions

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    Returns void

  • Renders controls and borders for the object the context here is not transformed

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    • Optional styleOverride: TStyleOverride = {}

      properties to override the object style

    Returns void

    Todo

    move to interactivity

  • Private

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    Returns void

  • Private

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    Returns void

  • Private

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    Returns void

  • Private

    Parameters

    • key: string
    • value: any

    Returns Group

  • Parameters

    • ctx: CanvasRenderingContext2D

    Returns void

  • Parameters

    • ctx: CanvasRenderingContext2D
    • __namedParameters: Pick<Group, "fill">

    Returns void

  • Private

    Sets line dash

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to set the dash line on

    • Optional dashArray: null | number[]

      array representing dashes

    Returns void

  • Private

    Parameters

    • obj: Record<string, any>

    Returns void

  • Private

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    Returns void

  • Protected

    Sets object's properties from options, for initialization only

    Parameters

    • Optional options: any = {}

      Options object

    Returns void

  • Private

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    Returns void

  • Parameters

    • ctx: CanvasRenderingContext2D
    • decl: Pick<Group, "strokeDashOffset" | "strokeLineCap" | "strokeLineJoin" | "strokeMiterLimit" | "strokeWidth" | "stroke">

    Returns void

  • Sets canvas globalCompositeOperation for specific object custom composition operation for the particular object can be specified using globalCompositeOperation property

    Parameters

    • ctx: CanvasRenderingContext2D

      Rendering canvas context

    Returns void

  • Returns svg representation of an instance

    Parameters

    • Optional reviver: TSVGReviver

      Method for further parsing of svg representation.

    Returns string[]

    svg representation of an instance

  • Private

    Update width and height of the canvas for cache returns true or false if canvas needed resize.

    Returns boolean

    true if the canvas has been resized

  • Animates object's properties

    Type Parameters

    Parameters

    • animatable: Record<string, T>

      map of keys and end values

    • Optional options: Partial<AnimationOptions<T>>

    Returns Record<string, TAnimation<T>>

    map of animation contexts

    As object — multiple properties

    object.animate({ left: ..., top: ... }); object.animate({ left: ..., top: ... }, { duration: ... });

  • Moves an object or a selection up in stack of drawn objects An optional parameter, intersecting allows to move the object in front of the first intersecting object. Where intersection is calculated with bounding box. If no intersection is found, there will not be change in the stack.

    Parameters

    Returns boolean

    true if change occurred

  • Moves an object or the objects of a multiple selection to the top of the stack of drawn objects

    Parameters

    Returns boolean

    true if change occurred

  • Calculates the coordinates of the 4 corner of the bbox, in absolute coordinates. those never change with zoom or viewport changes.

    Returns TCornerPoint

  • return the coordinate of the 4 corners of the bounding box in HTMLCanvasElement coordinates used for bounding box interactivity with the mouse

    Returns TCornerPoint

  • Calculates the coordinates of the center of each control plus the corners of the control itself This basically just delegates to each control positionHandler WARNING: changing what is passed to positionHandler is a breaking change, since position handler is a public api and should be done just if extremely necessary

    Returns Record<string, TOCoord>

  • calculate transform matrix that represents the current transformations from the object's properties, this matrix does not include the group transformation

    Returns TMat2D

    transform matrix for the object

  • calculate transform matrix that represents the current transformations from the object's properties.

    Parameters

    • Optional skipGroup: boolean = false

      return transform matrix for object not counting parent transformations There are some situation in which this is useful to avoid the fake rotation.

    Returns TMat2D

    transform matrix for the object

  • Override to customize drag and drop behavior return true if the object currently dragged can be dropped on the target

    Parameters

    • e: DragEvent

    Returns boolean

  • Clears the canvas.contextTop in a specific area that corresponds to the object's bounding box that is in the canvas.contextContainer. This function is used to clear pieces of contextTop where we render ephemeral effects on top of the object. Example: blinking cursor text selection, drag effects.

    Parameters

    • Optional restoreManually: boolean

      When true won't restore the context after clear, in order to draw something else.

    Returns undefined | CanvasRenderingContext2D

    canvas.contextTop that is either still transformed with the object transformMatrix, or restored to neutral transform

    Todo

    discuss swapping restoreManually with a renderCallback, but think of async issues

  • Clones an instance.

    Parameters

    • Optional propertiesToInclude: string[]

      Any properties that you might want to additionally include in the output

    Returns Promise<Group>

  • Creates an instance of Image out of an object makes use of toCanvasElement. Once this method was based on toDataUrl and loadImage, so it also had a quality and format option. toCanvasElement is faster and produce no loss of quality. If you need to get a real Jpeg or Png from an object, using toDataURL is the right way to do it. toCanvasElement and then toBlob from the obtained canvas is also a good option.

    Parameters

    • Optional options: any

      for clone as image, passed to toDataURL

    Returns FabricImage<Partial<ImageProps>, SerializedImageProps, ObjectEvents>

    Object cloned as image.

    Todo

    fix the export type, it could not be Image but the type that getClass return for 'image'.

  • Given a bounding box, return all the objects of the collection that are contained in the bounding box. If includeIntersecting is true, return also the objects that intersect the bounding box as well. This is meant to work with selection. Is not a generic method.

    Parameters

    • __namedParameters: TBBox
    • __namedParameters: {
          includeIntersecting?: boolean;
      } = {}
      • Optional includeIntersecting?: boolean

    Returns InteractiveFabricObject<Partial<FabricObjectProps>, SerializedObjectProps, ObjectEvents>[]

    array of objects contained in the bounding box, ordered from top to bottom stacking wise

  • Returns number representation of a collection complexity

    Returns number

    complexity

  • Returns true if collection contains an object.
    Prefer using FabricObject#isDescendantOf for performance reasons instead of a.contains(b) use b.isDescendantOf(a)

    Parameters

    Returns boolean

    true if collection contains an object

  • Checks if point is inside the object

    Parameters

    • point: Point

      Point to check against

    • Optional absolute: boolean = false

      use coordinates without viewportTransform

    • Optional calculate: boolean = false

      use coordinates of current position instead of stored ones

    Returns boolean

    true if point is inside the object

  • Returns void

  • Draws borders of an object's bounding box. Requires public properties: width, height Requires public options: padding, borderColor

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to draw on

    • options: Required<Omit<TComposeMatrixArgs, "flipX" | "flipY">>

      object representing current object parameters

    • Optional styleOverride: TStyleOverride

      object to override the object style

    Returns void

  • Paint the cached copy of the object on the target context.

    Parameters

    Returns void

  • Execute the drawing operation for an object clipPath

    Parameters

    Returns void

  • Draws corners of an object's bounding box. Requires public properties: width, height Requires public options: cornerSize, padding

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to draw on

    • styleOverride: Partial<Pick<InteractiveFabricObject<Partial<FabricObjectProps>, SerializedObjectProps, ObjectEvents>, "cornerStyle" | "cornerSize" | "cornerColor" | "cornerStrokeColor" | "cornerDashArray" | "transparentCorners">> = {}

      object to override the object style

    Returns void

  • Draws lines from a borders of an object's bounding box to controls that have withConnection property set. Requires public properties: width, height Requires public options: padding, borderColor

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to draw on

    • size: Point

      object size x = width, y = height

    Returns void

  • Execute the drawing operation for an object on a specified context

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to render on

    Returns void

  • Draws a colored layer behind the object, inside its selection borders. Requires public options: padding, selectionBackgroundColor this function is called when the context is transformed has checks to be skipped when the object is on a staticCanvas

    Parameters

    • ctx: CanvasRenderingContext2D

      Context to draw on

    Returns void

    Todo

    evaluate if make this disappear in favor of a pre-render hook for objects this was added by Andrea Bogazzi to make possible some feature for work reasons it seemed a good option, now is an edge case

  • Compare ancestors

    Type Parameters

    • T extends Group<T>

    • S extends boolean

    Parameters

    • other: T
    • Optional strict: S

      finds only ancestors that are objects (without canvas)

    Returns AncestryComparison<S>

    an object that represent the ancestry situation.

  • Fires event with an optional options object

    Type Parameters

    Parameters

    • eventName: K

      Event name to fire

    • Optional options: GroupEvents[K]

      Options object

    Returns void

  • Calls a function for each control. The function gets called, with the control, the control's key and the object that is calling the iterator

    Parameters

    Returns void

  • Executes given function for each object in this group A simple shortcut for getObjects().forEach, before es6 was more complicated, now is just a shortcut.

    Parameters

    Returns void

  • Basic getter

    Parameters

    • property: string

      Property name

    Returns any

    value of a property

  • Returns undefined | string

  • Type Parameters

    • T extends boolean

    Parameters

    • Optional strict: T

      returns only ancestors that are objects (without canvas)

    Returns Ancestors<T>

    ancestors (excluding ActiveSelection) from bottom to top

  • Returns coordinates of object's bounding rectangle (left, top, width, height) the box is intended as aligned to axis of canvas.

    Parameters

    • Optional absolute: boolean

      use coordinates without viewportTransform

    • Optional calculate: boolean

      use coordinates of current position instead of .lineCoords / .aCoords

    Returns TBBox

    Object with left, top, width, height properties

  • Returns number

  • Returns the center coordinates of the object relative to canvas

    Returns Point

  • return correct set of coordinates for intersection this will return either aCoords or lineCoords. The coords are returned in an array.

    Parameters

    • absolute: boolean = false

      will return aCoords if true or lineCoords

    • calculate: boolean = false

      will return aCoords if true or lineCoords

    Returns Point[]

    [tl, tr, br, bl] of points

  • Return the object opacity counting also the group property

    Returns number

  • Return the object scale factor counting also the group scaling

    Returns Point

  • Returns instance's parent EXCLUDING ActiveSelection

    Type Parameters

    • T extends boolean

    Parameters

    • Optional strict: T

      exclude canvas as well

    Returns undefined | TAncestor

  • Returns the coordinates of the object as if it has a different origin

    Parameters

    • originX: TOriginX

      Horizontal origin: 'left', 'center' or 'right'

    • originY: TOriginY

      Vertical origin: 'top', 'center' or 'bottom'

    Returns Point

  • Returns the center coordinates of the object relative to it's parent

    Returns Point

  • Returns number

    x position according to object's originX property in parent's coordinate plane
    if parent is canvas then this property is identical to getX

  • Returns number

    y position according to object's originY property in parent's coordinate plane
    if parent is canvas then this property is identical to getY

  • Returns height of an object bounding box counting transformations

    Returns number

    height value

    Todo

    shouldn't this account for group transform and return the actual size in canvas coordinate plane?

  • Returns width of an object's bounding box counting transformations

    Returns number

    width value

    Todo

    shouldn't this account for group transform and return the actual size in canvas coordinate plane?

  • Returns styles-string for svg-export, specific version for group

    Returns string

  • Returns the object angle relative to canvas counting also the group property

    Returns TDegree

  • Return the object scale factor counting also the group scaling, zoom and retina

    Returns Point

    object with scaleX and scaleY properties

  • Retrieves viewportTransform from Object's canvas if possible

    Returns TMat2D

    Method

    getViewportTransform

    Member Of

    FabricObject.prototype

  • Returns number

    x position according to object's originX property in canvas coordinate plane

  • Returns number

    y position according to object's originY property in canvas coordinate plane

  • Type Parameters

    Parameters

    • other: T
    • Optional strict: boolean

      checks only ancestors that are objects (without canvas)

    Returns boolean

  • return true if the object will draw a fill Does not consider text styles. This is just a shortcut used at rendering time We want it to be an approximation and be fast. wrote to avoid extra caching, it has to return true when fill happens, can guess when it will not happen at 100% chance, does not matter if it misses some use case where the fill is invisible.

    Returns null | boolean | ""

    Boolean

    Since

    3.0.0

  • return true if the object will draw a stroke Does not consider text styles. This is just a shortcut used at rendering time We want it to be an approximation and be fast. wrote to avoid extra caching, it has to return true when stroke happens, can guess when it will not happen at 100% chance, does not matter if it misses some use case where the stroke is invisible.

    Returns null | boolean | ""

    Boolean

    Since

    3.0.0

  • Checks if object intersects with another object

    Parameters

    • other: ObjectGeometry<ObjectEvents>

      Object to test

    • Optional absolute: boolean = false

      use coordinates without viewportTransform

    • Optional calculate: boolean = false

      use coordinates of current position instead of calculating them

    Returns boolean

    true if object intersects with another object

  • Checks if object intersects with an area formed by 2 points

    Parameters

    • pointTL: Point

      top-left point of area

    • pointBR: Point

      bottom-right point of area

    • Optional absolute: boolean

      use coordinates without viewportTransform

    • Optional calculate: boolean

      use coordinates of current position instead of stored one

    Returns boolean

    true if object intersects with an area formed by 2 points

  • Check if cache is dirty

    Parameters

    • skipCanvas: boolean = false

      skip canvas checks because this object is painted on parent canvas.

    Returns boolean

  • Checks if object is fully contained within area of another object

    Parameters

    • other: ObjectGeometry<ObjectEvents>

      Object to test

    • Optional absolute: boolean = false

      use coordinates without viewportTransform

    • Optional calculate: boolean = false

      use coordinates of current position instead of stored ones

    Returns boolean

    true if object is fully contained within area of another object

  • Checks if object is fully contained within area formed by 2 points

    Parameters

    • pointTL: Point

      top-left point of area

    • pointBR: Point

      bottom-right point of area

    • Optional absolute: boolean

      use coordinates without viewportTransform

    • Optional calculate: boolean

      use coordinates of current position instead of stored one

    Returns boolean

    true if object is fully contained within area formed by 2 points

  • Returns true if the specified control is visible, false otherwise.

    Parameters

    • controlKey: string

      The key of the control. Possible values are usually 'tl', 'tr', 'br', 'bl', 'ml', 'mt', 'mr', 'mb', 'mtr', but since the control api allow for any control name, can be any string.

    Returns boolean

    true if the specified control is visible, false otherwise

  • Checks if object is descendant of target Should be used instead of Group.contains or StaticCanvas.contains for performance reasons

    Parameters

    • target: TAncestor

    Returns boolean

  • Returns true if collection contains no objects

    Returns boolean

    true if collection is empty

  • Type Parameters

    Parameters

    • other: T

      object to compare against

    Returns undefined | boolean

    if objects do not share a common ancestor or they are strictly equal it is impossible to determine which is in front of the other; in such cases the function returns undefined

  • Returns boolean

  • Check if instance or its group are caching, recursively up

    Returns boolean

  • Checks if object is contained within the canvas with current viewportTransform the check is done stopping at first point that appears on screen

    Parameters

    • Optional calculate: boolean = false

      use coordinates of current position instead of .aCoords

    Returns boolean

    true if object is fully or partially contained within canvas

  • Type Parameters

    Parameters

    • other: T

    Returns boolean

  • Checks if object is partially contained within the canvas with current viewportTransform

    Parameters

    • Optional calculate: boolean

      use coordinates of current position instead of stored ones

    Returns boolean

    true if object is partially contained within canvas

  • Returns true if any of the specified types is identical to the type of an instance

    Parameters

    • Rest ...types: string[]

    Returns boolean

  • Moves an object to specified level in stack of drawn objects

    Parameters

    Returns boolean

    true if change occurred

  • When set to true, force the object to have its own cache, even if it is inside a group it may be needed when your object behave in a particular way on the cache and always needs its own isolated canvas to render correctly. Created to be overridden since 1.7.12

    Returns boolean

    Boolean

  • unsubscribe an event listener

    Type Parameters

    Parameters

    • eventName: K

      event name (eg. 'after:render')

    • handler: TEventCallback<any>

      event listener to unsubscribe

    Returns void

  • unsubscribe event listeners

    Parameters

    • handlers: EventRegistryObject<GroupEvents>

      handlers key/value pairs (eg. {'after:render': handler, 'selection:cleared': handler})

    Returns void

  • unsubscribe all event listeners

    Returns void

  • This callback function is called every time _discardActiveObject or _setActiveObject try to to deselect this object. If the function returns true, the process is cancelled

    Parameters

    Returns boolean

  • Hook that is called once layout has completed. Provided for layout customization, override if necessary. Complements getLayoutStrategyResult, which is called at the beginning of layout.

    Parameters

    Returns void

  • This callback function is called every time _discardActiveObject or _setActiveObject try to to select this object. If the function returns true, the process is cancelled

    Parameters

    • Optional options: {
          e?: TPointerEvent;
      }

      options sent from the upper functions

      • Optional e?: TPointerEvent

        event if the process is generated by an event

    Returns boolean

  • Calculates center taking into account originX, originY while not being sure that width/height are initialized

    Type Parameters

    Parameters

    Returns undefined | {
        centerX: number;
        centerY: number;
        correctionX: number;
        correctionY: number;
        height: number;
        width: number;
    }

  • Renders instance on a given context

    Parameters

    • ctx: CanvasRenderingContext2D

      context to render instance on

    Returns void

  • Parameters

    • Optional options: any

    Returns void

  • Override to customize drag and drop behavior render a specific effect when an object is the source of a drag event example: render the selection status for the part of text that is being dragged from a text object

    Parameters

    • e: DragEvent

    Returns void

  • Override to customize drag and drop behavior render a specific effect when an object is the target of a drag event used to show that the underly object can receive a drop, or to show how the object will change when dropping. example: show the cursor where the text is about to be dropped

    Parameters

    • e: DragEvent

    Returns void

  • Sets "angle" of an instance with centered rotation

    Parameters

    • angle: TDegree

      Angle value (in degrees)

    Returns void

  • Scales an object (equally by x and y)

    Parameters

    • value: number

      Scale factor

    Returns void

  • Scales an object to a given height, with respect to bounding box (scaling by x/y equally)

    Parameters

    • value: number

      New height value

    • absolute: boolean = false

      ignore viewport

    Returns void

  • Scales an object to a given width, with respect to bounding box (scaling by x/y equally)

    Parameters

    • value: number

      New width value

    • Optional absolute: boolean

      ignore viewport

    Returns void

  • Moves an object or a selection down in stack of drawn objects An optional parameter, intersecting allows to move the object in behind the first intersecting object. Where intersection is calculated with bounding box. If no intersection is found, there will not be change in the stack.

    Parameters

    Returns boolean

    true if change occurred

  • Moves an object or the objects of a multiple selection to the bottom of the stack of drawn objects

    Parameters

    Returns boolean

    true if change occurred

  • Sets property to a given value. When changing position/dimension -related properties (left, top, scale, angle, etc.) set does not update position of object's borders/controls. If you need to update those, call setCoords().

    Parameters

    • key: string | Record<string, any>

      Property name or object (if object, iterate over the object properties)

    • Optional value: any

      Property value (if function, the value is passed into it and its return value is used as a new one)

    Returns Group

  • Sets the visibility of the specified control. please do not use.

    Parameters

    • controlKey: string

      The key of the control. Possible values are 'tl', 'tr', 'br', 'bl', 'ml', 'mt', 'mr', 'mb', 'mtr'. but since the control api allow for any control name, can be any string.

    • visible: boolean

      true to set the specified control visible, false otherwise

    Returns void

    Todo

    discuss this overlap of priority here with the team. Andrea Bogazzi for details

  • Sets the visibility state of object controls, this is just a bulk option for setControlVisible;

    Parameters

    • Optional options: Record<string, boolean> = {}

      with an optional key per control example: {Boolean} [options.bl] true to enable the bottom-left control, false to disable it

    Returns void

  • Returns void

  • This callback function is called by the parent group of an object every time a non-delegated property changes on the group. It is passed the key and value as parameters. Not adding in this function's signature to avoid Travis build error about unused variables.

    Returns void

  • Protected

    Sets object's properties from options, for class constructor only. Needs to be overridden for different defaults.

    Parameters

    • Optional options: Record<string, any> = {}

      Options object

    Returns void

  • Sets the position of the object taking into consideration the object's origin

    Parameters

    • pos: Point

      The new position of the object

    • originX: TOriginX

      Horizontal origin: 'left', 'center' or 'right'

    • originY: TOriginY

      Vertical origin: 'top', 'center' or 'bottom'

    Returns void

  • Parameters

    • value: number

      x position according to object's originX property in parent's coordinate plane
      if parent is canvas then this method is identical to setX

    Returns void

  • As setXY, but in current parent's coordinate plane (the current group if any or the canvas)

    Parameters

    • point: Point

      position according to object's originX originY properties in parent's coordinate plane

    • Optional originX: TOriginX

      Horizontal origin: 'left', 'center' or 'right'

    • Optional originY: TOriginY

      Vertical origin: 'top', 'center' or 'bottom'

    Returns void

  • Parameters

    • value: number

      y position according to object's originY property in parent's coordinate plane
      if parent is canvas then this property is identical to setY

    Returns void

  • Parameters

    • value: number

      x position according to object's originX property in canvas coordinate plane

    Returns void

  • Set an object position to a particular point, the point is intended in absolute ( canvas ) coordinate. You can specify originX and originY values, that otherwise are the object's current values.

    Parameters

    • point: Point

      position in canvas coordinate plane

    • Optional originX: TOriginX

      Horizontal origin: 'left', 'center' or 'right'

    • Optional originY: TOriginY

      Vertical origin: 'top', 'center' or 'bottom'

    Returns void

    Example

    Set object's bottom left corner to point (5,5) on canvas

    object.setXY(new Point(5, 5), 'left', 'bottom').
    
  • Parameters

    • value: number

      y position according to object's originY property in canvas coordinate plane

    Returns void

  • Decide if the object should cache or not. Create its own cache level needsItsOwnCache should be used when the object drawing method requires a cache step. None of the fabric classes requires it. Generally you do not cache objects in groups because the group is already cached.

    Returns boolean

  • Returns a size of a collection (i.e: length of an array containing its objects)

    Returns number

    Collection size

  • override this function in order to customize the drawing of the control box, e.g. rounded corners, different border style.

    Parameters

    • ctx: CanvasRenderingContext2D

      ctx is rotated and translated so that (0,0) is at object's center

    • size: Point

      the control box size used

    Returns void

  • Converts an object into a HTMLCanvas element

    Parameters

    • options: any = {}

      Options object

    Returns HTMLCanvasElement

    Returns DOM element with the FabricObject

  • Returns svg clipPath representation of an instance

    Parameters

    • Optional reviver: TSVGReviver

      Method for further parsing of svg representation.

    Returns string

    svg representation of an instance

  • Converts an object into a data-url-like string

    Parameters

    • options: any = {}

      Options object

    Returns string

    Returns a data: URL containing a representation of the object in the format specified by options.format

  • Returns (dataless) object representation of an instance

    Parameters

    • Optional propertiesToInclude: any[]

      Any properties that you might want to additionally include in the output

    Returns any

    Object representation of an instance

  • Returns a JSON representation of an instance

    Returns any

    JSON

  • Returns object representation of an instance

    Type Parameters

    Parameters

    • Optional propertiesToInclude: K[] = []

      Any properties that you might want to additionally include in the output

    Returns Pick<T, K> & SerializedGroupProps

    object representation of an instance

  • Returns string

  • Toggles specified property from true to false or from false to true

    Parameters

    • property: string

      Property to toggle

    Returns Group

  • Transforms context when rendering an object

    Parameters

    • ctx: CanvasRenderingContext2D

      Context

    Returns void

  • Parameters

    • skipGroup: boolean = false

    Returns string

  • Translates the coordinates from origin to center coordinates (based on the object's dimensions)

    Parameters

    • point: Point

      The point which corresponds to the originX and originY params

    • originX: TOriginX

      Horizontal origin: 'left', 'center' or 'right'

    • originY: TOriginY

      Vertical origin: 'top', 'center' or 'bottom'

    Returns Point

  • Translates the coordinates from a set of origin to another (based on the object's dimensions)

    Parameters

    • point: Point

      The point which corresponds to the originX and originY params

    • fromOriginX: TOriginX

      Horizontal origin: 'left', 'center' or 'right'

    • fromOriginY: TOriginY

      Vertical origin: 'top', 'center' or 'bottom'

    • toOriginX: TOriginX

      Horizontal origin: 'left', 'center' or 'right'

    • toOriginY: TOriginY

      Vertical origin: 'top', 'center' or 'bottom'

    Returns Point

  • Translates the coordinates from center to origin coordinates (based on the object's dimensions)

    Parameters

    • center: Point

      The point which corresponds to center of the object

    • originX: TOriginX

      Horizontal origin: 'left', 'center' or 'right'

    • originY: TOriginY

      Vertical origin: 'top', 'center' or 'bottom'

    Returns Point

  • Type Parameters

    Parameters

    • Optional context: Partial<LayoutResult> & {
          layout?: T;
      }

      pass values to use for layout calculations

    Returns void

  • Check if this object or a child object will cast a shadow

    Returns boolean

  • Type Parameters

    Parameters

    • object: Record<string, unknown>
    • __namedParameters: Abortable & {
          extraParam?: string;
      } = {}

    Returns Promise<S>

  • Private

    Type Parameters

    Parameters

    • object: T

      Object to create a group from

    Returns Promise<Group>

    Todo

    support loading from svg

    Static

    Member Of

    Group

  • Returns Record<string, any>

Generated using TypeDoc