@nasser-sw/fabric 7.0.1-beta3 → 7.0.1-beta4

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.
Files changed (105) hide show
  1. package/0 +0 -0
  2. package/dist/index.js +323 -155
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/index.min.mjs +1 -1
  7. package/dist/index.min.mjs.map +1 -1
  8. package/dist/index.mjs +323 -155
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/index.node.cjs +323 -155
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.mjs +323 -155
  13. package/dist/index.node.mjs.map +1 -1
  14. package/dist/package.json.min.mjs +1 -1
  15. package/dist/package.json.mjs +1 -1
  16. package/dist/src/shapes/Line.d.ts +31 -86
  17. package/dist/src/shapes/Line.d.ts.map +1 -1
  18. package/dist/src/shapes/Line.min.mjs +1 -1
  19. package/dist/src/shapes/Line.min.mjs.map +1 -1
  20. package/dist/src/shapes/Line.mjs +323 -154
  21. package/dist/src/shapes/Line.mjs.map +1 -1
  22. package/dist-extensions/src/shapes/CustomLine.d.ts +10 -0
  23. package/dist-extensions/src/shapes/CustomLine.d.ts.map +1 -0
  24. package/dist-extensions/src/shapes/Line.d.ts +31 -86
  25. package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
  26. package/fabric-test-editor.html +157 -8
  27. package/fabric-test2.html +513 -0
  28. package/fabric.ts +182 -182
  29. package/package.json +1 -1
  30. package/src/shapes/Line.ts +372 -158
  31. package/debug/konva/CHANGELOG.md +0 -1474
  32. package/debug/konva/LICENSE +0 -22
  33. package/debug/konva/README.md +0 -205
  34. package/debug/konva/gulpfile.mjs +0 -110
  35. package/debug/konva/package.json +0 -139
  36. package/debug/konva/release.sh +0 -65
  37. package/debug/konva/resources/doc-includes/ContainerParams.txt +0 -6
  38. package/debug/konva/resources/doc-includes/NodeParams.txt +0 -20
  39. package/debug/konva/resources/doc-includes/ShapeParams.txt +0 -53
  40. package/debug/konva/resources/jsdoc.conf.json +0 -28
  41. package/debug/konva/rollup.config.mjs +0 -32
  42. package/debug/konva/src/Animation.ts +0 -237
  43. package/debug/konva/src/BezierFunctions.ts +0 -826
  44. package/debug/konva/src/Canvas.ts +0 -193
  45. package/debug/konva/src/Container.ts +0 -649
  46. package/debug/konva/src/Context.ts +0 -1017
  47. package/debug/konva/src/Core.ts +0 -5
  48. package/debug/konva/src/DragAndDrop.ts +0 -173
  49. package/debug/konva/src/Factory.ts +0 -246
  50. package/debug/konva/src/FastLayer.ts +0 -29
  51. package/debug/konva/src/Global.ts +0 -210
  52. package/debug/konva/src/Group.ts +0 -31
  53. package/debug/konva/src/Layer.ts +0 -546
  54. package/debug/konva/src/Node.ts +0 -3477
  55. package/debug/konva/src/PointerEvents.ts +0 -67
  56. package/debug/konva/src/Shape.ts +0 -2081
  57. package/debug/konva/src/Stage.ts +0 -1000
  58. package/debug/konva/src/Tween.ts +0 -811
  59. package/debug/konva/src/Util.ts +0 -1123
  60. package/debug/konva/src/Validators.ts +0 -210
  61. package/debug/konva/src/_CoreInternals.ts +0 -85
  62. package/debug/konva/src/_FullInternals.ts +0 -171
  63. package/debug/konva/src/canvas-backend.ts +0 -36
  64. package/debug/konva/src/filters/Blur.ts +0 -388
  65. package/debug/konva/src/filters/Brighten.ts +0 -48
  66. package/debug/konva/src/filters/Brightness.ts +0 -30
  67. package/debug/konva/src/filters/Contrast.ts +0 -75
  68. package/debug/konva/src/filters/Emboss.ts +0 -207
  69. package/debug/konva/src/filters/Enhance.ts +0 -154
  70. package/debug/konva/src/filters/Grayscale.ts +0 -25
  71. package/debug/konva/src/filters/HSL.ts +0 -108
  72. package/debug/konva/src/filters/HSV.ts +0 -106
  73. package/debug/konva/src/filters/Invert.ts +0 -23
  74. package/debug/konva/src/filters/Kaleidoscope.ts +0 -274
  75. package/debug/konva/src/filters/Mask.ts +0 -220
  76. package/debug/konva/src/filters/Noise.ts +0 -44
  77. package/debug/konva/src/filters/Pixelate.ts +0 -107
  78. package/debug/konva/src/filters/Posterize.ts +0 -46
  79. package/debug/konva/src/filters/RGB.ts +0 -82
  80. package/debug/konva/src/filters/RGBA.ts +0 -103
  81. package/debug/konva/src/filters/Sepia.ts +0 -27
  82. package/debug/konva/src/filters/Solarize.ts +0 -29
  83. package/debug/konva/src/filters/Threshold.ts +0 -44
  84. package/debug/konva/src/index.ts +0 -3
  85. package/debug/konva/src/shapes/Arc.ts +0 -176
  86. package/debug/konva/src/shapes/Arrow.ts +0 -231
  87. package/debug/konva/src/shapes/Circle.ts +0 -76
  88. package/debug/konva/src/shapes/Ellipse.ts +0 -121
  89. package/debug/konva/src/shapes/Image.ts +0 -319
  90. package/debug/konva/src/shapes/Label.ts +0 -386
  91. package/debug/konva/src/shapes/Line.ts +0 -364
  92. package/debug/konva/src/shapes/Path.ts +0 -1013
  93. package/debug/konva/src/shapes/Rect.ts +0 -79
  94. package/debug/konva/src/shapes/RegularPolygon.ts +0 -167
  95. package/debug/konva/src/shapes/Ring.ts +0 -94
  96. package/debug/konva/src/shapes/Sprite.ts +0 -370
  97. package/debug/konva/src/shapes/Star.ts +0 -125
  98. package/debug/konva/src/shapes/Text.ts +0 -1065
  99. package/debug/konva/src/shapes/TextPath.ts +0 -583
  100. package/debug/konva/src/shapes/Transformer.ts +0 -1889
  101. package/debug/konva/src/shapes/Wedge.ts +0 -129
  102. package/debug/konva/src/skia-backend.ts +0 -35
  103. package/debug/konva/src/types.ts +0 -84
  104. package/debug/konva/tsconfig.json +0 -31
  105. package/debug/konva/tsconfig.test.json +0 -7
@@ -1,82 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { Filter } from '../Node.ts';
3
- import { Node } from '../Node.ts';
4
- import { RGBComponent } from '../Validators.ts';
5
-
6
- /**
7
- * RGB Filter
8
- * @function
9
- * @name RGB
10
- * @memberof Konva.Filters
11
- * @param {Object} imageData
12
- * @author ippo615
13
- * @example
14
- * node.cache();
15
- * node.filters([Konva.Filters.RGB]);
16
- * node.blue(120);
17
- * node.green(200);
18
- */
19
- export const RGB: Filter = function (imageData) {
20
- const data = imageData.data,
21
- nPixels = data.length,
22
- red = this.red(),
23
- green = this.green(),
24
- blue = this.blue();
25
-
26
- for (let i = 0; i < nPixels; i += 4) {
27
- const brightness =
28
- (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
29
- data[i] = brightness * red; // r
30
- data[i + 1] = brightness * green; // g
31
- data[i + 2] = brightness * blue; // b
32
- data[i + 3] = data[i + 3]; // alpha
33
- }
34
- };
35
-
36
- Factory.addGetterSetter(Node, 'red', 0, function (this: Node, val) {
37
- this._filterUpToDate = false;
38
- if (val > 255) {
39
- return 255;
40
- } else if (val < 0) {
41
- return 0;
42
- } else {
43
- return Math.round(val);
44
- }
45
- });
46
- /**
47
- * get/set filter red value. Use with {@link Konva.Filters.RGB} filter.
48
- * @name red
49
- * @method
50
- * @memberof Konva.Node.prototype
51
- * @param {Integer} red value between 0 and 255
52
- * @returns {Integer}
53
- */
54
-
55
- Factory.addGetterSetter(Node, 'green', 0, function (this: Node, val) {
56
- this._filterUpToDate = false;
57
- if (val > 255) {
58
- return 255;
59
- } else if (val < 0) {
60
- return 0;
61
- } else {
62
- return Math.round(val);
63
- }
64
- });
65
- /**
66
- * get/set filter green value. Use with {@link Konva.Filters.RGB} filter.
67
- * @name green
68
- * @method
69
- * @memberof Konva.Node.prototype
70
- * @param {Integer} green value between 0 and 255
71
- * @returns {Integer}
72
- */
73
-
74
- Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter);
75
- /**
76
- * get/set filter blue value. Use with {@link Konva.Filters.RGB} filter.
77
- * @name blue
78
- * @method
79
- * @memberof Konva.Node.prototype
80
- * @param {Integer} blue value between 0 and 255
81
- * @returns {Integer}
82
- */
@@ -1,103 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { Filter } from '../Node.ts';
3
- import { Node } from '../Node.ts';
4
- import { RGBComponent } from '../Validators.ts';
5
-
6
- /**
7
- * RGBA Filter
8
- * @function
9
- * @name RGBA
10
- * @memberof Konva.Filters
11
- * @param {Object} imageData
12
- * @author codefo
13
- * @example
14
- * node.cache();
15
- * node.filters([Konva.Filters.RGBA]);
16
- * node.blue(120);
17
- * node.green(200);
18
- * node.alpha(0.3);
19
- */
20
-
21
- export const RGBA: Filter = function (imageData) {
22
- const data = imageData.data,
23
- nPixels = data.length,
24
- red = this.red(),
25
- green = this.green(),
26
- blue = this.blue(),
27
- alpha = this.alpha();
28
-
29
- for (let i = 0; i < nPixels; i += 4) {
30
- const ia = 1 - alpha;
31
-
32
- data[i] = red * alpha + data[i] * ia; // r
33
- data[i + 1] = green * alpha + data[i + 1] * ia; // g
34
- data[i + 2] = blue * alpha + data[i + 2] * ia; // b
35
- }
36
- };
37
-
38
- Factory.addGetterSetter(Node, 'red', 0, function (this: Node, val: number) {
39
- this._filterUpToDate = false;
40
- if (val > 255) {
41
- return 255;
42
- } else if (val < 0) {
43
- return 0;
44
- } else {
45
- return Math.round(val);
46
- }
47
- });
48
- /**
49
- * get/set filter red value. Use with {@link Konva.Filters.RGBA} filter.
50
- * @name red
51
- * @method
52
- * @memberof Konva.Node.prototype
53
- * @param {Integer} red value between 0 and 255
54
- * @returns {Integer}
55
- */
56
-
57
- Factory.addGetterSetter(Node, 'green', 0, function (this: Node, val) {
58
- this._filterUpToDate = false;
59
- if (val > 255) {
60
- return 255;
61
- } else if (val < 0) {
62
- return 0;
63
- } else {
64
- return Math.round(val);
65
- }
66
- });
67
- /**
68
- * get/set filter green value. Use with {@link Konva.Filters.RGBA} filter.
69
- * @name green
70
- * @method
71
- * @memberof Konva.Node.prototype
72
- * @param {Integer} green value between 0 and 255
73
- * @returns {Integer}
74
- */
75
-
76
- Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter);
77
- /**
78
- * get/set filter blue value. Use with {@link Konva.Filters.RGBA} filter.
79
- * @name blue
80
- * @method
81
- * @memberof Konva.Node.prototype
82
- * @param {Integer} blue value between 0 and 255
83
- * @returns {Integer}
84
- */
85
-
86
- Factory.addGetterSetter(Node, 'alpha', 1, function (this: Node, val) {
87
- this._filterUpToDate = false;
88
- if (val > 1) {
89
- return 1;
90
- } else if (val < 0) {
91
- return 0;
92
- } else {
93
- return val;
94
- }
95
- });
96
- /**
97
- * get/set filter alpha value. Use with {@link Konva.Filters.RGBA} filter.
98
- * @name alpha
99
- * @method
100
- * @memberof Konva.Node.prototype
101
- * @param {Float} alpha value between 0 and 1
102
- * @returns {Float}
103
- */
@@ -1,27 +0,0 @@
1
- import type { Filter } from '../Node.ts';
2
-
3
- // based on https://stackoverflow.com/questions/1061093/how-is-a-sepia-tone-created
4
-
5
- /**
6
- * @function
7
- * @name Sepia
8
- * @memberof Konva.Filters
9
- * @param {Object} imageData
10
- * @example
11
- * node.cache();
12
- * node.filters([Konva.Filters.Sepia]);
13
- */
14
- export const Sepia: Filter = function (imageData) {
15
- const data = imageData.data,
16
- nPixels = data.length;
17
-
18
- for (let i = 0; i < nPixels; i += 4) {
19
- const r = data[i + 0];
20
- const g = data[i + 1];
21
- const b = data[i + 2];
22
-
23
- data[i + 0] = Math.min(255, r * 0.393 + g * 0.769 + b * 0.189);
24
- data[i + 1] = Math.min(255, r * 0.349 + g * 0.686 + b * 0.168);
25
- data[i + 2] = Math.min(255, r * 0.272 + g * 0.534 + b * 0.131);
26
- }
27
- };
@@ -1,29 +0,0 @@
1
- import type { Filter } from '../Node.ts';
2
- /**
3
- * Solarize Filter
4
- * @function
5
- * @name Solarize
6
- * @memberof Konva.Filters
7
- * @param {Object} imageData
8
- * @example
9
- * node.cache();
10
- * node.filters([Konva.Filters.Solarize]);
11
- */
12
-
13
- export const Solarize: Filter = function (imageData) {
14
- const threshold = 128;
15
- const d = imageData.data;
16
- for (let i = 0; i < d.length; i += 4) {
17
- const r = d[i],
18
- g = d[i + 1],
19
- b = d[i + 2];
20
- // sRGB luma
21
- const L = 0.2126 * r + 0.7152 * g + 0.0722 * b;
22
- if (L >= threshold) {
23
- d[i] = 255 - r;
24
- d[i + 1] = 255 - g;
25
- d[i + 2] = 255 - b;
26
- }
27
- }
28
- return imageData;
29
- };
@@ -1,44 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { Filter } from '../Node.ts';
3
- import { Node } from '../Node.ts';
4
- import { getNumberValidator } from '../Validators.ts';
5
- /**
6
- * Threshold Filter. Pushes any value above the mid point to
7
- * the max and any value below the mid point to the min.
8
- * This affects the alpha channel.
9
- * @function
10
- * @name Threshold
11
- * @memberof Konva.Filters
12
- * @param {Object} imageData
13
- * @author ippo615
14
- * @example
15
- * node.cache();
16
- * node.filters([Konva.Filters.Threshold]);
17
- * node.threshold(0.1);
18
- */
19
-
20
- export const Threshold: Filter = function (imageData) {
21
- const level = this.threshold() * 255,
22
- data = imageData.data,
23
- len = data.length;
24
-
25
- for (let i = 0; i < len; i += 1) {
26
- data[i] = data[i] < level ? 0 : 255;
27
- }
28
- };
29
-
30
- Factory.addGetterSetter(
31
- Node,
32
- 'threshold',
33
- 0.5,
34
- getNumberValidator(),
35
- Factory.afterSetFilter
36
- );
37
- /**
38
- * get/set threshold. Must be a value between 0 and 1. Use with {@link Konva.Filters.Threshold} or {@link Konva.Filters.Mask} filter.
39
- * @name threshold
40
- * @method
41
- * @memberof Konva.Node.prototype
42
- * @param {Number} threshold
43
- * @returns {Number}
44
- */
@@ -1,3 +0,0 @@
1
- import { Konva } from './_FullInternals.ts';
2
-
3
- export default Konva;
@@ -1,176 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { ShapeConfig } from '../Shape.ts';
3
- import { Shape } from '../Shape.ts';
4
- import { Konva } from '../Global.ts';
5
- import type { GetSet } from '../types.ts';
6
- import { getNumberValidator, getBooleanValidator } from '../Validators.ts';
7
- import { _registerNode } from '../Global.ts';
8
- import type { Context } from '../Context.ts';
9
-
10
- export interface ArcConfig extends ShapeConfig {
11
- angle: number;
12
- innerRadius: number;
13
- outerRadius: number;
14
- clockwise?: boolean;
15
- }
16
-
17
- /**
18
- * Arc constructor
19
- * @constructor
20
- * @memberof Konva
21
- * @augments Konva.Shape
22
- * @param {Object} config
23
- * @param {Number} config.angle in degrees
24
- * @param {Number} config.innerRadius
25
- * @param {Number} config.outerRadius
26
- * @param {Boolean} [config.clockwise]
27
- * @@shapeParams
28
- * @@nodeParams
29
- * @example
30
- * // draw a Arc that's pointing downwards
31
- * var arc = new Konva.Arc({
32
- * innerRadius: 40,
33
- * outerRadius: 80,
34
- * fill: 'red',
35
- * stroke: 'black'
36
- * strokeWidth: 5,
37
- * angle: 60,
38
- * rotationDeg: -120
39
- * });
40
- */
41
- export class Arc extends Shape<ArcConfig> {
42
- _sceneFunc(context: Context) {
43
- const angle = Konva.getAngle(this.angle()),
44
- clockwise = this.clockwise();
45
-
46
- context.beginPath();
47
- context.arc(0, 0, this.outerRadius(), 0, angle, clockwise);
48
- context.arc(0, 0, this.innerRadius(), angle, 0, !clockwise);
49
- context.closePath();
50
- context.fillStrokeShape(this);
51
- }
52
- getWidth() {
53
- return this.outerRadius() * 2;
54
- }
55
- getHeight() {
56
- return this.outerRadius() * 2;
57
- }
58
- setWidth(width: number) {
59
- this.outerRadius(width / 2);
60
- }
61
- setHeight(height: number) {
62
- this.outerRadius(height / 2);
63
- }
64
-
65
- getSelfRect() {
66
- const innerRadius = this.innerRadius();
67
- const outerRadius = this.outerRadius();
68
- const clockwise = this.clockwise();
69
- const angle = Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
70
-
71
- const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
72
- const boundRightRatio = 1;
73
- const boundTopRatio = Math.sin(
74
- Math.min(Math.max(Math.PI, angle), (3 * Math.PI) / 2)
75
- );
76
- const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
77
- const boundLeft =
78
- boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
79
- const boundRight =
80
- boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius);
81
- const boundTop =
82
- boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
83
- const boundBottom =
84
- boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
85
-
86
- return {
87
- x: boundLeft,
88
- y: clockwise ? -1 * boundBottom : boundTop,
89
- width: boundRight - boundLeft,
90
- height: boundBottom - boundTop,
91
- };
92
- }
93
-
94
- innerRadius: GetSet<number, this>;
95
- outerRadius: GetSet<number, this>;
96
- angle: GetSet<number, this>;
97
- clockwise: GetSet<boolean, this>;
98
- }
99
-
100
- Arc.prototype._centroid = true;
101
- Arc.prototype.className = 'Arc';
102
- Arc.prototype._attrsAffectingSize = [
103
- 'innerRadius',
104
- 'outerRadius',
105
- 'angle',
106
- 'clockwise',
107
- ];
108
- _registerNode(Arc);
109
-
110
- // add getters setters
111
- Factory.addGetterSetter(Arc, 'innerRadius', 0, getNumberValidator());
112
-
113
- /**
114
- * get/set innerRadius
115
- * @name Konva.Arc#innerRadius
116
- * @method
117
- * @param {Number} innerRadius
118
- * @returns {Number}
119
- * @example
120
- * // get inner radius
121
- * var innerRadius = arc.innerRadius();
122
- *
123
- * // set inner radius
124
- * arc.innerRadius(20);
125
- */
126
-
127
- Factory.addGetterSetter(Arc, 'outerRadius', 0, getNumberValidator());
128
-
129
- /**
130
- * get/set outerRadius
131
- * @name Konva.Arc#outerRadius
132
- * @method
133
- * @param {Number} outerRadius
134
- * @returns {Number}
135
- * @example
136
- * // get outer radius
137
- * var outerRadius = arc.outerRadius();
138
- *
139
- * // set outer radius
140
- * arc.outerRadius(20);
141
- */
142
-
143
- Factory.addGetterSetter(Arc, 'angle', 0, getNumberValidator());
144
-
145
- /**
146
- * get/set angle in degrees
147
- * @name Konva.Arc#angle
148
- * @method
149
- * @param {Number} angle
150
- * @returns {Number}
151
- * @example
152
- * // get angle
153
- * var angle = arc.angle();
154
- *
155
- * // set angle
156
- * arc.angle(20);
157
- */
158
-
159
- Factory.addGetterSetter(Arc, 'clockwise', false, getBooleanValidator());
160
-
161
- /**
162
- * get/set clockwise flag
163
- * @name Konva.Arc#clockwise
164
- * @method
165
- * @param {Boolean} clockwise
166
- * @returns {Boolean}
167
- * @example
168
- * // get clockwise flag
169
- * var clockwise = arc.clockwise();
170
- *
171
- * // draw arc counter-clockwise
172
- * arc.clockwise(false);
173
- *
174
- * // draw arc clockwise
175
- * arc.clockwise(true);
176
- */
@@ -1,231 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { LineConfig } from './Line.ts';
3
- import { Line } from './Line.ts';
4
- import type { GetSet } from '../types.ts';
5
- import { getNumberValidator } from '../Validators.ts';
6
- import { _registerNode } from '../Global.ts';
7
- import { Path } from './Path.ts';
8
- import type { Context } from '../Context.ts';
9
-
10
- export interface ArrowConfig extends LineConfig {
11
- points: number[];
12
- tension?: number;
13
- closed?: boolean;
14
- pointerLength?: number;
15
- pointerWidth?: number;
16
- pointerAtBeginning?: boolean;
17
- pointerAtEnding?: boolean;
18
- }
19
-
20
- /**
21
- * Arrow constructor
22
- * @constructor
23
- * @memberof Konva
24
- * @augments Konva.Line
25
- * @param {Object} config
26
- * @param {Array} config.points Flat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].
27
- * @param {Number} [config.tension] Higher values will result in a more curvy line. A value of 0 will result in no interpolation.
28
- * The default is 0
29
- * @param {Number} config.pointerLength Arrow pointer length. Default value is 10.
30
- * @param {Number} config.pointerWidth Arrow pointer width. Default value is 10.
31
- * @param {Boolean} config.pointerAtBeginning Do we need to draw pointer on beginning position?. Default false.
32
- * @param {Boolean} config.pointerAtEnding Do we need to draw pointer on ending position?. Default true.
33
- * @@shapeParams
34
- * @@nodeParams
35
- * @example
36
- * var line = new Konva.Line({
37
- * points: [73, 70, 340, 23, 450, 60, 500, 20],
38
- * stroke: 'red',
39
- * tension: 1,
40
- * pointerLength : 10,
41
- * pointerWidth : 12
42
- * });
43
- */
44
- export class Arrow extends Line<ArrowConfig> {
45
- _sceneFunc(ctx: Context) {
46
- super._sceneFunc(ctx);
47
- const PI2 = Math.PI * 2;
48
- const points = this.points();
49
-
50
- let tp = points;
51
- const fromTension = this.tension() !== 0 && points.length > 4;
52
- if (fromTension) {
53
- tp = this.getTensionPoints();
54
- }
55
- const length = this.pointerLength();
56
-
57
- const n = points.length;
58
-
59
- let dx, dy;
60
- if (fromTension) {
61
- const lp = [
62
- tp[tp.length - 4],
63
- tp[tp.length - 3],
64
- tp[tp.length - 2],
65
- tp[tp.length - 1],
66
- points[n - 2],
67
- points[n - 1],
68
- ];
69
- const lastLength = Path.calcLength(
70
- tp[tp.length - 4],
71
- tp[tp.length - 3],
72
- 'C',
73
- lp
74
- );
75
- const previous = Path.getPointOnQuadraticBezier(
76
- Math.min(1, 1 - length / lastLength),
77
- lp[0],
78
- lp[1],
79
- lp[2],
80
- lp[3],
81
- lp[4],
82
- lp[5]
83
- );
84
-
85
- dx = points[n - 2] - previous.x;
86
- dy = points[n - 1] - previous.y;
87
- } else {
88
- dx = points[n - 2] - points[n - 4];
89
- dy = points[n - 1] - points[n - 3];
90
- }
91
-
92
- const radians = (Math.atan2(dy, dx) + PI2) % PI2;
93
-
94
- const width = this.pointerWidth();
95
-
96
- if (this.pointerAtEnding()) {
97
- ctx.save();
98
- ctx.beginPath();
99
- ctx.translate(points[n - 2], points[n - 1]);
100
- ctx.rotate(radians);
101
- ctx.moveTo(0, 0);
102
- ctx.lineTo(-length, width / 2);
103
- ctx.lineTo(-length, -width / 2);
104
- ctx.closePath();
105
- ctx.restore();
106
- this.__fillStroke(ctx);
107
- }
108
-
109
- if (this.pointerAtBeginning()) {
110
- ctx.save();
111
- ctx.beginPath();
112
- ctx.translate(points[0], points[1]);
113
- if (fromTension) {
114
- dx = (tp[0] + tp[2]) / 2 - points[0];
115
- dy = (tp[1] + tp[3]) / 2 - points[1];
116
- } else {
117
- dx = points[2] - points[0];
118
- dy = points[3] - points[1];
119
- }
120
-
121
- ctx.rotate((Math.atan2(-dy, -dx) + PI2) % PI2);
122
- ctx.moveTo(0, 0);
123
- ctx.lineTo(-length, width / 2);
124
- ctx.lineTo(-length, -width / 2);
125
- ctx.closePath();
126
- ctx.restore();
127
- this.__fillStroke(ctx);
128
- }
129
- }
130
-
131
- __fillStroke(ctx: Context) {
132
- // here is a tricky part
133
- // we need to disable dash for arrow pointers
134
- const isDashEnabled = this.dashEnabled();
135
- if (isDashEnabled) {
136
- // manually disable dash for head
137
- // it is better not to use setter here,
138
- // because it will trigger attr change event
139
- this.attrs.dashEnabled = false;
140
- ctx.setLineDash([]);
141
- }
142
-
143
- ctx.fillStrokeShape(this);
144
-
145
- // restore old value
146
- if (isDashEnabled) {
147
- this.attrs.dashEnabled = true;
148
- }
149
- }
150
-
151
- getSelfRect() {
152
- const lineRect = super.getSelfRect();
153
- const offset = this.pointerWidth() / 2;
154
- return {
155
- x: lineRect.x,
156
- y: lineRect.y - offset,
157
- width: lineRect.width,
158
- height: lineRect.height + offset * 2,
159
- };
160
- }
161
-
162
- pointerLength: GetSet<number, this>;
163
- pointerWidth: GetSet<number, this>;
164
- pointerAtEnding: GetSet<boolean, this>;
165
- pointerAtBeginning: GetSet<boolean, this>;
166
- }
167
-
168
- Arrow.prototype.className = 'Arrow';
169
- _registerNode(Arrow);
170
-
171
- /**
172
- * get/set pointerLength
173
- * @name Konva.Arrow#pointerLength
174
- * @method
175
- * @param {Number} Length of pointer of arrow. The default is 10.
176
- * @returns {Number}
177
- * @example
178
- * // get length
179
- * var pointerLength = line.pointerLength();
180
- *
181
- * // set length
182
- * line.pointerLength(15);
183
- */
184
-
185
- Factory.addGetterSetter(Arrow, 'pointerLength', 10, getNumberValidator());
186
- /**
187
- * get/set pointerWidth
188
- * @name Konva.Arrow#pointerWidth
189
- * @method
190
- * @param {Number} Width of pointer of arrow.
191
- * The default is 10.
192
- * @returns {Number}
193
- * @example
194
- * // get width
195
- * var pointerWidth = line.pointerWidth();
196
- *
197
- * // set width
198
- * line.pointerWidth(15);
199
- */
200
-
201
- Factory.addGetterSetter(Arrow, 'pointerWidth', 10, getNumberValidator());
202
- /**
203
- * get/set pointerAtBeginning
204
- * @name Konva.Arrow#pointerAtBeginning
205
- * @method
206
- * @param {Number} Should pointer displayed at beginning of arrow. The default is false.
207
- * @returns {Boolean}
208
- * @example
209
- * // get value
210
- * var pointerAtBeginning = line.pointerAtBeginning();
211
- *
212
- * // set value
213
- * line.pointerAtBeginning(true);
214
- */
215
-
216
- Factory.addGetterSetter(Arrow, 'pointerAtBeginning', false);
217
- /**
218
- * get/set pointerAtEnding
219
- * @name Konva.Arrow#pointerAtEnding
220
- * @method
221
- * @param {Number} Should pointer displayed at ending of arrow. The default is true.
222
- * @returns {Boolean}
223
- * @example
224
- * // get value
225
- * var pointerAtEnding = line.pointerAtEnding();
226
- *
227
- * // set value
228
- * line.pointerAtEnding(false);
229
- */
230
-
231
- Factory.addGetterSetter(Arrow, 'pointerAtEnding', true);