Description
b.0.0-beta16
This list is in progress and is meant to be an easy go to place to add things and find them when the time comes to write a document on what has changed.
This will be a list of descriptive items, extended as needed to capture behavior changes.
Apart from what is described here MANY bugs have been fixed in the process.
Generic concepts
-
Imports we moved from
import { fabric } from 'fabric'
toimport { Canvas, Rect, util } from 'fabric'
orimport * as fabric from 'fabric'
. To avoid packaging issues node has its own entrypointimport { StaticCanvas } from 'fabric/node'
. This means there is no fabric namespace/object anymore.- Introduced
classRegistry
to bridge the absence of a namespace - Introduced the
env
concept,getEnv
to allow node/browser specific values/logic. That has made importing fabric in SSR possible and will allow offscreen support in the future. - renamed the following Force users to use FabricObject instead of Object、FabricImage instead of Image、FabricText instead of Text #9172:
fabric.Object
=>FabricObject
fabric.Text
=>FabricText
fabric.Image
=>FabricImage
- Node's
registerFont
has been removed, useregisterFont
exposed by node canvas
- Introduced
-
method chaining is now deprecated, don't use it anymore. Not all methods were chainable, and chaining seems to offer limited advantages ( maybe saving 1-2 bytes in the code you write when minified? unsure what else ). Just for consistency sake and to be free to start returning useful information from some methods we will stop using it. We didn't remove it from everywhere so that there isn't unnecessary breakage, but you should consider that unsafe to use, since will break entirely on the next major release after 6.0
( add detailed list of where has been removed so far ) -
Callbacks are mostly gone, all of the functions that took a callback now return a Promise, this on top of being breaking slightly alter code behavior when is fixed. Before sync code would execute the callback synchronously, now is chained to however the browser handle the promise ( not sure if it goes in the event loop and under which circumstances ). Promises support #3684
-
TS: The code base is typed! If you used
@types/fabric
you should uninstall it -
Prototype Mutation:
Fabric has moved to native classes. No morecreateClass
orobject.util.extend
. You can still mutate the prototype, however, properties do not exist on the prototype in native classes. Look intogetDefaults
instead. -
scene vs. viewport
We introduced these concepts to describe the rendering/view planes as follows: The viewer is viewing the scene (what is rendered/"playing") from the viewport. The scene was considered is the past as theabsolute
plane whereas the viewport wasn't feat(Canvas): provide correctly named canvas pointer methods. BREAKING: rm_normalizePointer
,restorePointerVpt
#9175.
Normally geometry calculations occur in the scene with the exception ofpadding
which is a viewport scalar.- All events have a
scenePoint
andviewportPoint
properties replacing the deprecated and confusingabsolutePointer
andpointer
properties. Brushes are still in need of this change. - dep
Canvas#getPointer
in favor ofgetScenePoint
orgetViewportPoint
- Using
viewportTransform
is rather confusing with this change (especially withsendPointToPlane
etc.) perhaps be renaming tosceneTransform
is the correct migration path in the future.
- All events have a
-
React Compatibility:
- Ensure proper disposal in
useEffect
, especially with React 18. Refer to this hook for guidance. - Async Disposal: Handle async nature of dispose method. The asynchronous disposal of Canvas and StaticCanvas safeguards an edge case in which
dispose
is called while rendering is still in progress. This should burden your react app. - DOM Mutation: Fabric modifies the DOM and cleans up after itself as long as
Canvas#dispose
is called
- Ensure proper disposal in
Collection
- not available as a standard object as
fabric.Collection
any longer, was never meant to, it was a constrain of the previous build system ( we had no imports or require or bundling before ). insertAt
method signature changed frominsertAt(object, index)
toinsertAt(index, ...objects)
- Collection now owns the stack too, methods were renamed to accommodate
Group
:sendObjectToBack
sendToBackbringObjectToFront
bringToFrontsendObjectBackwards
sendBackwardsbringObjectForward
bringForwardmoveObjectTo
moveTo
- Support to stack operations with active selection is gone
Canvas and StaticCanvas
-
Canvas.dispose and StaticCanvas.dispose are now async In order to handle some concurrency issue with requestAnimationFrame, dispose is now checking and waiting for any uncancellable render to finish. This could have some side effects, especially in complex environments with UI frameworks and hot reload of code.
-
trying to initialize a canvas that has already been initialized
fix(Canvas): Safeguard from multiple initialization #7776 is not breaking, it saves the dev from a silent breakage that they weren't aware of -
removed canvas.straightenObject wasn't really useful.
-
changed cloneWithoutData , now it does not clone backgrounds.
-
canvas.clone now correctly return either a canvas or staticCanvas
-
drawClipPathOnCanvas
signature changed: now accepts the clipPath as a second argument instead of rechecking its existence -
getCenter
renamed togetCenterPoint
dep(Canvas#getCenter): migrate togetCenterPoint
#7699 -
add
returns the length of the array of objects after adding, likeArray#push
-
remove
returns an array with the removed objects inside -
insertAt
method signature changed (refer to theCollection
section) -
removed
sendToBack
,bringToFront
,sendBackward
,moveTo
,bringForward
( and gained similar methods from collection (refer to theCollection
section) -
Canvas#freeDrawingBrush
is not set by default -
scene vs. viewport changes
- dep
getPointer
in favor ofgetScenePoint
orgetViewportPoint
- rm
_normalizePointer
,restorePointerVpt
- dep
-
rm
interactive
flag, useinstance of Canvas
instead -
rm
setBackgroundColor
,setBackgroundImage
,setOverlayColor
,setOverlayImage
: assign the property directly and render the canvas
Object
- BREAKING Coords system improvements:
- removed
lineCoords
aCoords
should be treated as protected , if you need the scene corners of an object usegetCoords
- fixed coords to respect grouping and nesting, see the Group section
- removed
absolute
,calculate
from geometry methods signatures (all listed methods operate in the scene):getCoords
intersectsWithRect
intersectsWithObject
isContainedWithinObject
isContainedWithinRect
getBoundingRect
containsPoint
changed signature entirely and fixed
getRelativeXY
/setRelativeXY
to get/set the coordinate in the parent plane,getXY
/setXY
to get/set the coordinate in the scene planeadjustPosition
is gone. It took a parameter only, was internally unused, didn't take care of internal edge cases setPositionByOrigin is more flexible- rm
_setOriginToCenter
and_resetOrigin
change(): rm _setOriginToCenter and _resetOrigin #9179 - Control coords (
oCoords
) are calculated only if the object has acanvas
ref
- removed
type
has become a static field and should be used only for serialization withclassRegistry
. There is still a deprecated getter on the object for compatibility reasons. Avoid using it.- Object looses the stack methods, instead of guessing which was the stack we refer to when we move forward/backward we do that from the stack itself BREAKING(Object Stacking): 🔙 refactor logic to support Group 🔝 #8461, see the Collection section
- stateful functionality is deprecated, is officially removed, but is still reacheable. Don't use it. Comparing large set of propeties to detect a change doesn't really play well neither with performance nor with edge cases. stateful and statefulCache are removed.
stateful
was used to fire an object modified every render cycle in which a change in state properties was determiend. All the events that can modify an object already fire anobject:modified
event, and the user has no ability to change colors or state outside developer written code, so there is no really need for event firing here. statefulCache was an experiment and the suggestion to useset(property, value)
replaced it since long. FabricJS internally still use some stateful logic for now, but the intention is to get rid of it. - methods like
center
,centerH
,centerV
,viewportCenter
are gone. Those were aliases for the canvas methods, use them instead. animate
changed to adapt to animation changes- The
controls
object is not shared between instances - it is not on the prototype as all class fields - BREAKING:
Object#getObjectScaling
,Object#getTotalObjectScaling
now returnsPoint
instead of{scaleX,scaleY}
BREAKING chore(): Reuse fabric.Point logic for scaling and naming consistency #7710
Text
- see Text styles under the Serialization section
- rename
data-fabric-hiddentextarea
todata-fabric
with valuetextarea
, if you were usinghasAttribute('data-fabric-hiddentextarea')
now you have to usegetAttribute('data-fabric')
and then check for equality withtextarea
or change your cssSelector accordingly. _getStyleDeclaration
returns an empty object instead of undefined when style is not set.- controls can be used in editing mode
Polyline Polygon Path
_setPositionDimensions
(considered private in the past), has been renamed tosetDimensions
. The logic with which Polyline based object calculate the size is changed. There wasn't an api in 5.x to change the size, but devs needed to do it anyway and the alternative was to create a new object. Is not called setPositionAndDimensions because the logic to correcly change size while keeping a visual correct position is not there yet and maybe it won't.- exposed long desired poly controls
createPolyControls
Group
- complete rewrite described in
V6
: 🎉 Group Rewrite #7670 - CONCEPT: Group rewrite exposes a change in concept - strict object tree. An object can belong to one parent.
- exposed the
parent
property onFabricObject
alongsidegroup
to allow an object to return to itsparent
after being deselected from an active selection. addWithUpdate
is gone, nowadd
does what it has to do.LayoutManager
has been introduced to handle group layout refactor(): Layout Manager #9152. By default it will befit-content
, meaning the group will fit around its objects, updating when objects are added/removed/modified.
Controls
- expose
shouldActivate
for ease of use patch():Control#shouldActivate
#8934 patch(Control): move hit detection to shouldActivate #9374 - no longer shared, they are a class field
Serialization
Text#styles
is now exported differently. This is BREAKING only if you are handling the style object post export The default object we exported was large most of the time, with tons of empty keys and verbosity. It seems reasonable to think that most of the time text is styled in some chunk of text with coherent different styles ( eg: a red word in a black text or some words underlined and some not more than a rainbow of different stylings per object ) for that reason we changed the approach of serialization to an array with start and end index for the style. We didn't apply that to actual runtime code because we were unsure of performance, so at least for version 6, styles at runtime are going to be the same. It is highly recommended to not fiddle with the style object directly and to treat it as internal, using the public facing methods to apply changes. feat(Text): condensed styles structure v6 #8006populateWithProperties
=>pick
populate with properties was used internally to add the extra options to exported objects. Between spread operator and new syntax, a generic pick approach seemed more correct.toJSON
is not an alias oftoObject
. This was a long standing bug, but also a breaking change.toJSON
never accepted additional properties and will give you only the default object export.toJSON
is meant forJSON#stringify
interoperability and is not meant to be used in your code base directly. reference fix(): weirdtoJson
bug #8111- classRegistry => register your subclasses to use them during serialization
NUM_FRACTION_DIGIT
moved toconfig
and incremented from 2 to 4
Brushes
PatternBrush
: removed the getPatternSrcFunction
. Wasn't working anymore since the refactor of Pattern and also a super weird practice.
Animation
- animation util does not accept anymore the
+=
or-=
syntax for changes, nor accept the byValue option. You can specify an animation only by startValue and endValue. - Every animation returns a class with a cancel method to cancel the animation.
- Animation callback onChange and onComplete will fire for every animation generated by set of properties. This change is necessary because if we assign the callbacks to only one animation, in case that animation will be cancelled, the other ones won't have any registered callback.
Utils
makeBoundingBoxFromPoints
signature change. The transformation is not supported anymore and requires real points- removal of all the array utils ( min, max, find those are well covered by es6 now and also is out of fabric scope to provide generic data manipulation utils )
- some utils are considered internal and not exposed anymore ( TODO add list )
clone
andextend
have been removed. Those were used in all examples unfortunately so the community has likely adopted them, consider migrating to a well known common library for those functionalities ( lodash, underscore ... ). Avoid using such utilities on instances of shapes or canvas. So do not clone a Rect with a clone utility. You can clone objects you don't want to mutate, in general plain javascript objects.makeElementSelectable
andmakeElementUnselectable
are removed. Those were needed internally and one of them is still used internally, but is not a fabricJS core functionality and not part of the api anymore.- exposed
sendObjectToPlane
,sendPointToPlane
,sendVectorToPlane
to ease common usages of linear algebra. Check them out, you will benefit from it. - exposed more vector utils
Misc
Observable
now returns a disposer making it easier to use and theoff
method redundant feat(observable): BREAKING return disposer instead of context for chaining #7994Point
methods MAJOR feat(fabric.Point): divide, scalarDivide, scalarDivideEquals #7716 chore(): Cleanup fabric.Point for v6 #7709- Eraser has been extracted to https://github.com/ShaMan123/erase2d
- Touch gestures are not yet migrated/officially supported - use a lib for that for now
- Build pipeline (rollup)
- new testing frameworks (jest, playwright)
Activity