konva 10.3.3 → 10.4.0

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 (123) hide show
  1. package/README.md +1 -1
  2. package/konva.js +1327 -1572
  3. package/konva.min.js +4 -4
  4. package/lib/Animation.d.ts +63 -3
  5. package/lib/Animation.js +86 -65
  6. package/lib/BezierFunctions.d.ts +10 -0
  7. package/lib/BezierFunctions.js +32 -0
  8. package/lib/Canvas.d.ts +53 -0
  9. package/lib/Canvas.js +93 -34
  10. package/lib/Container.d.ts +156 -9
  11. package/lib/Container.js +260 -25
  12. package/lib/Context.d.ts +247 -0
  13. package/lib/Context.js +312 -74
  14. package/lib/Core.js +1 -0
  15. package/lib/DragAndDrop.d.ts +1 -0
  16. package/lib/DragAndDrop.js +66 -17
  17. package/lib/Factory.d.ts +24 -1
  18. package/lib/Factory.js +14 -20
  19. package/lib/FastLayer.d.ts +14 -1
  20. package/lib/FastLayer.js +14 -1
  21. package/lib/Global.d.ts +114 -3
  22. package/lib/Global.js +134 -5
  23. package/lib/Group.d.ts +11 -0
  24. package/lib/Group.js +11 -0
  25. package/lib/Layer.d.ts +128 -3
  26. package/lib/Layer.js +260 -49
  27. package/lib/Node.d.ts +692 -30
  28. package/lib/Node.js +1534 -202
  29. package/lib/PointerEvents.d.ts +2 -1
  30. package/lib/PointerEvents.js +19 -1
  31. package/lib/Shape.d.ts +99 -14
  32. package/lib/Shape.js +1101 -67
  33. package/lib/Stage.d.ts +81 -1
  34. package/lib/Stage.js +166 -7
  35. package/lib/Tween.d.ts +159 -4
  36. package/lib/Tween.js +243 -24
  37. package/lib/Util.d.ts +147 -4
  38. package/lib/Util.js +332 -82
  39. package/lib/Validators.d.ts +0 -2
  40. package/lib/Validators.js +3 -25
  41. package/lib/_CoreInternals.d.ts +10 -6
  42. package/lib/_CoreInternals.js +1 -0
  43. package/lib/_FullInternals.d.ts +15 -6
  44. package/lib/_FullInternals.js +7 -0
  45. package/lib/canvas-backend.js +6 -0
  46. package/lib/filters/Blur.d.ts +18 -0
  47. package/lib/filters/Blur.js +97 -24
  48. package/lib/filters/Brighten.d.ts +21 -0
  49. package/lib/filters/Brighten.js +24 -0
  50. package/lib/filters/Brightness.d.ts +11 -0
  51. package/lib/filters/Brightness.js +16 -0
  52. package/lib/filters/Contrast.d.ts +10 -0
  53. package/lib/filters/Contrast.js +21 -0
  54. package/lib/filters/Emboss.d.ts +20 -0
  55. package/lib/filters/Emboss.js +68 -8
  56. package/lib/filters/Enhance.d.ts +14 -0
  57. package/lib/filters/Enhance.js +34 -0
  58. package/lib/filters/Grayscale.d.ts +9 -0
  59. package/lib/filters/Grayscale.js +12 -0
  60. package/lib/filters/HSL.d.ts +17 -0
  61. package/lib/filters/HSL.js +48 -5
  62. package/lib/filters/HSV.d.ts +18 -0
  63. package/lib/filters/HSV.js +49 -5
  64. package/lib/filters/Invert.d.ts +9 -0
  65. package/lib/filters/Invert.js +12 -0
  66. package/lib/filters/Kaleidoscope.d.ts +12 -0
  67. package/lib/filters/Kaleidoscope.js +83 -0
  68. package/lib/filters/Mask.d.ts +11 -0
  69. package/lib/filters/Mask.js +18 -0
  70. package/lib/filters/Noise.d.ts +19 -0
  71. package/lib/filters/Noise.js +19 -0
  72. package/lib/filters/Pixelate.d.ts +20 -0
  73. package/lib/filters/Pixelate.js +28 -1
  74. package/lib/filters/Posterize.d.ts +21 -0
  75. package/lib/filters/Posterize.js +22 -0
  76. package/lib/filters/RGB.d.ts +21 -0
  77. package/lib/filters/RGB.js +43 -28
  78. package/lib/filters/RGBA.d.ts +23 -0
  79. package/lib/filters/RGBA.js +28 -41
  80. package/lib/filters/Sepia.d.ts +9 -0
  81. package/lib/filters/Sepia.js +10 -0
  82. package/lib/filters/Solarize.d.ts +10 -0
  83. package/lib/filters/Solarize.js +11 -0
  84. package/lib/filters/Threshold.d.ts +22 -0
  85. package/lib/filters/Threshold.js +22 -0
  86. package/lib/shapes/Arc.d.ts +40 -0
  87. package/lib/shapes/Arc.js +89 -6
  88. package/lib/shapes/Arrow.d.ts +24 -1
  89. package/lib/shapes/Arrow.js +83 -0
  90. package/lib/shapes/Circle.d.ts +18 -0
  91. package/lib/shapes/Circle.js +36 -9
  92. package/lib/shapes/Ellipse.d.ts +34 -2
  93. package/lib/shapes/Ellipse.js +67 -9
  94. package/lib/shapes/Image.d.ts +49 -0
  95. package/lib/shapes/Image.js +151 -22
  96. package/lib/shapes/Label.d.ts +65 -1
  97. package/lib/shapes/Label.js +113 -20
  98. package/lib/shapes/Line.d.ts +50 -8
  99. package/lib/shapes/Line.js +116 -20
  100. package/lib/shapes/Path.d.ts +40 -6
  101. package/lib/shapes/Path.js +187 -128
  102. package/lib/shapes/Rect.d.ts +18 -0
  103. package/lib/shapes/Rect.js +36 -0
  104. package/lib/shapes/RegularPolygon.d.ts +22 -0
  105. package/lib/shapes/RegularPolygon.js +70 -0
  106. package/lib/shapes/Ring.d.ts +19 -0
  107. package/lib/shapes/Ring.js +51 -5
  108. package/lib/shapes/Sprite.d.ts +78 -0
  109. package/lib/shapes/Sprite.js +238 -25
  110. package/lib/shapes/Star.d.ts +23 -0
  111. package/lib/shapes/Star.js +62 -0
  112. package/lib/shapes/Text.d.ts +59 -1
  113. package/lib/shapes/Text.js +481 -97
  114. package/lib/shapes/TextPath.d.ts +49 -3
  115. package/lib/shapes/TextPath.js +278 -34
  116. package/lib/shapes/Transformer.d.ts +108 -11
  117. package/lib/shapes/Transformer.js +744 -102
  118. package/lib/shapes/Wedge.d.ts +22 -0
  119. package/lib/shapes/Wedge.js +67 -3
  120. package/lib/skia-backend.js +9 -0
  121. package/lib/types.d.ts +2 -23
  122. package/lib/types.js +1 -21
  123. package/package.json +12 -16
