Skip to content

Commit e131a83

Browse files
committed
fix(plugin): 注释蒙版操作
1 parent ef47142 commit e131a83

File tree

5 files changed

+20
-29
lines changed

5 files changed

+20
-29
lines changed

.eslintrc-auto-import.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@
6464
"watchPostEffect": true,
6565
"watchSyncEffect": true
6666
}
67-
}
67+
}

packages/core/plugin/LayerPlugin.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,12 @@ class LayerPlugin implements IPluginTempl {
1616
constructor(public canvas: fabric.Canvas, public editor: IEditor) {}
1717

1818
_getWorkspace() {
19-
const result: Record<'workspace' | 'coverMask', fabric.Object | null> = {
20-
workspace: null,
21-
coverMask: null,
22-
};
23-
this.canvas.getObjects().forEach((item) => {
24-
if (item.id === 'workspace') {
25-
result.workspace = item;
26-
} else if (item.id === 'coverMask') {
27-
result.coverMask = item;
28-
}
29-
});
30-
return result;
19+
return this.canvas.getObjects().find((item) => item.id === 'workspace');
3120
}
3221

3322
_workspaceSendToBack() {
3423
const workspace = this._getWorkspace();
35-
workspace.workspace && workspace.workspace.sendToBack();
36-
workspace.coverMask && workspace.coverMask.bringToFront();
24+
workspace && workspace.sendToBack();
3725
}
3826

3927
up() {

packages/core/plugin/ResizePlugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { fabric } from 'fabric';
1010
import Editor from '../Editor';
1111
import { throttle } from 'lodash-es';
1212
import '../styles/resizePlugin.css';
13-
import WorkspacePlugin from './WorkspacePlugin';
1413

1514
type IEditor = Editor;
1615

@@ -204,7 +203,10 @@ class ResizePlugin implements IPluginTempl {
204203
}
205204

206205
this.editor.setCenterFromObject(workspace);
207-
206+
workspace.clone((cloned: fabric.Rect) => {
207+
this.canvas.clipPath = cloned;
208+
this.canvas.requestRenderAll();
209+
});
208210
if (['left', 'right'].includes(type)) {
209211
this.canvas.defaultCursor = 'ew-resize';
210212
} else {

packages/core/plugin/WorkspacePlugin.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class WorkspacePlugin implements IPluginTempl {
2727
workspaceEl!: HTMLElement;
2828
workspace: null | fabric.Rect;
2929
resizeObserver!: ResizeObserver;
30-
coverMask: null | fabric.Rect = null;
3130
option: any;
3231
zoomRatio: number;
3332
constructor(public canvas: fabric.Canvas, public editor: IEditor) {
@@ -61,6 +60,7 @@ class WorkspacePlugin implements IPluginTempl {
6160
workspace.set('hasControls', false);
6261
workspace.set('evented', false);
6362
this.setSize(workspace.width, workspace.height);
63+
this.editor.emit('sizeChange', workspace.width, workspace.height);
6464
}
6565
resolve('');
6666
});
@@ -159,8 +159,12 @@ class WorkspacePlugin implements IPluginTempl {
159159
this.canvas.zoomToPoint(new fabric.Point(center.left, center.top), scale);
160160
if (!this.workspace) return;
161161
this.setCenterFromObject(this.workspace);
162-
this.editor.getPlugin('MaskPlugin') && this.editor?.setCoverMask(true);
163162

163+
// 超出画布不展示
164+
this.workspace.clone((cloned: fabric.Rect) => {
165+
this.canvas.clipPath = cloned;
166+
this.canvas.requestRenderAll();
167+
});
164168
if (cb) cb(this.workspace.left, this.workspace.top);
165169
}
166170

@@ -208,17 +212,14 @@ class WorkspacePlugin implements IPluginTempl {
208212
}
209213

210214
_bindWheel() {
211-
this.canvas.on('mouse:wheel', (opt) => {
215+
this.canvas.on('mouse:wheel', function (this: fabric.Canvas, opt) {
212216
const delta = opt.e.deltaY;
213-
let zoom = this.canvas.getZoom();
217+
let zoom = this.getZoom();
214218
zoom *= 0.999 ** delta;
215219
if (zoom > 20) zoom = 20;
216220
if (zoom < 0.01) zoom = 0.01;
217-
const center = this.canvas.getCenter();
218-
this.canvas.zoomToPoint(new fabric.Point(center.left, center.top), zoom);
219-
220-
this.editor.getPlugin('MaskPlugin') && this.editor?.setCoverMask(true);
221-
221+
const center = this.getCenter();
222+
this.zoomToPoint(new fabric.Point(center.left, center.top), zoom);
222223
opt.e.preventDefault();
223224
opt.e.stopPropagation();
224225
});

src/components/bgBar.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
</div>
2525
</div>
2626

27-
<div>
27+
<!-- <div>
2828
<Divider plain orientation="left">
2929
<h4>蒙版</h4>
3030
</Divider>
3131
3232
<workspaceMask />
33-
</div>
33+
</div> -->
3434
</div>
3535
</template>
3636

3737
<script setup name="BgBar">
38-
import workspaceMask from './workspaceMask.vue';
38+
// import workspaceMask from './workspaceMask.vue';
3939
import { ref } from 'vue';
4040
import useSelect from '@/hooks/select';
4141
const { mixinState, canvasEditor } = useSelect();

0 commit comments

Comments
 (0)