Skip to content

Commit

Permalink
fix: 修复部分ts报错 (ikuaitu#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
liumingye authored Jun 10, 2024
1 parent 0fc5364 commit bef2fcf
Showing 36 changed files with 168 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .eslintrc-auto-import.json
Original file line number Diff line number Diff line change
@@ -64,4 +64,4 @@
"watchPostEffect": true,
"watchSyncEffect": true
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -27,3 +27,4 @@ yarn.lock
pnpm-lock.yaml
package-lock.json
typings/auto-imports.d.ts
.eslintrc-auto-import.json
22 changes: 12 additions & 10 deletions packages/core/plugin.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ class FontPlugin {
repoSrc: string;

constructor(canvas: fabric.Canvas, editor: IEditor, config: { repoSrc: string }) {
// 初始化
// 初始化
this.canvas = canvas;
this.editor = editor;
// 可插入外部配置
@@ -27,17 +27,19 @@ class FontPlugin {
hookImportBefore(json: string) {
return this.downFontByJSON(json);
}

// 挂载API方法
downFontByJSON(str: string) {}

downFontByJSON() {
//
}

// 私有方法 + 发布事件
_createFontCSS(){
const params = []
this.editor.emit('textEvent1', params)
_createFontCSS() {
const params = [];
this.editor.emit('textEvent1', params);
}

// 右键菜单
// 右键菜单
contextMenu() {
const selectedMode = this.editor.getSelectMode();
if (selectedMode === SelectMode.ONE) {
@@ -62,9 +64,9 @@ class FontPlugin {
];
}
}

// 快捷键
hotkeyEvent(eventName: string, e: { type, code }) {
hotkeyEvent(eventName: string, { type }: KeyboardEvent) {
// eventName:hotkeys中的属性 backspace、space
// type:keyUp keyDown
// code:hotkeys-js Code
13 changes: 3 additions & 10 deletions packages/core/plugin/AlignGuidLinePlugin.ts
Original file line number Diff line number Diff line change
@@ -23,21 +23,14 @@ declare interface HorizontalLine {
y: number;
}

class AlignGuidLinePlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
public defautOption = {
class AlignGuidLinePlugin implements IPluginTempl {
defautOption = {
color: 'rgba(255,95,95,1)',
width: 1,
};
static pluginName = 'AlignGuidLinePlugin';
static events = ['', ''];
static apis = [];
public hotkeys: string[] = [''];
dragMode = false;
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
constructor(public canvas: fabric.Canvas, public editor: IEditor) {
this.dragMode = false;
this.init();
}
9 changes: 2 additions & 7 deletions packages/core/plugin/BarCodePlugin.ts
Original file line number Diff line number Diff line change
@@ -24,15 +24,10 @@ enum CodeType {
pharmacode = 'pharmacode',
}

class BarCodePlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
class BarCodePlugin implements IPluginTempl {
static pluginName = 'BarCodePlugin';
static apis = ['addBarcode', 'setBarcode', 'getBarcodeTypes'];
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
}
constructor(public canvas: fabric.Canvas, public editor: IEditor) {}

async hookTransform(object: any) {
if (object.extensionType === 'barcode') {
9 changes: 2 additions & 7 deletions packages/core/plugin/CenterAlignPlugin.ts
Original file line number Diff line number Diff line change
@@ -10,16 +10,11 @@ import { fabric } from 'fabric';
import Editor from '../Editor';
type IEditor = Editor;

class CenterAlignPlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
class CenterAlignPlugin implements IPluginTempl {
static pluginName = 'CenterAlignPlugin';
static apis = ['centerH', 'center', 'position', 'centerV'];
// public hotkeys: string[] = ['space'];
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
}
constructor(public canvas: fabric.Canvas, public editor: IEditor) {}

center(workspace: fabric.Rect, object: fabric.Object) {
const center = workspace.getCenterPoint();
13 changes: 5 additions & 8 deletions packages/core/plugin/ControlsPlugin.ts
Original file line number Diff line number Diff line change
@@ -152,8 +152,9 @@ function peakControl() {
render: renderIconEdge,
});
}

// 删除
function deleteControl(canvas: fabric.Canvas) {
/*function deleteControl(canvas: fabric.Canvas) {
const deleteIcon =
"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg version='1.1' id='Ebene_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='595.275px' height='595.275px' viewBox='200 215 230 470' xml:space='preserve'%3E%3Ccircle style='fill:%23F44336;' cx='299.76' cy='439.067' r='218.516'/%3E%3Cg%3E%3Crect x='267.162' y='307.978' transform='matrix(0.7071 -0.7071 0.7071 0.7071 -222.6202 340.6915)' style='fill:white;' width='65.545' height='262.18'/%3E%3Crect x='266.988' y='308.153' transform='matrix(0.7071 0.7071 -0.7071 0.7071 398.3889 -83.3116)' style='fill:white;' width='65.544' height='262.179'/%3E%3C/g%3E%3C/svg%3E";
const delImg = document.createElement('img');
@@ -192,7 +193,7 @@ function deleteControl(canvas: fabric.Canvas) {
render: renderDelIcon,
// cornerSize: 24,
});
}
}*/

// 旋转
function rotationControl() {
@@ -220,13 +221,9 @@ function rotationControl() {
});
}

class ControlsPlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
class ControlsPlugin implements IPluginTempl {
static pluginName = 'ControlsPlugin';
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
constructor(public canvas: fabric.Canvas, public editor: IEditor) {
this.init();
}
init() {
8 changes: 2 additions & 6 deletions packages/core/plugin/ControlsRotatePlugin.ts
Original file line number Diff line number Diff line change
@@ -14,13 +14,9 @@ function rotateIcon(angle: number) {
return `url("data:image/svg+xml,%3Csvg height='18' width='18' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: black;'%3E%3Cg fill='none' transform='rotate(${angle} 16 16)'%3E%3Cpath d='M22.4484 0L32 9.57891L22.4484 19.1478V13.1032C17.6121 13.8563 13.7935 17.6618 13.0479 22.4914H19.2141L9.60201 32.01L0 22.4813H6.54912C7.36524 14.1073 14.0453 7.44023 22.4484 6.61688V0Z' fill='white'/%3E%3Cpath d='M24.0605 3.89587L29.7229 9.57896L24.0605 15.252V11.3562C17.0479 11.4365 11.3753 17.0895 11.3048 24.0879H15.3048L9.60201 29.7308L3.90932 24.0879H8.0806C8.14106 15.3223 15.2645 8.22345 24.0605 8.14313V3.89587Z' fill='black'/%3E%3C/g%3E%3C/svg%3E ") 12 12,crosshair`;
}

class ControlsRotatePlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
class ControlsRotatePlugin implements IPluginTempl {
static pluginName = 'ControlsRotatePlugin';
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
constructor(public canvas: fabric.Canvas, public editor: IEditor) {
this.init();
}
init() {
15 changes: 5 additions & 10 deletions packages/core/plugin/CopyPlugin.ts
Original file line number Diff line number Diff line change
@@ -12,17 +12,12 @@ type IEditor = Editor;
import { v4 as uuid } from 'uuid';
import { getImgStr } from '../utils/utils';

class CopyPlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
class CopyPlugin implements IPluginTempl {
static pluginName = 'CopyPlugin';
static apis = ['clone'];
public hotkeys: string[] = ['ctrl+v', 'ctrl+c'];
private cache: null | fabric.ActiveSelection | fabric.Object;
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
this.cache = null;
hotkeys: string[] = ['ctrl+v', 'ctrl+c'];
private cache: null | fabric.ActiveSelection | fabric.Object = null;
constructor(public canvas: fabric.Canvas, public editor: IEditor) {
this.initPaste();
}

@@ -92,7 +87,7 @@ class CopyPlugin {
}

// 快捷键扩展回调
hotkeyEvent(eventName: string, e: any) {
hotkeyEvent(eventName: string, e: KeyboardEvent) {
if (eventName === 'ctrl+c' && e.type === 'keydown') {
const activeObject = this.canvas.getActiveObject();
this.cache = activeObject;
13 changes: 4 additions & 9 deletions packages/core/plugin/DeleteHotKeyPlugin.ts
Original file line number Diff line number Diff line change
@@ -11,19 +11,14 @@ import Editor from '../Editor';
type IEditor = Editor;
// import { v4 as uuid } from 'uuid';

class DeleteHotKeyPlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
class DeleteHotKeyPlugin implements IPluginTempl {
static pluginName = 'DeleteHotKeyPlugin';
static apis = ['del'];
public hotkeys: string[] = ['backspace'];
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
}
hotkeys: string[] = ['backspace'];
constructor(public canvas: fabric.Canvas, public editor: IEditor) {}

// 快捷键扩展回调
hotkeyEvent(eventName: string, e: any) {
hotkeyEvent(eventName: string, e: KeyboardEvent) {
if (e.type === 'keydown' && eventName === 'backspace') {
this.del();
}
9 changes: 2 additions & 7 deletions packages/core/plugin/DrawLinePlugin.ts
Original file line number Diff line number Diff line change
@@ -13,9 +13,7 @@ import ThinTailArrow from '../objects/ThinTailArrow';
import Editor from '../Editor';
type IEditor = Editor;

class DrawLinePlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
class DrawLinePlugin implements IPluginTempl {
static pluginName = 'DrawLinePlugin';
static apis = ['setLineType', 'setMode'];
isDrawingLineMode: boolean;
@@ -24,10 +22,7 @@ class DrawLinePlugin {
pointer: any;
pointerPoints: any;
isDrawingLine: boolean;
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;

constructor(public canvas: fabric.Canvas, public editor: IEditor) {
this.isDrawingLine = false;
this.isDrawingLineMode = false;
this.lineType = '';
2 changes: 1 addition & 1 deletion packages/core/plugin/DrawPolygonPlugin.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ type IEditor = Editor;
type LineCoords = [fabric.Point, fabric.Point];
type OffListener = (ev: fabric.IEvent) => void;
type OnEnd = (...args: any[]) => void;
class DrawPolygonPlugin {
class DrawPolygonPlugin implements IPluginTempl {
isDrawingPolygon = false;
points: fabric.Point[] = [];
lines: fabric.Line[] = [];
14 changes: 5 additions & 9 deletions packages/core/plugin/DringPlugin.ts
Original file line number Diff line number Diff line change
@@ -9,18 +9,14 @@
import Editor from '../Editor';
type IEditor = Editor;

export class DringPlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
public defautOption = {};
export class DringPlugin implements IPluginTempl {
defautOption = {};
static pluginName = 'DringPlugin';
static events = ['startDring', 'endDring'];
static apis = ['startDring', 'endDring'];
public hotkeys: string[] = ['space'];
hotkeys: string[] = ['space'];
dragMode = false;
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
constructor(public canvas: fabric.Canvas, public editor: IEditor) {
this.dragMode = false;
this.init();
}
@@ -104,7 +100,7 @@ export class DringPlugin {

// 快捷键扩展回调
// eslint-disable-next-line @typescript-eslint/no-explicit-any
hotkeyEvent(eventName: string, e: any) {
hotkeyEvent(eventName: string, e: KeyboardEvent) {
if (e.code === 'Space' && e.type === 'keydown') {
if (!this.dragMode) {
this.startDring();
9 changes: 2 additions & 7 deletions packages/core/plugin/FlipPlugin.ts
Original file line number Diff line number Diff line change
@@ -7,15 +7,10 @@ import { SelectMode } from '../eventType';
const t = (key: string) => key;
// import event from '@/utils/event/notifier';

export default class FlipPlugin {
public canvas: fabric.Canvas;
public editor: Editor;
export default class FlipPlugin implements IPluginTempl {
static pluginName = 'FlipPlugin';
static apis = ['flip'];
constructor(canvas: fabric.Canvas, editor: Editor) {
this.canvas = canvas;
this.editor = editor;
}
constructor(public canvas: fabric.Canvas, public editor: Editor) {}

flip(type: 'X' | 'Y') {
const activeObject = this.canvas.getActiveObject();
10 changes: 3 additions & 7 deletions packages/core/plugin/FontPlugin.ts
Original file line number Diff line number Diff line change
@@ -27,17 +27,13 @@ interface FontSource {
img: string;
}

class FontPlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
class FontPlugin implements IPluginTempl {
private tempPromise: Promise<FontSource[]> | null;
static pluginName = 'FontPlugin';
static apis = ['getFontList', 'loadFont', 'getFontJson', 'downFontByJSON'];
repoSrc: string;
cacheList: FontSource[];
constructor(canvas: fabric.Canvas, editor: IEditor, config: { repoSrc: string }) {
this.canvas = canvas;
this.editor = editor;
constructor(public canvas: fabric.Canvas, public editor: IEditor, config: { repoSrc: string }) {
this.repoSrc = config.repoSrc;
this.cacheList = [];
this.tempPromise = null;
@@ -100,7 +96,7 @@ class FontPlugin {
const fileStr = `data:text/json;charset=utf-8,${encodeURIComponent(
JSON.stringify(json, null, '\t')
)}`;
const dataUrl = activeObject.toDataURL();
const dataUrl = activeObject.toDataURL({});
downFile(fileStr, 'font.json');
downFile(dataUrl, 'font.png');
}
2 changes: 1 addition & 1 deletion packages/core/plugin/FreeDrawPlugin.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ type DrawOptions = {
width: number;
};

export default class FreeDrawPlugin {
export default class FreeDrawPlugin implements IPluginTempl {
static pluginName = 'FreeDrawPlugin';
static apis = ['startDraw', 'endDraw'];
constructor(public canvas: fabric.Canvas, public editor: IEditor) {}
9 changes: 2 additions & 7 deletions packages/core/plugin/GroupAlignPlugin.ts
Original file line number Diff line number Diff line change
@@ -10,16 +10,11 @@ import { fabric } from 'fabric';
import Editor from '../Editor';
type IEditor = Editor;

class GroupAlignPlugin {
public canvas: fabric.Canvas;
public editor: IEditor;
class GroupAlignPlugin implements IPluginTempl {
static pluginName = 'GroupAlignPlugin';
static apis = ['left', 'right', 'xcenter', 'ycenter', 'top', 'bottom', 'xequation', 'yequation'];
// public hotkeys: string[] = ['space'];
constructor(canvas: fabric.Canvas, editor: IEditor) {
this.canvas = canvas;
this.editor = editor;
}
constructor(public canvas: fabric.Canvas, public editor: IEditor) {}

left() {
const { canvas } = this;
Loading

0 comments on commit bef2fcf

Please sign in to comment.