Comments (3)
Thanks for great package. Same issue here haha
from fabric-history.
i have the same issue, it will be nice to apply undo and redo in de eraser
from fabric-history.
//undo可以撤销橡皮擦的步骤。但是它会附带删除一个画笔步骤所以需要在每一次使用橡皮擦过后
//去创建一个极小的看不见的画笔步骤。
//并且需要确定橡皮擦的线条有没有和已有的画笔进行了交互。否则不创建线条
npm i fabric-history
import 'fabric-history';
canvas.value.undo();
//使用橡皮擦时去监听一个路径完成创建的事件
canvas.value.on('path:created', intersects)
// 离开橡皮擦时取消事件监听器
canvas.value.off('path:created', intersects);
// 创建线条后的交互查询
const intersects=(e)=> {
// 获取当前画布上的所有元素
const objects = canvas.value.getObjects();
// 循环遍历画布上的每个对象执行交叉检测
//一次擦除可能跨越多条路径,有一条相交叫返回true
const result= objects.some(object => {
// 执行交叉检测
const isIntersecting = object.intersectsWithObject(e.path);
//object.id !=='simulate'排除自己创建的元素
return isIntersecting && object.id !=='simulate'
console.log(元素 ${object} 与捕获到的路径存在交叉
);
});
if(result) addSimulatePoint()
}
// 创建一条红色线条
const addSimulatePoint=()=> {
var point = new fabric.Circle({
left: 0,
top: 0,
radius: 1,
fill: 'red',
selectable: false, // 禁止选择
evented: false, // 禁止触发事件
visible:false
});
// 设置唯一标识符避免橡皮擦划到去创建新的元素
point.set('id', 'simulate');
// 将红色线条添加到画布中
canvas.value.add(point);
// canvas.value.renderAll();
}
from fabric-history.
Related Issues (20)
- Uncaught TypeError: canvas.undo is not a function HOT 2
- Create an ability to store custom properties HOT 2
- Preserve selected objects on each state when undo/redo
- custom added properties are removed HOT 2
- [Bug] Undo after first drawing on a Canvas with background image set not working properly HOT 2
- Non-Selectable objects still get selectable eventually HOT 2
- Insufficient Granularity of Access Control in JSDom - https://github.com/advisories/GHSA-f4c9-cqv8-9v98 HOT 2
- Clear canvas isn't part of the history HOT 3
- Undo/Redo functions are removing 2 objects at same time HOT 2
- Undo after setting scaled background image ends in white space in the right corner.
- Keep objects selected after undo/redo
- when load from json it removes all items on undo but I want initial json HOT 2
- Type definition HOT 2
- Fabric v6 support HOT 2
- Skip Action to become part of history HOT 1
- Undo Redo remove my object's attributes HOT 2
- Is there a way to exclude some object saving in history? HOT 2
- Multiple canvases: managing history undo and redo
- Makes browser to crash.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fabric-history.