@@ -2,6 +2,29 @@ import { Factory } from "../Factory.js";
2
2
  import { Shape } from "../Shape.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
4
  import { _registerNode } from "../Global.js";
5
+ /**
6
+ * Star constructor
7
+ * @constructor
8
+ * @memberof Konva
9
+ * @augments Konva.Shape
10
+ * @param {Object} config
11
+ * @param {Integer} config.numPoints
12
+ * @param {Number} config.innerRadius
13
+ * @param {Number} config.outerRadius
14
+ * @@shapeParams
15
+ * @@nodeParams
16
+ * @example
17
+ * var star = new Konva.Star({
18
+ * x: 100,
19
+ * y: 200,
20
+ * numPoints: 5,
21
+ * innerRadius: 70,
22
+ * outerRadius: 70,
23
+ * fill: 'red',
24
+ * stroke: 'black',
25
+ * strokeWidth: 4
26
+ * });
27
+ */
5
28
  export class Star extends Shape {
6
29
  _sceneFunc(context) {
7
30
  const innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();
@@ -33,6 +56,45 @@ Star.prototype.className = 'Star';
33
56
  Star.prototype._centroid = true;
34
57
  Star.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
35
58
  _registerNode(Star);
59
+ /**
60
+ * get/set number of points
61
+ * @name Konva.Star#numPoints
62
+ * @method
63
+ * @param {Number} numPoints
64
+ * @returns {Number}
65
+ * @example
66
+ * // get inner radius
67
+ * var numPoints = star.numPoints();
68
+ *
69
+ * // set inner radius
70
+ * star.numPoints(20);
71
+ */
36
72
  Factory.addGetterSetter(Star, 'numPoints', 5, getNumberValidator());
73
+ /**
74
+ * get/set innerRadius
75
+ * @name Konva.Star#innerRadius
76
+ * @method
77
+ * @param {Number} innerRadius
78
+ * @returns {Number}
79
+ * @example
80
+ * // get inner radius
81
+ * var innerRadius = star.innerRadius();
82
+ *
83
+ * // set inner radius
84
+ * star.innerRadius(20);
85
+ */
37
86
  Factory.addGetterSetter(Star, 'innerRadius', 0, getNumberValidator());
87
+ /**
88
+ * get/set outerRadius
89
+ * @name Konva.Star#outerRadius
90
+ * @method
91
+ * @param {Number} outerRadius
92
+ * @returns {Number}
93
+ * @example
94
+ * // get inner radius
95
+ * var outerRadius = star.outerRadius();
96
+ *
97
+ * // set inner radius
98
+ * star.outerRadius(20);
99
+ */
38
100
  Factory.addGetterSetter(Star, 'outerRadius', 0, getNumberValidator());
@@ -13,6 +13,7 @@ export interface CharRenderProps {
13
13
  width: number;
14
14
  context: Context;
15
15
  }
16
+ export declare function getDecorationLineWidth(fontSize: number): number;
16
17
  export declare function stringToArray(string: string): string[];
17
18
  export interface TextConfig extends ShapeConfig {
18
19
  direction?: string;
@@ -30,7 +31,41 @@ export interface TextConfig extends ShapeConfig {
30
31
  letterSpacing?: number;
31
32
  wrap?: string;
32
33
  ellipsis?: boolean;
34
+ charRenderFunc?: null | ((props: CharRenderProps) => void);
33
35
  }
36
+ export declare function getDummyContext(): CanvasRenderingContext2D;
37
+ /**
38
+ * Text constructor
39
+ * @constructor
40
+ * @memberof Konva
41
+ * @augments Konva.Shape
42
+ * @param {Object} config
43
+ * @param {String} [config.direction] default is inherit
44
+ * @param {String} [config.fontFamily] default is Arial
45
+ * @param {Number} [config.fontSize] in pixels. Default is 12
46
+ * @param {String} [config.fontStyle] can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
47
+ * @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
48
+ * @param {String} [config.textDecoration] can be line-through, underline or empty string. Default is empty string.
49
+ * @param {Number} [config.underlineOffset] offset for underline line. Default is calculated based on font size.
50
+ * @param {String} config.text
51
+ * @param {String} [config.align] can be left, center, right or justify
52
+ * @param {String} [config.verticalAlign] can be top, middle or bottom
53
+ * @param {Number} [config.padding]
54
+ * @param {Number} [config.lineHeight] default is 1
55
+ * @param {String} [config.wrap] can be "word", "char", or "none". Default is word
56
+ * @param {Boolean} [config.ellipsis] can be true or false. Default is false. If true, text that does not fit is cut and ends with "…". That needs a fixed height or wrap="none"
57
+ * @@shapeParams
58
+ * @@nodeParams
59
+ * @example
60
+ * var text = new Konva.Text({
61
+ * x: 10,
62
+ * y: 15,
63
+ * text: 'Simple Text',
64
+ * fontSize: 30,
65
+ * fontFamily: 'Calibri',
66
+ * fill: 'green'
67
+ * });
68
+ */
34
69
  export declare class Text extends Shape<TextConfig> {
35
70
  textArr: Array<{
36
71
  text: string;
@@ -50,8 +85,22 @@ export declare class Text extends Shape<TextConfig> {
50
85
  setText(text: string): this;
51
86
  getWidth(): any;
52
87
  getHeight(): any;
88
+ /**
89
+ * get pure text width without padding
90
+ * @method
91
+ * @name Konva.Text#getTextWidth
92
+ * @returns {Number}
93
+ */
53
94
  getTextWidth(): number;
54
95
  getTextHeight(): number;
96
+ /**
97
+ * measure string with the font of current text shape.
98
+ * That method can't handle multiline text.
99
+ * @method
100
+ * @name Konva.Text#measureSize
101
+ * @param {String} text text to measure
102
+ * @returns {Object} { width , height } of measured text
103
+ */
55
104
  measureSize(text: string): {
56
105
  actualBoundingBoxAscent: number;
57
106
  actualBoundingBoxDescent: number;
@@ -69,8 +118,15 @@ export declare class Text extends Shape<TextConfig> {
69
118
  };
70
119
  _getContextFont(): string;
71
120
  _addTextLine(line: string): number;
72
- _getTextWidth(text: string): number;
121
+ _getTextWidth(text: string, graphemes?: number): number;
73
122
  _setTextData(): void;
123
+ /**
124
+ * whether to handle ellipsis, there are two cases:
125
+ * 1. the current line is the last line
126
+ * 2. wrap is NONE
127
+ * @param {Number} currentHeightPx
128
+ * @returns {Boolean}
129
+ */
74
130
  _shouldHandleEllipsis(currentHeightPx: number): boolean;
75
131
  _tryToAddEllipsisToLastLine(): void;
76
132
  getStrokeScaleEnabled(): boolean;
@@ -91,4 +147,6 @@ export declare class Text extends Shape<TextConfig> {
91
147
  wrap: GetSet<string, this>;
92
148
  ellipsis: GetSet<boolean, this>;
93
149
  charRenderFunc: GetSet<null | ((props: CharRenderProps) => void), this>;
150
+ width: GetSet<number, this, number | 'auto'>;
151
+ height: GetSet<number, this, number | 'auto'>;
94
152
  }