fabricjs / fabric.js

Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser
http://fabricjs.com
Other
29.03k stars 3.51k forks source link

🧐 Breaking changes for fabric 6.0 #8299

Open asturur opened 2 years ago

asturur commented 2 years ago

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

Collection

Canvas and StaticCanvas

Object

Text

Polyline Polygon Path

Group

Controls

Serialization

Brushes

PatternBrush: removed the getPatternSrcFunction. Wasn't working anymore since the refactor of Pattern and also a super weird practice.

Animation

Utils

Misc

ShaMan123 commented 2 years ago
asturur commented 2 years ago

i 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

ShaMan123 commented 2 years ago

What do you think about planting console.warn in highly breaking stuff that won't surface as errors?

asturur commented 2 years ago

we can with the / dev mode / thing

ShaMan123 commented 2 years ago

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?

ShaMan123 commented 2 years ago

from http://fabricjs.com/v6-breaking-changes:

ShaMan123 commented 2 years ago
ShaMan123 commented 2 years ago

How about we release v6.0.0 with warnings and v6.0.1 without?

ShaMan123 commented 2 years ago

Or add an option to config? or both

asturur commented 2 years ago

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

ShaMan123 commented 2 years ago

OK I will PR an option I have in mind and we discuss there

asturur commented 2 years ago

OK I will PR an option I have in mind and we discuss there Preferably something at build time, no runtime

ShaMan123 commented 2 years ago

Polyline/Polygon/Path _setPositionDimensions => setDimensions #8344

rogeriochaves commented 2 years ago

Group has no longer the method addWithUpdate, only add

asturur commented 2 years ago

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

asturur commented 1 year ago

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

ShaMan123 commented 1 year ago

toLocalPoint => controlsUtils.getLocalPoint or unexported normalizePoint

asturur commented 1 year ago

Added all the breaking changes from #8461 and #8519

asturur commented 1 year ago

Need to add the breaking changes from repacking the lib, as soon as export work i can have a full list

asturur commented 1 year ago

Added breakign changes from animation simplification and the removal of canvas aliases on object

ShaMan123 commented 1 year ago

This is a great practice, we should stick to it now on for future versions

ShaMan123 commented 1 year ago

EraserBrush isn't part of v6 yet, so that is breaking for now #8499

ShaMan123 commented 1 year ago

moved to native classes => no more createClass

ShaMan123 commented 1 year ago
linxianxi commented 1 year ago

how to set canvas background image in v6?

maslennikov commented 1 year ago

@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).

ShaMan123 commented 1 year ago

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.

bladerunner2020 commented 1 year ago

how to set canvas background image in v6?

Also wondering how to set background image as setBackgroundImage is not a function any more...

ShaMan123 commented 1 year ago

canvas.backgroundImage = imageObject

Open dedicated issues/discussions so we don't pollute this thread. Thanks

ShaMan123 commented 1 year ago

setOptions => set

ShaMan123 commented 1 year ago

Object#animate accepts only a map of props Object#_animate accepts only a single prop

ShaMan123 commented 1 year ago

Anyone struggling take a look at https://github.com/fabricjs/fabric.js/discussions/8739#discussioncomment-5126111

3400442579 commented 1 year ago

image image

ShaMan123 commented 1 year ago

tree shaking isn't there yet.

linxianxi commented 1 year ago

How is v6 progressing? Could you give us an approximate time for the official version?

ShaMan123 commented 1 year ago

@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

ShaMan123 commented 1 year ago

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!

pixobe commented 1 year ago

@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?

  1. I cloned this repo
  2. npm run build:fast or npm run build
  3. Linked the package locally to a stenciljs project (that generates web component)
ShaMan123 commented 1 year ago

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

pixobe commented 1 year ago

@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.

ShaMan123 commented 1 year ago

open an issue with a repro let's discuss there

ikilane commented 1 year ago

please please please, don't forget about rtl support, it's so important to us.

enriqueerrando commented 1 year ago

Hi @ShaMan123, how is everything going? Is there an ETA for the V6?

Thanks in advance!

ShaMan123 commented 1 year ago

We are at the finish line

8767 is the last major blocker

No ETA unfortunately Beta is pretty close to the official release. Maybe exports will change a bit (types)

enriqueerrando commented 1 year ago

Ok, thanks for the update!

vinkovsky commented 1 year ago

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 with useEffect 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?

ShaMan123 commented 1 year ago

A reproduction is valuable. Please open an issue dedicated for this with a repro. Then we can help and solve this.

vinkovsky commented 1 year ago

A reproduction is valuable.

Hello @ShaMan123! Sure, thanks for the reply.

https://github.com/fabricjs/fabric.js/issues/8899

Sara-Sultan commented 1 year ago

I wonder how to use destroy function in group as it is not a function any more. group.destroy();

ShaMan123 commented 1 year ago

You can call removeAll and remove it from canvas.