简体   繁体   English

将 Fabric 项目从 1.6.3 升级到 3.6.x

[英]Upgrade Fabric project from 1.6.3 to 3.6.x

I've been using fabric.js for a long time in one of my canvas projects.在我的一个 canvas 项目中,我已经使用 fabric.js 很长时间了。 Currently, my project is built upon version 1.6.3 of fabric.目前,我的项目是建立在 1.6.3 版的 fabric 之上的。

Now, due to its limitations with animations and the same have been resolved in recent versions.现在,由于它对动画的限制,在最近的版本中已经解决了同样的问题。 I would like to upgrade it to 3.6.x But while doing that, I realised there are tons of depreciation and upgrades to it.我想将它升级到 3.6.x 但在这样做的同时,我意识到它有大量的折旧和升级。 My project currently has some 20k lines of code.我的项目目前有大约 20k 行代码。 Doing this manually is certainly not a viable option.手动执行此操作当然不是一个可行的选择。

Can anyone suggest a better solution?任何人都可以提出更好的解决方案吗? Possibly a migration script or alike to save myself.可能是一个迁移脚本或类似的东西来拯救自己。

To my knowledge there is no upgrade/migration script to automate the process of getting your code working under the latest version of Fabric.js.据我所知,没有升级/迁移脚本可以自动执行让您的代码在最新版本的 Fabric.js 下运行的过程。 To get you started though, here are a few tips.不过,为了让您入门,这里有一些提示。

Upgrading from v1.6.3 to v2.x从 v1.6.3 升级到 v2.x

Fabric.js version v2.x has probably the biggest breaking changes of the major versions. Fabric.js 版本 v2.x 可能是主要版本中最大的突破性变化。 In addition to several methods that were removed, there are significant changes to how image height and width is handled in order to accommodate the new image cropping functionality.除了已删除的几种方法之外,为了适应新的图像裁剪功能,处理图像高度和宽度的方式也发生了重大变化。 The following guide outlines these changes, and also includes some sample code to help with deserializing pre-v2.0 JSON strings.以下指南概述了这些更改,还包括一些示例代码以帮助反序列化 pre-v2.0 JSON 字符串。

Beginning with v2.4.0, clipPath support was added which allows you to clip an object or the canvas with another Fabric object.从 v2.4.0 开始,添加了clipPath支持,允许您使用另一个 Fabric object 剪辑 object 或 canvas。 The clipTo method which was the previous means of doing this is now marked as depreciated, so if your project uses clipTo you should really begin making this transition.以前执行此操作的clipTo方法现在被标记为已弃用,因此如果您的项目使用clipTo ,您应该真正开始进行此转换。 See this 4-part guide to better understand the new functionality.请参阅此 4 部分指南以更好地了解新功能。

Upgrading from v2.x to v3.x从 v2.x 升级到 v3.x

Fabric.js v3.x has fewer breaking changes than v2.x. Fabric.js v3.x 的重大更改比 v2.x 少。 Support for Node 4 and 6 was removed and object caching is now required under some circumstances rather than being optional, but this upgrade is more about new features than big changes.删除了对节点 4 和 6 的支持,并且现在在某些情况下需要 object 缓存而不是可选的,但这次升级更多的是关于新功能而不是重大变化。

See http://fabricjs.com/changelog for a detailed list of changes across each version.有关每个版本的详细更改列表,请参阅http://fabricjs.com/changelog

Upgrading from v3.x to v4.x从 v3.x 升级到 v4.x

I've included this section as well because although at this point the v4.x branch is still in beta, there are quite a few breaking changes that mostly involve the removal of old methods.我也包含了这一部分,因为尽管此时 v4.x 分支仍处于测试阶段,但有很多重大更改主要涉及删除旧方法。 If you make these changes now you can still run your project on the v3.x branch until v4.x leaves beta.如果您现在进行这些更改,您仍然可以在 v3.x 分支上运行您的项目,直到 v4.x 退出测试版。

One big change is that the clipTo method has finally been removed, so if you're still using clipTo you will need to make the move to using clipPath .一个很大的变化是clipTo方法终于被删除了,所以如果你还在使用clipTo ,你需要转而使用clipPath

The biggest improvement coming in v4.x is a new custom control interface. v4.x 中最大的改进是一个新的自定义控制界面。 With this system, you'll be able to customize the function of each control, add icons, and even new controls to your objects.使用此系统,您将能够自定义每个控件的 function,添加图标,甚至为您的对象添加新控件。 See the following demos for help with the new system.有关新系统的帮助,请参阅以下演示。

See https://github.com/fabricjs/fabric.js/releases for a current list of changes and removed methods in the v4.x branch.请参阅https://github.com/fabricjs/fabric.js/releases以获取 v4.x 分支中当前更改和删除方法的列表。

Have fun!玩得开心!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM