konva 8.4.3 → 9.0.1

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 (192) hide show
  1. package/README.md +1 -9
  2. package/konva.js +17691 -16989
  3. package/konva.min.js +3 -3
  4. package/lib/Animation.js +11 -7
  5. package/lib/BezierFunctions.d.ts +6 -0
  6. package/lib/BezierFunctions.js +791 -0
  7. package/lib/Canvas.d.ts +1 -0
  8. package/lib/Canvas.js +26 -18
  9. package/lib/Container.js +16 -12
  10. package/lib/Context.d.ts +3 -1
  11. package/lib/Context.js +18 -10
  12. package/lib/Core.js +7 -3
  13. package/lib/DragAndDrop.js +25 -22
  14. package/lib/Factory.js +27 -24
  15. package/lib/FastLayer.js +10 -6
  16. package/lib/Global.js +16 -12
  17. package/lib/Group.js +10 -6
  18. package/lib/Layer.js +37 -33
  19. package/lib/Node.d.ts +1 -0
  20. package/lib/Node.js +105 -104
  21. package/lib/PointerEvents.js +15 -7
  22. package/lib/Shape.js +90 -86
  23. package/lib/Stage.js +51 -47
  24. package/lib/Tween.js +26 -22
  25. package/lib/Util.js +29 -25
  26. package/lib/Validators.js +58 -44
  27. package/lib/_CoreInternals.js +36 -33
  28. package/lib/_FullInternals.js +78 -75
  29. package/lib/filters/Blur.js +9 -5
  30. package/lib/filters/Brighten.js +9 -5
  31. package/lib/filters/Contrast.js +9 -5
  32. package/lib/filters/Emboss.js +14 -10
  33. package/lib/filters/Enhance.js +9 -5
  34. package/lib/filters/Grayscale.js +5 -1
  35. package/lib/filters/HSL.js +11 -7
  36. package/lib/filters/HSV.js +11 -7
  37. package/lib/filters/Invert.js +5 -1
  38. package/lib/filters/Kaleidoscope.js +13 -9
  39. package/lib/filters/Mask.js +9 -5
  40. package/lib/filters/Noise.js +9 -5
  41. package/lib/filters/Pixelate.js +11 -7
  42. package/lib/filters/Posterize.js +9 -5
  43. package/lib/filters/RGB.js +11 -7
  44. package/lib/filters/RGBA.js +12 -8
  45. package/lib/filters/Sepia.js +5 -1
  46. package/lib/filters/Solarize.js +5 -1
  47. package/lib/filters/Threshold.js +9 -5
  48. package/lib/index-node.js +7 -5
  49. package/lib/index.js +4 -2
  50. package/lib/shapes/Arc.js +17 -13
  51. package/lib/shapes/Arrow.js +17 -13
  52. package/lib/shapes/Circle.js +11 -7
  53. package/lib/shapes/Ellipse.js +13 -9
  54. package/lib/shapes/Image.js +21 -17
  55. package/lib/shapes/Label.js +18 -13
  56. package/lib/shapes/Line.js +14 -10
  57. package/lib/shapes/Path.d.ts +5 -2
  58. package/lib/shapes/Path.js +44 -43
  59. package/lib/shapes/Rect.js +13 -9
  60. package/lib/shapes/RegularPolygon.js +12 -8
  61. package/lib/shapes/Ring.js +12 -8
  62. package/lib/shapes/Sprite.js +19 -15
  63. package/lib/shapes/Star.js +13 -9
  64. package/lib/shapes/Text.js +31 -26
  65. package/lib/shapes/TextPath.d.ts +5 -1
  66. package/lib/shapes/TextPath.js +82 -188
  67. package/lib/shapes/Transformer.d.ts +2 -0
  68. package/lib/shapes/Transformer.js +97 -82
  69. package/lib/shapes/Wedge.js +16 -12
  70. package/lib/types.d.ts +6 -0
  71. package/lib/types.js +5 -2
  72. package/package.json +13 -42
  73. package/cmj/Animation.d.ts +0 -24
  74. package/cmj/Animation.js +0 -145
  75. package/cmj/Canvas.d.ts +0 -32
  76. package/cmj/Canvas.js +0 -114
  77. package/cmj/Container.d.ts +0 -47
  78. package/cmj/Container.js +0 -325
  79. package/cmj/Context.d.ts +0 -85
  80. package/cmj/Context.js +0 -538
  81. package/cmj/Core.d.ts +0 -3
  82. package/cmj/Core.js +0 -7
  83. package/cmj/DragAndDrop.d.ts +0 -17
  84. package/cmj/DragAndDrop.js +0 -111
  85. package/cmj/Factory.d.ts +0 -11
  86. package/cmj/Factory.js +0 -125
  87. package/cmj/FastLayer.d.ts +0 -4
  88. package/cmj/FastLayer.js +0 -16
  89. package/cmj/Global.d.ts +0 -34
  90. package/cmj/Global.js +0 -61
  91. package/cmj/Group.d.ts +0 -8
  92. package/cmj/Group.js +0 -17
  93. package/cmj/Layer.d.ts +0 -61
  94. package/cmj/Layer.js +0 -309
  95. package/cmj/Node.d.ts +0 -328
  96. package/cmj/Node.js +0 -1420
  97. package/cmj/PointerEvents.d.ts +0 -11
  98. package/cmj/PointerEvents.js +0 -45
  99. package/cmj/Shape.d.ts +0 -186
  100. package/cmj/Shape.js +0 -521
  101. package/cmj/Stage.d.ts +0 -85
  102. package/cmj/Stage.js +0 -692
  103. package/cmj/Tween.d.ts +0 -86
  104. package/cmj/Tween.js +0 -520
  105. package/cmj/Util.d.ts +0 -91
  106. package/cmj/Util.js +0 -801
  107. package/cmj/Validators.d.ts +0 -11
  108. package/cmj/Validators.js +0 -192
  109. package/cmj/_CoreInternals.d.ts +0 -152
  110. package/cmj/_CoreInternals.js +0 -37
  111. package/cmj/_FullInternals.d.ts +0 -196
  112. package/cmj/_FullInternals.js +0 -81
  113. package/cmj/filters/Blur.d.ts +0 -2
  114. package/cmj/filters/Blur.js +0 -701
  115. package/cmj/filters/Brighten.d.ts +0 -2
  116. package/cmj/filters/Brighten.js +0 -16
  117. package/cmj/filters/Contrast.d.ts +0 -2
  118. package/cmj/filters/Contrast.js +0 -38
  119. package/cmj/filters/Emboss.d.ts +0 -2
  120. package/cmj/filters/Emboss.js +0 -106
  121. package/cmj/filters/Enhance.d.ts +0 -2
  122. package/cmj/filters/Enhance.js +0 -87
  123. package/cmj/filters/Grayscale.d.ts +0 -2
  124. package/cmj/filters/Grayscale.js +0 -13
  125. package/cmj/filters/HSL.d.ts +0 -2
  126. package/cmj/filters/HSL.js +0 -28
  127. package/cmj/filters/HSV.d.ts +0 -2
  128. package/cmj/filters/HSV.js +0 -28
  129. package/cmj/filters/Invert.d.ts +0 -2
  130. package/cmj/filters/Invert.js +0 -12
  131. package/cmj/filters/Kaleidoscope.d.ts +0 -2
  132. package/cmj/filters/Kaleidoscope.js +0 -137
  133. package/cmj/filters/Mask.d.ts +0 -2
  134. package/cmj/filters/Mask.js +0 -144
  135. package/cmj/filters/Noise.d.ts +0 -2
  136. package/cmj/filters/Noise.js +0 -16
  137. package/cmj/filters/Pixelate.d.ts +0 -2
  138. package/cmj/filters/Pixelate.js +0 -64
  139. package/cmj/filters/Posterize.d.ts +0 -2
  140. package/cmj/filters/Posterize.js +0 -14
  141. package/cmj/filters/RGB.d.ts +0 -2
  142. package/cmj/filters/RGB.js +0 -43
  143. package/cmj/filters/RGBA.d.ts +0 -2
  144. package/cmj/filters/RGBA.js +0 -53
  145. package/cmj/filters/Sepia.d.ts +0 -2
  146. package/cmj/filters/Sepia.js +0 -15
  147. package/cmj/filters/Solarize.d.ts +0 -2
  148. package/cmj/filters/Solarize.js +0 -29
  149. package/cmj/filters/Threshold.d.ts +0 -2
  150. package/cmj/filters/Threshold.js +0 -14
  151. package/cmj/index-node.d.ts +0 -2
  152. package/cmj/index-node.js +0 -21
  153. package/cmj/index-types.d.ts +0 -181
  154. package/cmj/index.d.ts +0 -2
  155. package/cmj/index.js +0 -4
  156. package/cmj/package.json +0 -6
  157. package/cmj/shapes/Arc.d.ts +0 -26
  158. package/cmj/shapes/Arc.js +0 -59
  159. package/cmj/shapes/Arrow.d.ts +0 -26
  160. package/cmj/shapes/Arrow.js +0 -103
  161. package/cmj/shapes/Circle.d.ts +0 -14
  162. package/cmj/shapes/Circle.js +0 -37
  163. package/cmj/shapes/Ellipse.d.ts +0 -17
  164. package/cmj/shapes/Ellipse.js +0 -41
  165. package/cmj/shapes/Image.d.ts +0 -25
  166. package/cmj/shapes/Image.js +0 -117
  167. package/cmj/shapes/Label.d.ts +0 -36
  168. package/cmj/shapes/Label.js +0 -178
  169. package/cmj/shapes/Line.d.ts +0 -28
  170. package/cmj/shapes/Line.js +0 -159
  171. package/cmj/shapes/Path.d.ts +0 -37
  172. package/cmj/shapes/Path.js +0 -631
  173. package/cmj/shapes/Rect.d.ts +0 -10
  174. package/cmj/shapes/Rect.js +0 -26
  175. package/cmj/shapes/RegularPolygon.d.ts +0 -23
  176. package/cmj/shapes/RegularPolygon.js +0 -69
  177. package/cmj/shapes/Ring.d.ts +0 -16
  178. package/cmj/shapes/Ring.js +0 -37
  179. package/cmj/shapes/Sprite.d.ts +0 -31
  180. package/cmj/shapes/Sprite.js +0 -112
  181. package/cmj/shapes/Star.d.ts +0 -18
  182. package/cmj/shapes/Star.js +0 -42
  183. package/cmj/shapes/Text.d.ts +0 -63
  184. package/cmj/shapes/Text.js +0 -373
  185. package/cmj/shapes/TextPath.d.ts +0 -56
  186. package/cmj/shapes/TextPath.js +0 -351
  187. package/cmj/shapes/Transformer.d.ts +0 -116
  188. package/cmj/shapes/Transformer.js +0 -971
  189. package/cmj/shapes/Wedge.d.ts +0 -18
  190. package/cmj/shapes/Wedge.js +0 -42
  191. package/cmj/types.d.ts +0 -50
  192. package/cmj/types.js +0 -25
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Arrow = void 0;
4
- const Factory_1 = require("../Factory");
5
- const Line_1 = require("./Line");
6
- const Validators_1 = require("../Validators");
7
- const Global_1 = require("../Global");
8
- const Path_1 = require("./Path");
9
- class Arrow extends Line_1.Line {
10
- _sceneFunc(ctx) {
11
- super._sceneFunc(ctx);
12
- var PI2 = Math.PI * 2;
13
- var points = this.points();
14
- var tp = points;
15
- var fromTension = this.tension() !== 0 && points.length > 4;
16
- if (fromTension) {
17
- tp = this.getTensionPoints();
18
- }
19
- var length = this.pointerLength();
20
- var n = points.length;
21
- var dx, dy;
22
- if (fromTension) {
23
- const lp = [
24
- tp[tp.length - 4],
25
- tp[tp.length - 3],
26
- tp[tp.length - 2],
27
- tp[tp.length - 1],
28
- points[n - 2],
29
- points[n - 1],
30
- ];
31
- const lastLength = Path_1.Path.calcLength(tp[tp.length - 4], tp[tp.length - 3], 'C', lp);
32
- const previous = Path_1.Path.getPointOnQuadraticBezier(Math.min(1, 1 - length / lastLength), lp[0], lp[1], lp[2], lp[3], lp[4], lp[5]);
33
- dx = points[n - 2] - previous.x;
34
- dy = points[n - 1] - previous.y;
35
- }
36
- else {
37
- dx = points[n - 2] - points[n - 4];
38
- dy = points[n - 1] - points[n - 3];
39
- }
40
- var radians = (Math.atan2(dy, dx) + PI2) % PI2;
41
- var width = this.pointerWidth();
42
- if (this.pointerAtEnding()) {
43
- ctx.save();
44
- ctx.beginPath();
45
- ctx.translate(points[n - 2], points[n - 1]);
46
- ctx.rotate(radians);
47
- ctx.moveTo(0, 0);
48
- ctx.lineTo(-length, width / 2);
49
- ctx.lineTo(-length, -width / 2);
50
- ctx.closePath();
51
- ctx.restore();
52
- this.__fillStroke(ctx);
53
- }
54
- if (this.pointerAtBeginning()) {
55
- ctx.save();
56
- ctx.beginPath();
57
- ctx.translate(points[0], points[1]);
58
- if (fromTension) {
59
- dx = (tp[0] + tp[2]) / 2 - points[0];
60
- dy = (tp[1] + tp[3]) / 2 - points[1];
61
- }
62
- else {
63
- dx = points[2] - points[0];
64
- dy = points[3] - points[1];
65
- }
66
- ctx.rotate((Math.atan2(-dy, -dx) + PI2) % PI2);
67
- ctx.moveTo(0, 0);
68
- ctx.lineTo(-length, width / 2);
69
- ctx.lineTo(-length, -width / 2);
70
- ctx.closePath();
71
- ctx.restore();
72
- this.__fillStroke(ctx);
73
- }
74
- }
75
- __fillStroke(ctx) {
76
- var isDashEnabled = this.dashEnabled();
77
- if (isDashEnabled) {
78
- this.attrs.dashEnabled = false;
79
- ctx.setLineDash([]);
80
- }
81
- ctx.fillStrokeShape(this);
82
- if (isDashEnabled) {
83
- this.attrs.dashEnabled = true;
84
- }
85
- }
86
- getSelfRect() {
87
- const lineRect = super.getSelfRect();
88
- const offset = this.pointerWidth() / 2;
89
- return {
90
- x: lineRect.x - offset,
91
- y: lineRect.y - offset,
92
- width: lineRect.width + offset * 2,
93
- height: lineRect.height + offset * 2,
94
- };
95
- }
96
- }
97
- exports.Arrow = Arrow;
98
- Arrow.prototype.className = 'Arrow';
99
- (0, Global_1._registerNode)(Arrow);
100
- Factory_1.Factory.addGetterSetter(Arrow, 'pointerLength', 10, (0, Validators_1.getNumberValidator)());
101
- Factory_1.Factory.addGetterSetter(Arrow, 'pointerWidth', 10, (0, Validators_1.getNumberValidator)());
102
- Factory_1.Factory.addGetterSetter(Arrow, 'pointerAtBeginning', false);
103
- Factory_1.Factory.addGetterSetter(Arrow, 'pointerAtEnding', true);
@@ -1,14 +0,0 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet } from '../types';
3
- import { Context } from '../Context';
4
- export interface CircleConfig extends ShapeConfig {
5
- radius?: number;
6
- }
7
- export declare class Circle extends Shape<CircleConfig> {
8
- _sceneFunc(context: Context): void;
9
- getWidth(): number;
10
- getHeight(): number;
11
- setWidth(width: number): void;
12
- setHeight(height: number): void;
13
- radius: GetSet<number, this>;
14
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Circle = void 0;
4
- const Factory_1 = require("../Factory");
5
- const Shape_1 = require("../Shape");
6
- const Validators_1 = require("../Validators");
7
- const Global_1 = require("../Global");
8
- class Circle extends Shape_1.Shape {
9
- _sceneFunc(context) {
10
- context.beginPath();
11
- context.arc(0, 0, this.attrs.radius || 0, 0, Math.PI * 2, false);
12
- context.closePath();
13
- context.fillStrokeShape(this);
14
- }
15
- getWidth() {
16
- return this.radius() * 2;
17
- }
18
- getHeight() {
19
- return this.radius() * 2;
20
- }
21
- setWidth(width) {
22
- if (this.radius() !== width / 2) {
23
- this.radius(width / 2);
24
- }
25
- }
26
- setHeight(height) {
27
- if (this.radius() !== height / 2) {
28
- this.radius(height / 2);
29
- }
30
- }
31
- }
32
- exports.Circle = Circle;
33
- Circle.prototype._centroid = true;
34
- Circle.prototype.className = 'Circle';
35
- Circle.prototype._attrsAffectingSize = ['radius'];
36
- (0, Global_1._registerNode)(Circle);
37
- Factory_1.Factory.addGetterSetter(Circle, 'radius', 0, (0, Validators_1.getNumberValidator)());
@@ -1,17 +0,0 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { Context } from '../Context';
3
- import { GetSet, Vector2d } from '../types';
4
- export interface EllipseConfig extends ShapeConfig {
5
- radiusX: number;
6
- radiusY: number;
7
- }
8
- export declare class Ellipse extends Shape<EllipseConfig> {
9
- _sceneFunc(context: Context): void;
10
- getWidth(): number;
11
- getHeight(): number;
12
- setWidth(width: number): void;
13
- setHeight(height: number): void;
14
- radius: GetSet<Vector2d, this>;
15
- radiusX: GetSet<number, this>;
16
- radiusY: GetSet<number, this>;
17
- }
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Ellipse = void 0;
4
- const Factory_1 = require("../Factory");
5
- const Shape_1 = require("../Shape");
6
- const Validators_1 = require("../Validators");
7
- const Global_1 = require("../Global");
8
- class Ellipse extends Shape_1.Shape {
9
- _sceneFunc(context) {
10
- var rx = this.radiusX(), ry = this.radiusY();
11
- context.beginPath();
12
- context.save();
13
- if (rx !== ry) {
14
- context.scale(1, ry / rx);
15
- }
16
- context.arc(0, 0, rx, 0, Math.PI * 2, false);
17
- context.restore();
18
- context.closePath();
19
- context.fillStrokeShape(this);
20
- }
21
- getWidth() {
22
- return this.radiusX() * 2;
23
- }
24
- getHeight() {
25
- return this.radiusY() * 2;
26
- }
27
- setWidth(width) {
28
- this.radiusX(width / 2);
29
- }
30
- setHeight(height) {
31
- this.radiusY(height / 2);
32
- }
33
- }
34
- exports.Ellipse = Ellipse;
35
- Ellipse.prototype.className = 'Ellipse';
36
- Ellipse.prototype._centroid = true;
37
- Ellipse.prototype._attrsAffectingSize = ['radiusX', 'radiusY'];
38
- (0, Global_1._registerNode)(Ellipse);
39
- Factory_1.Factory.addComponentsGetterSetter(Ellipse, 'radius', ['x', 'y']);
40
- Factory_1.Factory.addGetterSetter(Ellipse, 'radiusX', 0, (0, Validators_1.getNumberValidator)());
41
- Factory_1.Factory.addGetterSetter(Ellipse, 'radiusY', 0, (0, Validators_1.getNumberValidator)());
@@ -1,25 +0,0 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet, IRect } from '../types';
3
- import { Context } from '../Context';
4
- export interface ImageConfig extends ShapeConfig {
5
- image: CanvasImageSource | undefined;
6
- crop?: IRect;
7
- cornerRadius?: number | number[];
8
- }
9
- export declare class Image extends Shape<ImageConfig> {
10
- constructor(attrs: ImageConfig);
11
- _setImageLoad(): void;
12
- _useBufferCanvas(): boolean;
13
- _sceneFunc(context: Context): void;
14
- _hitFunc(context: Context): void;
15
- getWidth(): any;
16
- getHeight(): any;
17
- static fromURL(url: string, callback: (img: Image) => void, onError?: OnErrorEventHandler): void;
18
- image: GetSet<CanvasImageSource | undefined, this>;
19
- crop: GetSet<IRect, this>;
20
- cropX: GetSet<number, this>;
21
- cropY: GetSet<number, this>;
22
- cropWidth: GetSet<number, this>;
23
- cropHeight: GetSet<number, this>;
24
- cornerRadius: GetSet<number | number[], this>;
25
- }
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Image = void 0;
4
- const Util_1 = require("../Util");
5
- const Factory_1 = require("../Factory");
6
- const Shape_1 = require("../Shape");
7
- const Global_1 = require("../Global");
8
- const Validators_1 = require("../Validators");
9
- class Image extends Shape_1.Shape {
10
- constructor(attrs) {
11
- super(attrs);
12
- this.on('imageChange.konva', () => {
13
- this._setImageLoad();
14
- });
15
- this._setImageLoad();
16
- }
17
- _setImageLoad() {
18
- const image = this.image();
19
- if (image && image.complete) {
20
- return;
21
- }
22
- if (image && image.readyState === 4) {
23
- return;
24
- }
25
- if (image && image['addEventListener']) {
26
- image['addEventListener']('load', () => {
27
- this._requestDraw();
28
- });
29
- }
30
- }
31
- _useBufferCanvas() {
32
- return super._useBufferCanvas(true);
33
- }
34
- _sceneFunc(context) {
35
- const width = this.getWidth();
36
- const height = this.getHeight();
37
- const cornerRadius = this.cornerRadius();
38
- const image = this.attrs.image;
39
- let params;
40
- if (image) {
41
- const cropWidth = this.attrs.cropWidth;
42
- const cropHeight = this.attrs.cropHeight;
43
- if (cropWidth && cropHeight) {
44
- params = [
45
- image,
46
- this.cropX(),
47
- this.cropY(),
48
- cropWidth,
49
- cropHeight,
50
- 0,
51
- 0,
52
- width,
53
- height,
54
- ];
55
- }
56
- else {
57
- params = [image, 0, 0, width, height];
58
- }
59
- }
60
- if (this.hasFill() || this.hasStroke() || cornerRadius) {
61
- context.beginPath();
62
- cornerRadius
63
- ? Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius)
64
- : context.rect(0, 0, width, height);
65
- context.closePath();
66
- context.fillStrokeShape(this);
67
- }
68
- if (image) {
69
- if (cornerRadius) {
70
- context.clip();
71
- }
72
- context.drawImage.apply(context, params);
73
- }
74
- }
75
- _hitFunc(context) {
76
- var width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
77
- context.beginPath();
78
- if (!cornerRadius) {
79
- context.rect(0, 0, width, height);
80
- }
81
- else {
82
- Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius);
83
- }
84
- context.closePath();
85
- context.fillStrokeShape(this);
86
- }
87
- getWidth() {
88
- var _a, _b;
89
- return (_a = this.attrs.width) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.width;
90
- }
91
- getHeight() {
92
- var _a, _b;
93
- return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
94
- }
95
- static fromURL(url, callback, onError = null) {
96
- var img = Util_1.Util.createImageElement();
97
- img.onload = function () {
98
- var image = new Image({
99
- image: img,
100
- });
101
- callback(image);
102
- };
103
- img.onerror = onError;
104
- img.crossOrigin = 'Anonymous';
105
- img.src = url;
106
- }
107
- }
108
- exports.Image = Image;
109
- Image.prototype.className = 'Image';
110
- (0, Global_1._registerNode)(Image);
111
- Factory_1.Factory.addGetterSetter(Image, 'cornerRadius', 0, (0, Validators_1.getNumberOrArrayOfNumbersValidator)(4));
112
- Factory_1.Factory.addGetterSetter(Image, 'image');
113
- Factory_1.Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
114
- Factory_1.Factory.addGetterSetter(Image, 'cropX', 0, (0, Validators_1.getNumberValidator)());
115
- Factory_1.Factory.addGetterSetter(Image, 'cropY', 0, (0, Validators_1.getNumberValidator)());
116
- Factory_1.Factory.addGetterSetter(Image, 'cropWidth', 0, (0, Validators_1.getNumberValidator)());
117
- Factory_1.Factory.addGetterSetter(Image, 'cropHeight', 0, (0, Validators_1.getNumberValidator)());
@@ -1,36 +0,0 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { Group } from '../Group';
3
- import { Context } from '../Context';
4
- import { ContainerConfig } from '../Container';
5
- import { GetSet } from '../types';
6
- import { Text } from './Text';
7
- export interface LabelConfig extends ContainerConfig {
8
- }
9
- export declare class Label extends Group {
10
- constructor(config?: LabelConfig);
11
- getText(): Text;
12
- getTag(): Tag;
13
- _addListeners(text: any): void;
14
- getWidth(): number;
15
- getHeight(): number;
16
- _sync(): void;
17
- }
18
- export interface TagConfig extends ShapeConfig {
19
- pointerDirection?: string;
20
- pointerWidth?: number;
21
- pointerHeight?: number;
22
- cornerRadius?: number | Array<number>;
23
- }
24
- export declare class Tag extends Shape<TagConfig> {
25
- _sceneFunc(context: Context): void;
26
- getSelfRect(): {
27
- x: number;
28
- y: number;
29
- width: number;
30
- height: number;
31
- };
32
- pointerDirection: GetSet<'left' | 'top' | 'right' | 'bottom', this>;
33
- pointerWidth: GetSet<number, this>;
34
- pointerHeight: GetSet<number, this>;
35
- cornerRadius: GetSet<number, this>;
36
- }
@@ -1,178 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tag = exports.Label = void 0;
4
- const Factory_1 = require("../Factory");
5
- const Shape_1 = require("../Shape");
6
- const Group_1 = require("../Group");
7
- const Validators_1 = require("../Validators");
8
- const Global_1 = require("../Global");
9
- var ATTR_CHANGE_LIST = [
10
- 'fontFamily',
11
- 'fontSize',
12
- 'fontStyle',
13
- 'padding',
14
- 'lineHeight',
15
- 'text',
16
- 'width',
17
- 'height',
18
- 'pointerDirection',
19
- 'pointerWidth',
20
- 'pointerHeight',
21
- ], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left', attrChangeListLen = ATTR_CHANGE_LIST.length;
22
- class Label extends Group_1.Group {
23
- constructor(config) {
24
- super(config);
25
- this.on('add.konva', function (evt) {
26
- this._addListeners(evt.child);
27
- this._sync();
28
- });
29
- }
30
- getText() {
31
- return this.find('Text')[0];
32
- }
33
- getTag() {
34
- return this.find('Tag')[0];
35
- }
36
- _addListeners(text) {
37
- var that = this, n;
38
- var func = function () {
39
- that._sync();
40
- };
41
- for (n = 0; n < attrChangeListLen; n++) {
42
- text.on(ATTR_CHANGE_LIST[n] + CHANGE_KONVA, func);
43
- }
44
- }
45
- getWidth() {
46
- return this.getText().width();
47
- }
48
- getHeight() {
49
- return this.getText().height();
50
- }
51
- _sync() {
52
- var text = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight;
53
- if (text && tag) {
54
- width = text.width();
55
- height = text.height();
56
- pointerDirection = tag.pointerDirection();
57
- pointerWidth = tag.pointerWidth();
58
- pointerHeight = tag.pointerHeight();
59
- x = 0;
60
- y = 0;
61
- switch (pointerDirection) {
62
- case UP:
63
- x = width / 2;
64
- y = -1 * pointerHeight;
65
- break;
66
- case RIGHT:
67
- x = width + pointerWidth;
68
- y = height / 2;
69
- break;
70
- case DOWN:
71
- x = width / 2;
72
- y = height + pointerHeight;
73
- break;
74
- case LEFT:
75
- x = -1 * pointerWidth;
76
- y = height / 2;
77
- break;
78
- }
79
- tag.setAttrs({
80
- x: -1 * x,
81
- y: -1 * y,
82
- width: width,
83
- height: height,
84
- });
85
- text.setAttrs({
86
- x: -1 * x,
87
- y: -1 * y,
88
- });
89
- }
90
- }
91
- }
92
- exports.Label = Label;
93
- Label.prototype.className = 'Label';
94
- (0, Global_1._registerNode)(Label);
95
- class Tag extends Shape_1.Shape {
96
- _sceneFunc(context) {
97
- var width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
98
- let topLeft = 0;
99
- let topRight = 0;
100
- let bottomLeft = 0;
101
- let bottomRight = 0;
102
- if (typeof cornerRadius === 'number') {
103
- topLeft =
104
- topRight =
105
- bottomLeft =
106
- bottomRight =
107
- Math.min(cornerRadius, width / 2, height / 2);
108
- }
109
- else {
110
- topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
111
- topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
112
- bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
113
- bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
114
- }
115
- context.beginPath();
116
- context.moveTo(topLeft, 0);
117
- if (pointerDirection === UP) {
118
- context.lineTo((width - pointerWidth) / 2, 0);
119
- context.lineTo(width / 2, -1 * pointerHeight);
120
- context.lineTo((width + pointerWidth) / 2, 0);
121
- }
122
- context.lineTo(width - topRight, 0);
123
- context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
124
- if (pointerDirection === RIGHT) {
125
- context.lineTo(width, (height - pointerHeight) / 2);
126
- context.lineTo(width + pointerWidth, height / 2);
127
- context.lineTo(width, (height + pointerHeight) / 2);
128
- }
129
- context.lineTo(width, height - bottomRight);
130
- context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
131
- if (pointerDirection === DOWN) {
132
- context.lineTo((width + pointerWidth) / 2, height);
133
- context.lineTo(width / 2, height + pointerHeight);
134
- context.lineTo((width - pointerWidth) / 2, height);
135
- }
136
- context.lineTo(bottomLeft, height);
137
- context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
138
- if (pointerDirection === LEFT) {
139
- context.lineTo(0, (height + pointerHeight) / 2);
140
- context.lineTo(-1 * pointerWidth, height / 2);
141
- context.lineTo(0, (height - pointerHeight) / 2);
142
- }
143
- context.lineTo(0, topLeft);
144
- context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
145
- context.closePath();
146
- context.fillStrokeShape(this);
147
- }
148
- getSelfRect() {
149
- var x = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();
150
- if (direction === UP) {
151
- y -= pointerHeight;
152
- height += pointerHeight;
153
- }
154
- else if (direction === DOWN) {
155
- height += pointerHeight;
156
- }
157
- else if (direction === LEFT) {
158
- x -= pointerWidth * 1.5;
159
- width += pointerWidth;
160
- }
161
- else if (direction === RIGHT) {
162
- width += pointerWidth * 1.5;
163
- }
164
- return {
165
- x: x,
166
- y: y,
167
- width: width,
168
- height: height,
169
- };
170
- }
171
- }
172
- exports.Tag = Tag;
173
- Tag.prototype.className = 'Tag';
174
- (0, Global_1._registerNode)(Tag);
175
- Factory_1.Factory.addGetterSetter(Tag, 'pointerDirection', NONE);
176
- Factory_1.Factory.addGetterSetter(Tag, 'pointerWidth', 0, (0, Validators_1.getNumberValidator)());
177
- Factory_1.Factory.addGetterSetter(Tag, 'pointerHeight', 0, (0, Validators_1.getNumberValidator)());
178
- Factory_1.Factory.addGetterSetter(Tag, 'cornerRadius', 0, (0, Validators_1.getNumberOrArrayOfNumbersValidator)(4));
@@ -1,28 +0,0 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet } from '../types';
3
- import { Context } from '../Context';
4
- export interface LineConfig extends ShapeConfig {
5
- points?: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
6
- tension?: number;
7
- closed?: boolean;
8
- bezier?: boolean;
9
- }
10
- export declare class Line<Config extends LineConfig = LineConfig> extends Shape<Config> {
11
- constructor(config?: Config);
12
- _sceneFunc(context: Context): void;
13
- getTensionPoints(): any;
14
- _getTensionPoints(): any[];
15
- _getTensionPointsClosed(): any[];
16
- getWidth(): number;
17
- getHeight(): number;
18
- getSelfRect(): {
19
- x: number;
20
- y: number;
21
- width: number;
22
- height: number;
23
- };
24
- closed: GetSet<boolean, this>;
25
- bezier: GetSet<boolean, this>;
26
- tension: GetSet<number, this>;
27
- points: GetSet<number[], this>;
28
- }