@hprint/plugins 0.0.1-alpha.2 → 0.0.1-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +17 -17
- package/dist/index.mjs +1071 -1057
- package/dist/src/plugins/AlignGuidLinePlugin.d.ts +7 -2
- package/dist/src/plugins/AlignGuidLinePlugin.d.ts.map +1 -1
- package/dist/src/plugins/GroupAlignPlugin.d.ts.map +1 -1
- package/dist/src/plugins/LockPlugin.d.ts.map +1 -1
- package/dist/src/plugins/QrCodePlugin.d.ts +5 -0
- package/dist/src/plugins/QrCodePlugin.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/assets/style/resizePlugin.css +27 -27
- package/src/objects/Arrow.js +47 -47
- package/src/objects/ThinTailArrow.js +50 -50
- package/src/plugins/AlignGuidLinePlugin.ts +1152 -1141
- package/src/plugins/BarCodePlugin.ts +2 -2
- package/src/plugins/ControlsPlugin.ts +251 -251
- package/src/plugins/ControlsRotatePlugin.ts +111 -111
- package/src/plugins/CopyPlugin.ts +255 -255
- package/src/plugins/DeleteHotKeyPlugin.ts +57 -57
- package/src/plugins/DrawLinePlugin.ts +162 -162
- package/src/plugins/DrawPolygonPlugin.ts +205 -205
- package/src/plugins/DringPlugin.ts +125 -125
- package/src/plugins/FlipPlugin.ts +59 -59
- package/src/plugins/FontPlugin.ts +165 -165
- package/src/plugins/FreeDrawPlugin.ts +49 -49
- package/src/plugins/GroupAlignPlugin.ts +365 -365
- package/src/plugins/GroupPlugin.ts +82 -82
- package/src/plugins/GroupTextEditorPlugin.ts +198 -198
- package/src/plugins/HistoryPlugin.ts +181 -181
- package/src/plugins/ImageStroke.ts +121 -121
- package/src/plugins/LayerPlugin.ts +108 -108
- package/src/plugins/LockPlugin.ts +242 -240
- package/src/plugins/MaskPlugin.ts +155 -155
- package/src/plugins/MaterialPlugin.ts +224 -224
- package/src/plugins/MiddleMousePlugin.ts +45 -45
- package/src/plugins/MoveHotKeyPlugin.ts +46 -46
- package/src/plugins/PathTextPlugin.ts +89 -89
- package/src/plugins/PolygonModifyPlugin.ts +224 -224
- package/src/plugins/PrintPlugin.ts +81 -81
- package/src/plugins/PsdPlugin.ts +52 -52
- package/src/plugins/QrCodePlugin.ts +322 -329
- package/src/plugins/ResizePlugin.ts +278 -278
- package/src/plugins/RulerPlugin.ts +78 -78
- package/src/plugins/SimpleClipImagePlugin.ts +244 -244
- package/src/plugins/UnitPlugin.ts +326 -326
- package/src/plugins/WaterMarkPlugin.ts +257 -257
- package/src/types/eventType.ts +11 -11
- package/src/utils/psd.js +432 -432
- package/src/utils/ruler/guideline.ts +145 -145
- package/src/utils/ruler/index.ts +91 -91
- package/src/utils/ruler/ruler.ts +924 -924
- package/src/utils/ruler/utils.ts +162 -162
- package/tsconfig.json +10 -10
- package/vite.config.ts +29 -29
|
@@ -2,14 +2,19 @@ import { fabric, IEditor, IPluginTempl } from '@hprint/core';
|
|
|
2
2
|
declare class AlignGuidLinePlugin implements IPluginTempl {
|
|
3
3
|
canvas: fabric.Canvas;
|
|
4
4
|
editor: IEditor;
|
|
5
|
+
static pluginName: string;
|
|
6
|
+
static apis: string[];
|
|
5
7
|
defautOption: {
|
|
6
8
|
color: string;
|
|
7
9
|
width: number;
|
|
8
10
|
};
|
|
9
|
-
static pluginName: string;
|
|
10
11
|
dragMode: boolean;
|
|
11
|
-
|
|
12
|
+
switch: boolean;
|
|
13
|
+
constructor(canvas: fabric.Canvas, editor: IEditor, options?: {
|
|
14
|
+
switch?: boolean;
|
|
15
|
+
});
|
|
12
16
|
init(): void;
|
|
17
|
+
changeSwitch(switchStatus: boolean): void;
|
|
13
18
|
destroy(): void;
|
|
14
19
|
}
|
|
15
20
|
export default AlignGuidLinePlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlignGuidLinePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/AlignGuidLinePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAc7D,cAAM,mBAAoB,YAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"AlignGuidLinePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/AlignGuidLinePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAc7D,cAAM,mBAAoB,YAAW,YAAY;IAUlC,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAV1B,MAAM,CAAC,UAAU,SAAyB;IAC1C,MAAM,CAAC,IAAI,WAAoB;IAC/B,YAAY;;;MAGV;IACF,QAAQ,UAAS;IACjB,MAAM,EAAG,OAAO,CAAC;gBAEN,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO,EACtB,OAAO,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,OAAO,CAAC;KACpB;IAML,IAAI;IAolCJ,YAAY,CAAC,YAAY,EAAE,OAAO;IAIlC,OAAO;CAGV;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupAlignPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/GroupAlignPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,KAAK,OAAO,GAAG,IAAI,CACf,gBAAgB,EACd,MAAM,GACN,OAAO,GACP,SAAS,GACT,SAAS,GACT,KAAK,GACL,QAAQ,GACR,WAAW,GACX,WAAW,CAChB,CAAC;AAEF,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;
|
|
1
|
+
{"version":3,"file":"GroupAlignPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/GroupAlignPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,KAAK,OAAO,GAAG,IAAI,CACf,gBAAgB,EACd,MAAM,GACN,OAAO,GACP,SAAS,GACT,SAAS,GACT,KAAK,GACL,QAAQ,GACR,WAAW,GACX,WAAW,CAChB,CAAC;AAEF,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAI;CACxC;AAED,cAAM,gBAAiB,YAAW,YAAY;IAc/B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAd1B,MAAM,CAAC,UAAU,SAAsB;IACvC,MAAM,CAAC,IAAI,WAST;gBAGS,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAG1B,IAAI;IAuBJ,KAAK;IA0BL,OAAO;IA0BP,OAAO;IA0BP,GAAG;IAsBH,MAAM;IA0BN,SAAS;IAwFT,SAAS;IAoFT,OAAO;CAGV;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LockPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/LockPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM1D,KAAK,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;AAEnD,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;
|
|
1
|
+
{"version":3,"file":"LockPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/LockPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM1D,KAAK,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;AAEnD,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAI;CACxC;AAuBD,MAAM,CAAC,OAAO,OAAO,UAAW,YAAW,YAAY;IAIxC,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAJ1B,MAAM,CAAC,UAAU,SAAgB;IACjC,MAAM,CAAC,IAAI,WAAsB;gBAEtB,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAK1B,IAAI;IA8GJ,qBAAqB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM;IAWxC,uBAAuB;IAevB,eAAe;IAYf,IAAI;IAaJ,MAAM;IAgBN,WAAW;;;;;IAgBX,OAAO;CAGV"}
|
|
@@ -15,6 +15,11 @@ declare class QrCodePlugin implements IPluginTempl {
|
|
|
15
15
|
originObject: any;
|
|
16
16
|
fabricObject: any;
|
|
17
17
|
}): Promise<void>;
|
|
18
|
+
_getQrCodeResult(options: any): Promise<{
|
|
19
|
+
url: string;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
}>;
|
|
18
23
|
_getBase64Str(options: any): Promise<string>;
|
|
19
24
|
_defaultBarcodeOption(): {
|
|
20
25
|
value: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QrCodePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/QrCodePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,KAAK,OAAO,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,GAAG,WAAW,CAAC,CAAC;AAE7D,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAI;CACxC;
|
|
1
|
+
{"version":3,"file":"QrCodePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/QrCodePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,KAAK,OAAO,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,GAAG,WAAW,CAAC,CAAC;AAE7D,OAAO,QAAQ,cAAc,CAAC;IAE1B,UAAU,OAAQ,SAAQ,OAAO;KAAI;CACxC;AAED,cAAM,YAAa,YAAW,YAAY;IAI3B,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,OAAO;IAJ1B,MAAM,CAAC,UAAU,SAAkB;IACnC,MAAM,CAAC,IAAI,WAA8B;gBAE9B,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,MAAM,EAAE,OAAO;IAGpB,aAAa,CAAC,MAAM,EAAE,GAAG;IA0BzB,sBAAsB,CAAC,EAAE,YAAY,EAAE,YAAY,EAAE,EAAE;QAAE,YAAY,EAAE,GAAG,CAAC;QAAC,YAAY,EAAE,GAAG,CAAA;KAAE;IAM/F,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAsCvF,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAKlD,qBAAqB;;;;;;IASrB;;OAEG;IACH,eAAe,CAAC,MAAM,EAAE,GAAG;YAiBb,kBAAkB;IAkChC;;OAEG;IACH,OAAO,CAAC,cAAc;IAiBtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAoCzB;;OAEG;IACG,SAAS,CACX,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;QAChC,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACnB,EACD,GAAG,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAwDlB,SAAS,CAAC,MAAM,EAAE,GAAG;IA2B3B,OAAO;CAGV;AAED,eAAe,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hprint/plugins",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"qs": "~6.12.3",
|
|
23
23
|
"socket.io-client": "^4.8.1",
|
|
24
24
|
"uuid": "~8.3.2",
|
|
25
|
-
"@hprint/core": "0.0.1-alpha.
|
|
26
|
-
"@hprint/shared": "0.0.1-alpha.
|
|
25
|
+
"@hprint/core": "0.0.1-alpha.3",
|
|
26
|
+
"@hprint/shared": "0.0.1-alpha.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/bwip-js": "^3.2.3",
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
.resize-bar {
|
|
2
|
-
border-radius: 3px;
|
|
3
|
-
background-color: rgba(160, 160, 160, 0.6);
|
|
4
|
-
position: absolute;
|
|
5
|
-
}
|
|
6
|
-
.resize-bar:hover {
|
|
7
|
-
background-color: #328cff;
|
|
8
|
-
}
|
|
9
|
-
.resize-bar.horizontal {
|
|
10
|
-
width: 6px;
|
|
11
|
-
height: 30px;
|
|
12
|
-
}
|
|
13
|
-
.resize-bar.vertical {
|
|
14
|
-
width: 30px;
|
|
15
|
-
height: 6px;
|
|
16
|
-
}
|
|
17
|
-
.resize-bar.active {
|
|
18
|
-
background-color: #328cff;
|
|
19
|
-
}
|
|
20
|
-
#resize-left-bar,
|
|
21
|
-
#resize-right-bar {
|
|
22
|
-
cursor: ew-resize;
|
|
23
|
-
}
|
|
24
|
-
#resize-top-bar,
|
|
25
|
-
#resize-bottom-bar {
|
|
26
|
-
cursor: ns-resize;
|
|
27
|
-
}
|
|
1
|
+
.resize-bar {
|
|
2
|
+
border-radius: 3px;
|
|
3
|
+
background-color: rgba(160, 160, 160, 0.6);
|
|
4
|
+
position: absolute;
|
|
5
|
+
}
|
|
6
|
+
.resize-bar:hover {
|
|
7
|
+
background-color: #328cff;
|
|
8
|
+
}
|
|
9
|
+
.resize-bar.horizontal {
|
|
10
|
+
width: 6px;
|
|
11
|
+
height: 30px;
|
|
12
|
+
}
|
|
13
|
+
.resize-bar.vertical {
|
|
14
|
+
width: 30px;
|
|
15
|
+
height: 6px;
|
|
16
|
+
}
|
|
17
|
+
.resize-bar.active {
|
|
18
|
+
background-color: #328cff;
|
|
19
|
+
}
|
|
20
|
+
#resize-left-bar,
|
|
21
|
+
#resize-right-bar {
|
|
22
|
+
cursor: ew-resize;
|
|
23
|
+
}
|
|
24
|
+
#resize-top-bar,
|
|
25
|
+
#resize-bottom-bar {
|
|
26
|
+
cursor: ns-resize;
|
|
27
|
+
}
|
package/src/objects/Arrow.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { fabric } from '@hprint/core';
|
|
2
|
-
|
|
3
|
-
fabric.Arrow = fabric.util.createClass(fabric.Line, {
|
|
4
|
-
type: 'arrow',
|
|
5
|
-
superType: 'drawing',
|
|
6
|
-
initialize(points, options) {
|
|
7
|
-
if (!points) {
|
|
8
|
-
const { x1, x2, y1, y2 } = options;
|
|
9
|
-
points = [x1, y1, x2, y2];
|
|
10
|
-
}
|
|
11
|
-
options = options || {};
|
|
12
|
-
this.callSuper('initialize', points, options);
|
|
13
|
-
},
|
|
14
|
-
_render(ctx) {
|
|
15
|
-
this.callSuper('_render', ctx);
|
|
16
|
-
ctx.save();
|
|
17
|
-
// 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
|
|
18
|
-
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
|
|
19
|
-
const xDiff = (this.x2 - this.x1) * this.scaleX;
|
|
20
|
-
const yDiff = (this.y2 - this.y1) * this.scaleY;
|
|
21
|
-
const angle = Math.atan2(yDiff, xDiff);
|
|
22
|
-
ctx.translate(
|
|
23
|
-
((this.x2 - this.x1) / 2) * this.scaleX,
|
|
24
|
-
((this.y2 - this.y1) / 2) * this.scaleY
|
|
25
|
-
);
|
|
26
|
-
ctx.rotate(angle);
|
|
27
|
-
ctx.beginPath();
|
|
28
|
-
// Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
|
|
29
|
-
ctx.moveTo(0, 0);
|
|
30
|
-
ctx.lineTo(-10, 5);
|
|
31
|
-
ctx.lineTo(-10, -5);
|
|
32
|
-
ctx.closePath();
|
|
33
|
-
ctx.lineWidth = this.lineWidth;
|
|
34
|
-
ctx.strokeStyle = this.stroke;
|
|
35
|
-
ctx.fillStyle = this.fill;
|
|
36
|
-
ctx.stroke();
|
|
37
|
-
ctx.fill();
|
|
38
|
-
ctx.restore();
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
fabric.Arrow.fromObject = (options, callback) => {
|
|
43
|
-
const { x1, x2, y1, y2 } = options;
|
|
44
|
-
return callback(new fabric.Arrow([x1, y1, x2, y2], options));
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export default fabric.Arrow;
|
|
1
|
+
import { fabric } from '@hprint/core';
|
|
2
|
+
|
|
3
|
+
fabric.Arrow = fabric.util.createClass(fabric.Line, {
|
|
4
|
+
type: 'arrow',
|
|
5
|
+
superType: 'drawing',
|
|
6
|
+
initialize(points, options) {
|
|
7
|
+
if (!points) {
|
|
8
|
+
const { x1, x2, y1, y2 } = options;
|
|
9
|
+
points = [x1, y1, x2, y2];
|
|
10
|
+
}
|
|
11
|
+
options = options || {};
|
|
12
|
+
this.callSuper('initialize', points, options);
|
|
13
|
+
},
|
|
14
|
+
_render(ctx) {
|
|
15
|
+
this.callSuper('_render', ctx);
|
|
16
|
+
ctx.save();
|
|
17
|
+
// 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
|
|
18
|
+
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
|
|
19
|
+
const xDiff = (this.x2 - this.x1) * this.scaleX;
|
|
20
|
+
const yDiff = (this.y2 - this.y1) * this.scaleY;
|
|
21
|
+
const angle = Math.atan2(yDiff, xDiff);
|
|
22
|
+
ctx.translate(
|
|
23
|
+
((this.x2 - this.x1) / 2) * this.scaleX,
|
|
24
|
+
((this.y2 - this.y1) / 2) * this.scaleY
|
|
25
|
+
);
|
|
26
|
+
ctx.rotate(angle);
|
|
27
|
+
ctx.beginPath();
|
|
28
|
+
// Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
|
|
29
|
+
ctx.moveTo(0, 0);
|
|
30
|
+
ctx.lineTo(-10, 5);
|
|
31
|
+
ctx.lineTo(-10, -5);
|
|
32
|
+
ctx.closePath();
|
|
33
|
+
ctx.lineWidth = this.lineWidth;
|
|
34
|
+
ctx.strokeStyle = this.stroke;
|
|
35
|
+
ctx.fillStyle = this.fill;
|
|
36
|
+
ctx.stroke();
|
|
37
|
+
ctx.fill();
|
|
38
|
+
ctx.restore();
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
fabric.Arrow.fromObject = (options, callback) => {
|
|
43
|
+
const { x1, x2, y1, y2 } = options;
|
|
44
|
+
return callback(new fabric.Arrow([x1, y1, x2, y2], options));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default fabric.Arrow;
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { fabric } from '@hprint/core';
|
|
2
|
-
|
|
3
|
-
fabric.ThinTailArrow = fabric.util.createClass(fabric.Line, {
|
|
4
|
-
type: 'thinTailArrow',
|
|
5
|
-
superType: 'drawing',
|
|
6
|
-
initialize(points, options) {
|
|
7
|
-
if (!points) {
|
|
8
|
-
const { x1, x2, y1, y2 } = options;
|
|
9
|
-
points = [x1, y1, x2, y2];
|
|
10
|
-
}
|
|
11
|
-
options = options || {};
|
|
12
|
-
this.callSuper('initialize', points, options);
|
|
13
|
-
},
|
|
14
|
-
_render(ctx) {
|
|
15
|
-
ctx.save();
|
|
16
|
-
// 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
|
|
17
|
-
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
|
|
18
|
-
const xDiff = (this.x2 - this.x1) * this.scaleX;
|
|
19
|
-
const yDiff = (this.y2 - this.y1) * this.scaleY;
|
|
20
|
-
ctx.translate(-xDiff / 2, -yDiff / 2);
|
|
21
|
-
// 箭头方位角
|
|
22
|
-
const angle = Math.atan2(yDiff, xDiff);
|
|
23
|
-
ctx.rotate(angle);
|
|
24
|
-
// 箭头总长(最小长度是20)
|
|
25
|
-
let length = Math.hypot(xDiff, yDiff);
|
|
26
|
-
length = length < 20 ? 20 : length;
|
|
27
|
-
// 绘制箭头
|
|
28
|
-
ctx.beginPath();
|
|
29
|
-
ctx.moveTo(0, 0);
|
|
30
|
-
ctx.lineTo(length - 18, -5);
|
|
31
|
-
ctx.lineTo(length - 20, -12);
|
|
32
|
-
ctx.lineTo(length, 0);
|
|
33
|
-
ctx.lineTo(length - 20, 12);
|
|
34
|
-
ctx.lineTo(length - 18, 5);
|
|
35
|
-
ctx.lineTo(0, 0);
|
|
36
|
-
ctx.lineWidth = this.strokeWidth;
|
|
37
|
-
ctx.strokeStyle = this.stroke;
|
|
38
|
-
ctx.fillStyle = this.fill;
|
|
39
|
-
ctx.stroke();
|
|
40
|
-
ctx.fill();
|
|
41
|
-
ctx.restore();
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
fabric.ThinTailArrow.fromObject = (options, callback) => {
|
|
46
|
-
const { x1, x2, y1, y2 } = options;
|
|
47
|
-
return callback(new fabric.ThinTailArrow([x1, y1, x2, y2], options));
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export default fabric.ThinTailArrow;
|
|
1
|
+
import { fabric } from '@hprint/core';
|
|
2
|
+
|
|
3
|
+
fabric.ThinTailArrow = fabric.util.createClass(fabric.Line, {
|
|
4
|
+
type: 'thinTailArrow',
|
|
5
|
+
superType: 'drawing',
|
|
6
|
+
initialize(points, options) {
|
|
7
|
+
if (!points) {
|
|
8
|
+
const { x1, x2, y1, y2 } = options;
|
|
9
|
+
points = [x1, y1, x2, y2];
|
|
10
|
+
}
|
|
11
|
+
options = options || {};
|
|
12
|
+
this.callSuper('initialize', points, options);
|
|
13
|
+
},
|
|
14
|
+
_render(ctx) {
|
|
15
|
+
ctx.save();
|
|
16
|
+
// 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
|
|
17
|
+
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
|
|
18
|
+
const xDiff = (this.x2 - this.x1) * this.scaleX;
|
|
19
|
+
const yDiff = (this.y2 - this.y1) * this.scaleY;
|
|
20
|
+
ctx.translate(-xDiff / 2, -yDiff / 2);
|
|
21
|
+
// 箭头方位角
|
|
22
|
+
const angle = Math.atan2(yDiff, xDiff);
|
|
23
|
+
ctx.rotate(angle);
|
|
24
|
+
// 箭头总长(最小长度是20)
|
|
25
|
+
let length = Math.hypot(xDiff, yDiff);
|
|
26
|
+
length = length < 20 ? 20 : length;
|
|
27
|
+
// 绘制箭头
|
|
28
|
+
ctx.beginPath();
|
|
29
|
+
ctx.moveTo(0, 0);
|
|
30
|
+
ctx.lineTo(length - 18, -5);
|
|
31
|
+
ctx.lineTo(length - 20, -12);
|
|
32
|
+
ctx.lineTo(length, 0);
|
|
33
|
+
ctx.lineTo(length - 20, 12);
|
|
34
|
+
ctx.lineTo(length - 18, 5);
|
|
35
|
+
ctx.lineTo(0, 0);
|
|
36
|
+
ctx.lineWidth = this.strokeWidth;
|
|
37
|
+
ctx.strokeStyle = this.stroke;
|
|
38
|
+
ctx.fillStyle = this.fill;
|
|
39
|
+
ctx.stroke();
|
|
40
|
+
ctx.fill();
|
|
41
|
+
ctx.restore();
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
fabric.ThinTailArrow.fromObject = (options, callback) => {
|
|
46
|
+
const { x1, x2, y1, y2 } = options;
|
|
47
|
+
return callback(new fabric.ThinTailArrow([x1, y1, x2, y2], options));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default fabric.ThinTailArrow;
|