Open asturur opened 2 years ago
dispose
is now async, could be breaking with useEffect
in hot reloadmakeBoundingBoxFromPoints(points: Point[])
signature changepopulateWithProperties
=> pick
returns new objecttoJSON
should not be used by the dev directly, use toObject
#8111i ll keep formatting the top post to be the reference to read. I ll threat this asyncronously, feel free to continue add known changes if you know them. i was planning to revisit all the PRs and extract
What do you think about planting console.warn
in highly breaking stuff that won't surface as errors?
we can with the / dev mode / thing
I think it is better to add an internal util and use rollup to remove console logs or use an env var or something Those comments are useless now, right?
from http://fabricjs.com/v6-breaking-changes:
getCenterPoint
#7699 fromElement
and the parser are out of line)Object#getObjectScaling
, Object#getTotalObjectScaling
now returns a fabric.Point instead of {scaleX,scaleY}
#7710How about we release v6.0.0 with warnings and v6.0.1 without?
Or add an option to config
? or both
I think it is better to add an internal util and use rollup to remove console logs or use an env var or something Those comments are useless now, right?
Are useless now but can be activated, can safely become dead code removal with a rollup plugin that swap the comment with a falsy if, with or without an utility to log. Let's keep this thread for logging more than discussing or it get noisy fast
OK I will PR an option I have in mind and we discuss there
OK I will PR an option I have in mind and we discuss there Preferably something at build time, no runtime
Polyline/Polygon/Path _setPositionDimensions
=> setDimensions
#8344
Group has no longer the method addWithUpdate
, only add
From latest TS pr: some chainability removed: setCoords, scale, scaleToWidth, scaleToHeight adjustPosition is gone ( what it was even for? )
Going to update all the upper main description now
BREAKING insertAt signature - (objects, index) => (index, ...objects). Done to comply with the rest of the methods and resemblance to Array.splice BREAKING removed fabric.Collection, but I can put it back
toLocalPoint
=> controlsUtils.getLocalPoint
or unexported normalizePoint
Added all the breaking changes from #8461 and #8519
Need to add the breaking changes from repacking the lib, as soon as export work i can have a full list
Added breakign changes from animation simplification and the removal of canvas aliases on object
This is a great practice, we should stick to it now on for future versions
EraserBrush isn't part of v6 yet, so that is breaking for now #8499
moved to native classes => no more createClass
how to set canvas background image in v6?
@ShaMan123 experimenting with v6 beta: awesome work, thank you so much for the effort! More straightforward object model and typescript support feels real good.
I understand that a lot is going on with v6 right now but want to provide some hands-on feedback. What I found lacking is reexport of core fabrics types & typing utils (e.g. from typedefs, event typedefs), and of some basic internal building blocks (e.g. to implement custom corner controls logic - resizing instead of scaling - I had to reimplement half of controls supporting code because it is not exported).
Thanks for the feedback. v6 is open for it. We noticed types #8715 etc. Exporting is the one thing that is not stable now and should change. Feel free to open issues.
how to set canvas background image in v6?
Also wondering how to set background image as setBackgroundImage is not a function any more...
canvas.backgroundImage = imageObject
Open dedicated issues/discussions so we don't pollute this thread. Thanks
setOptions
=> set
Object#animate
accepts only a map of props
Object#_animate
accepts only a single prop
Anyone struggling take a look at https://github.com/fabricjs/fabric.js/discussions/8739#discussioncomment-5126111
tree shaking isn't there yet.
How is v6 progressing? Could you give us an approximate time for the official version?
@asturur I think it is worth mentioning that since stateful is removed whoever didn't use set relied on hasStateChange and now will find that their app is completely broken. Since we plan to remove set as well I would suggest adding dirty flags (which was what hasStateChanged did) Happy v6 to us all
The prototype doesn't hold defaults anymore, mutation is used only for methods.
Change defaults with the static prop ownDefaults
or method getDefaults
Controls are not shared!
@ShaMan123 I am building the Master branch locally (V6), type of Image object is randomly generated.
For eg: image$1
const img = new fabric.Image(image, options);
console.log(img.get("type"); // image$1
Is there something that am doing wrong?
npm run build:fast
or npm run build
We changed type to be the class name. We didn't take into consideration that rollup, the build tool, will rename the class. You should avoid using type. Use instanceof instead. @asturur
@ShaMan123 Actually the issue is happening when saving as json/restoring it. And also many of the props are missing while saving for eg: control setting like cornerStyle etc.
I appreciate your time and contribution for open source project.
open an issue with a repro let's discuss there
please please please, don't forget about rtl support, it's so important to us.
Hi @ShaMan123, how is everything going? Is there an ETA for the V6?
Thanks in advance!
We are at the finish line
No ETA unfortunately Beta is pretty close to the official release. Maybe exports will change a bit (types)
Ok, thanks for the update!
Hi folks! I am currently working on a react wrapper with Fabricjs v6.
This part is very interesting to me
- canvas
dispose
is now async, could be breaking withuseEffect
in hot reload
How do you handle async disposing in a cleanup function? I try different approaches and my code breaks when initializing a canvas that is not yet removed, or the canvas is removed after initialization, so I see a white screen.
Сould you give me some ideas?
A reproduction is valuable. Please open an issue dedicated for this with a repro. Then we can help and solve this.
A reproduction is valuable.
Hello @ShaMan123! Sure, thanks for the reply.
I wonder how to use destroy function in group as it is not a function any more.
group.destroy();
You can call removeAll and remove it from canvas.
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.classRegistry
to bridge the absence of a namespaceenv
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.fabric.Object
=>FabricObject
fabric.Text
=>FabricText
fabric.Image
=>FabricImage
registerFont
has been removed, useregisterFont
exposed by node canvasmethod 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 ). https://github.com/fabricjs/fabric.js/issues/3684
TS: The code base is typed! If you used
@types/fabric
you should uninstall itPrototype Mutation: Fabric has moved to native classes. No more
createClass
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 the
absolute
plane whereas the viewport wasn't #9175. Normally geometry calculations occur in the scene with the exception ofpadding
which is a viewport scalar.scenePoint
andviewportPoint
properties replacing the deprecated and confusingabsolutePointer
andpointer
properties. Brushes are still in need of this change.Canvas#getPointer
in favor ofgetScenePoint
orgetViewportPoint
viewportTransform
is rather confusing with this change (especially withsendPointToPlane
etc.) perhaps be renaming tosceneTransform
is the correct migration path in the future.React Compatibility:
useEffect
, especially with React 18. Refer to this hook for guidance.dispose
is called while rendering is still in progress. This should burden your react app.Canvas#dispose
is calledCollection
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)
Group
:sendObjectToBack
sendToBackbringObjectToFront
bringToFrontsendObjectBackwards
sendBackwardsbringObjectForward
bringForwardmoveObjectTo
moveToCanvas 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
#7776 is not breaking, it saves the dev from a silent breakage that they weren't aware ofremoved 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 existencegetCenter
renamed togetCenterPoint
#7699add
returns the length of the array of objects after adding, likeArray#push
remove
returns an array with the removed objects insideinsertAt
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 defaultscene vs. viewport changes
getPointer
in favor ofgetScenePoint
orgetViewportPoint
_normalizePointer
,restorePointerVpt
rm
interactive
flag, useinstance of Canvas
insteadrm
setBackgroundColor
,setBackgroundImage
,setOverlayColor
,setOverlayImage
: assign the property directly and render the canvasObject
lineCoords
aCoords
should be treated as protected , if you need the scene corners of an object usegetCoords
absolute
,calculate
from geometry methods signatures (all listed methods operate in the scene):getCoords
intersectsWithRect
intersectsWithObject
isContainedWithinObject
isContainedWithinRect
getBoundingRect
containsPoint
changed signature entirely and fixedgetRelativeXY
/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_setOriginToCenter
and_resetOrigin
#9179oCoords
) are calculated only if the object has acanvas
reftype
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.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.center
,centerH
,centerV
,viewportCenter
are gone. Those were aliases for the canvas methods, use them instead.animate
changed to adapt to animation changescontrols
object is not shared between instances - it is not on the prototype as all class fieldsObject#getObjectScaling
,Object#getTotalObjectScaling
now returnsPoint
instead of{scaleX,scaleY}
#7710Text
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.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.createPolyControls
Group
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 #9152. By default it will befit-content
, meaning the group will fit around its objects, updating when objects are added/removed/modified.Controls
shouldActivate
for ease of use #8934 #9374Serialization
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. https://github.com/fabricjs/fabric.js/pull/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 #8111NUM_FRACTION_DIGIT
moved toconfig
and incremented from 2 to 4Brushes
PatternBrush
: removed thegetPatternSrcFunction
. Wasn't working anymore since the refactor of Pattern and also a super weird practice.Animation
+=
or-=
syntax for changes, nor accept the byValue option. You can specify an animation only by startValue and endValue.Utils
makeBoundingBoxFromPoints
signature change. The transformation is not supported anymore and requires real pointsclone
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 classes.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.sendObjectToPlane
,sendPointToPlane
,sendVectorToPlane
to ease common usages of linear algebra. Check them out, you will benefit from it.Misc
Observable
now returns a disposer making it easier to use and theoff
method redundant #7994Point
methods #7716 #7709