konva 10.6.0 → 10.7.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.
- package/README.md +12 -8
- package/konva.js +533 -230
- package/konva.min.js +4 -4
- package/lib/Canvas.d.ts +9 -2
- package/lib/Canvas.js +83 -5
- package/lib/Container.d.ts +3 -2
- package/lib/Container.js +23 -12
- package/lib/Context.d.ts +5 -2
- package/lib/Context.js +22 -1
- package/lib/Global.d.ts +2 -1
- package/lib/Global.js +8 -3
- package/lib/Group.d.ts +7 -1
- package/lib/Group.js +61 -0
- package/lib/Layer.d.ts +1 -1
- package/lib/Layer.js +4 -2
- package/lib/Node.d.ts +4 -7
- package/lib/Node.js +19 -43
- package/lib/Shape.d.ts +9 -15
- package/lib/Shape.js +145 -85
- package/lib/Stage.d.ts +0 -2
- package/lib/Stage.js +2 -13
- package/lib/Util.d.ts +1 -0
- package/lib/Util.js +25 -0
- package/lib/shapes/Arc.js +3 -3
- package/lib/shapes/Arrow.d.ts +1 -0
- package/lib/shapes/Arrow.js +7 -1
- package/lib/shapes/Circle.d.ts +1 -0
- package/lib/shapes/Circle.js +4 -1
- package/lib/shapes/Ellipse.d.ts +1 -0
- package/lib/shapes/Ellipse.js +4 -1
- package/lib/shapes/Image.d.ts +2 -1
- package/lib/shapes/Image.js +6 -3
- package/lib/shapes/Label.js +18 -20
- package/lib/shapes/Line.d.ts +1 -0
- package/lib/shapes/Line.js +4 -1
- package/lib/shapes/Path.js +1 -1
- package/lib/shapes/Rect.d.ts +1 -0
- package/lib/shapes/Rect.js +4 -1
- package/lib/shapes/RegularPolygon.js +1 -1
- package/lib/shapes/Ring.d.ts +7 -0
- package/lib/shapes/Ring.js +8 -1
- package/lib/shapes/Sprite.d.ts +2 -1
- package/lib/shapes/Sprite.js +6 -3
- package/lib/shapes/Star.d.ts +6 -0
- package/lib/shapes/Star.js +5 -1
- package/lib/shapes/Text.d.ts +5 -2
- package/lib/shapes/Text.js +49 -22
- package/lib/shapes/TextPath.d.ts +7 -0
- package/lib/shapes/TextPath.js +16 -1
- package/lib/shapes/Transformer.js +7 -5
- package/lib/shapes/Wedge.js +1 -1
- package/package.json +2 -18
package/lib/shapes/Label.js
CHANGED
|
@@ -181,31 +181,29 @@ export class Tag extends Shape {
|
|
|
181
181
|
context.fillStrokeShape(this);
|
|
182
182
|
}
|
|
183
183
|
getSelfRect() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
184
|
+
const pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();
|
|
185
|
+
// The pointer base is centred on its side and can be longer than it.
|
|
186
|
+
if (direction === UP || direction === DOWN) {
|
|
187
|
+
return {
|
|
188
|
+
x: Math.min(0, (width - pointerWidth) / 2),
|
|
189
|
+
y: direction === UP ? -pointerHeight : 0,
|
|
190
|
+
width: Math.max(width, pointerWidth),
|
|
191
|
+
height: height + pointerHeight,
|
|
192
|
+
};
|
|
188
193
|
}
|
|
189
|
-
|
|
190
|
-
|
|
194
|
+
if (direction === LEFT || direction === RIGHT) {
|
|
195
|
+
return {
|
|
196
|
+
x: direction === LEFT ? -pointerWidth : 0,
|
|
197
|
+
y: Math.min(0, (height - pointerHeight) / 2),
|
|
198
|
+
width: width + pointerWidth,
|
|
199
|
+
height: Math.max(height, pointerHeight),
|
|
200
|
+
};
|
|
191
201
|
}
|
|
192
|
-
|
|
193
|
-
x -= pointerWidth;
|
|
194
|
-
width += pointerWidth;
|
|
195
|
-
}
|
|
196
|
-
else if (direction === RIGHT) {
|
|
197
|
-
width += pointerWidth;
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
x: x,
|
|
201
|
-
y: y,
|
|
202
|
-
width: width,
|
|
203
|
-
height: height,
|
|
204
|
-
};
|
|
202
|
+
return { x: 0, y: 0, width, height };
|
|
205
203
|
}
|
|
206
204
|
}
|
|
207
205
|
Tag.prototype.className = 'Tag';
|
|
208
|
-
_registerNode(Tag);
|
|
206
|
+
_registerNode(Tag, true);
|
|
209
207
|
/**
|
|
210
208
|
* get/set pointer direction
|
|
211
209
|
* @name Konva.Tag#pointerDirection
|
package/lib/shapes/Line.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare class Line<Config extends LineConfig = LineConfig> extends Shape<
|
|
|
43
43
|
* The handlers take plain numbers, because this runs on every frame.
|
|
44
44
|
*/
|
|
45
45
|
_eachTensionSegment(onQuadratic: (x0: number, y0: number, cpx: number, cpy: number, x: number, y: number) => void, onCubic: (x0: number, y0: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number) => void): void;
|
|
46
|
+
_getStrokePadding(miterLimit?: number | undefined): number;
|
|
46
47
|
_sceneFunc(context: Context): void;
|
|
47
48
|
getTensionPoints(): any;
|
|
48
49
|
_getTensionPoints(): number[];
|
package/lib/shapes/Line.js
CHANGED
|
@@ -105,6 +105,9 @@ export class Line extends Shape {
|
|
|
105
105
|
onQuadratic(x0, y0, tp[len - 2], tp[len - 1], points[length - 2], points[length - 1]);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
+
_getStrokePadding(miterLimit = this.points().length === 4 && !this.closed() ? 1 : undefined) {
|
|
109
|
+
return super._getStrokePadding(miterLimit);
|
|
110
|
+
}
|
|
108
111
|
_sceneFunc(context) {
|
|
109
112
|
const points = this.points(), length = points.length, closed = this.closed(), bezier = this.bezier();
|
|
110
113
|
if (!length) {
|
|
@@ -204,7 +207,7 @@ export class Line extends Shape {
|
|
|
204
207
|
}
|
|
205
208
|
Line.prototype.className = 'Line';
|
|
206
209
|
Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension', 'closed'];
|
|
207
|
-
_registerNode(Line);
|
|
210
|
+
_registerNode(Line, true);
|
|
208
211
|
// add getters setters
|
|
209
212
|
Factory.addGetterSetter(Line, 'closed', false);
|
|
210
213
|
/**
|
package/lib/shapes/Path.js
CHANGED
|
@@ -703,7 +703,7 @@ export class Path extends Shape {
|
|
|
703
703
|
}
|
|
704
704
|
Path.prototype.className = 'Path';
|
|
705
705
|
Path.prototype._attrsAffectingSize = ['data'];
|
|
706
|
-
_registerNode(Path);
|
|
706
|
+
_registerNode(Path, true);
|
|
707
707
|
/**
|
|
708
708
|
* get/set SVG path data string. This method
|
|
709
709
|
* also automatically parses the data string
|
package/lib/shapes/Rect.d.ts
CHANGED
package/lib/shapes/Rect.js
CHANGED
|
@@ -22,6 +22,9 @@ import { getNumberOrArrayOfNumbersValidator } from "../Validators.js";
|
|
|
22
22
|
* });
|
|
23
23
|
*/
|
|
24
24
|
export class Rect extends Shape {
|
|
25
|
+
_getStrokePadding() {
|
|
26
|
+
return super._getStrokePadding(this.strokeScaleEnabled() ? 1 : undefined);
|
|
27
|
+
}
|
|
25
28
|
_sceneFunc(context) {
|
|
26
29
|
const cornerRadius = this.cornerRadius(), width = this.width(), height = this.height();
|
|
27
30
|
context.beginPath();
|
|
@@ -37,7 +40,7 @@ export class Rect extends Shape {
|
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
Rect.prototype.className = 'Rect';
|
|
40
|
-
_registerNode(Rect);
|
|
43
|
+
_registerNode(Rect, true);
|
|
41
44
|
/**
|
|
42
45
|
* get/set corner radius
|
|
43
46
|
* @method
|
|
@@ -94,7 +94,7 @@ export class RegularPolygon extends Shape {
|
|
|
94
94
|
RegularPolygon.prototype.className = 'RegularPolygon';
|
|
95
95
|
RegularPolygon.prototype._centroid = true;
|
|
96
96
|
RegularPolygon.prototype._attrsAffectingSize = ['radius', 'sides'];
|
|
97
|
-
_registerNode(RegularPolygon);
|
|
97
|
+
_registerNode(RegularPolygon, true);
|
|
98
98
|
/**
|
|
99
99
|
* get/set radius
|
|
100
100
|
* @method
|
package/lib/shapes/Ring.d.ts
CHANGED
|
@@ -26,7 +26,14 @@ export interface RingConfig extends ShapeConfig {
|
|
|
26
26
|
* });
|
|
27
27
|
*/
|
|
28
28
|
export declare class Ring extends Shape<RingConfig> {
|
|
29
|
+
_getStrokePadding(): number;
|
|
29
30
|
_sceneFunc(context: Context): void;
|
|
31
|
+
getSelfRect(): {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
};
|
|
30
37
|
getWidth(): number;
|
|
31
38
|
getHeight(): number;
|
|
32
39
|
setWidth(width: number): void;
|
package/lib/shapes/Ring.js
CHANGED
|
@@ -23,6 +23,9 @@ const PIx2 = Math.PI * 2;
|
|
|
23
23
|
* });
|
|
24
24
|
*/
|
|
25
25
|
export class Ring extends Shape {
|
|
26
|
+
_getStrokePadding() {
|
|
27
|
+
return super._getStrokePadding(1);
|
|
28
|
+
}
|
|
26
29
|
_sceneFunc(context) {
|
|
27
30
|
const innerRadius = Math.abs(this.innerRadius()), outerRadius = Math.abs(this.outerRadius());
|
|
28
31
|
context.beginPath();
|
|
@@ -32,6 +35,10 @@ export class Ring extends Shape {
|
|
|
32
35
|
context.closePath();
|
|
33
36
|
context.fillStrokeShape(this);
|
|
34
37
|
}
|
|
38
|
+
getSelfRect() {
|
|
39
|
+
const radius = Math.max(Math.abs(this.innerRadius()), Math.abs(this.outerRadius()));
|
|
40
|
+
return { x: -radius, y: -radius, width: radius * 2, height: radius * 2 };
|
|
41
|
+
}
|
|
35
42
|
getWidth() {
|
|
36
43
|
return Math.abs(this.outerRadius()) * 2;
|
|
37
44
|
}
|
|
@@ -48,7 +55,7 @@ export class Ring extends Shape {
|
|
|
48
55
|
Ring.prototype.className = 'Ring';
|
|
49
56
|
Ring.prototype._centroid = true;
|
|
50
57
|
Ring.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
|
51
|
-
_registerNode(Ring);
|
|
58
|
+
_registerNode(Ring, true);
|
|
52
59
|
/**
|
|
53
60
|
* get/set innerRadius
|
|
54
61
|
* @method
|
package/lib/shapes/Sprite.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export declare class Sprite extends Shape<SpriteConfig> {
|
|
|
70
70
|
offsetX: any;
|
|
71
71
|
offsetY: any;
|
|
72
72
|
} | undefined;
|
|
73
|
+
_getStrokePadding(): number;
|
|
73
74
|
_sceneFunc(context: Context): void;
|
|
74
75
|
_hitFunc(context: Context): void;
|
|
75
76
|
getSelfRect(): {
|
|
@@ -78,7 +79,7 @@ export declare class Sprite extends Shape<SpriteConfig> {
|
|
|
78
79
|
width: any;
|
|
79
80
|
height: any;
|
|
80
81
|
};
|
|
81
|
-
_useBufferCanvas(): boolean;
|
|
82
|
+
_useBufferCanvas(forceFill?: boolean, opacity?: any): boolean;
|
|
82
83
|
_setInterval(): void;
|
|
83
84
|
/**
|
|
84
85
|
* start sprite animation
|
package/lib/shapes/Sprite.js
CHANGED
|
@@ -95,6 +95,9 @@ export class Sprite extends Shape {
|
|
|
95
95
|
offsetY: offset[index * 2 + 1] || 0,
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
+
_getStrokePadding() {
|
|
99
|
+
return super._getStrokePadding(this.strokeScaleEnabled() ? 1 : undefined);
|
|
100
|
+
}
|
|
98
101
|
_sceneFunc(context) {
|
|
99
102
|
const frame = this._getFrame();
|
|
100
103
|
if (!frame) {
|
|
@@ -130,8 +133,8 @@ export class Sprite extends Shape {
|
|
|
130
133
|
}
|
|
131
134
|
: { x: 0, y: 0, width: 0, height: 0 };
|
|
132
135
|
}
|
|
133
|
-
_useBufferCanvas() {
|
|
134
|
-
return super._useBufferCanvas(true);
|
|
136
|
+
_useBufferCanvas(forceFill, opacity = this.getAbsoluteOpacity()) {
|
|
137
|
+
return super._useBufferCanvas(true, opacity);
|
|
135
138
|
}
|
|
136
139
|
_setInterval() {
|
|
137
140
|
const that = this;
|
|
@@ -184,7 +187,7 @@ export class Sprite extends Shape {
|
|
|
184
187
|
}
|
|
185
188
|
}
|
|
186
189
|
Sprite.prototype.className = 'Sprite';
|
|
187
|
-
_registerNode(Sprite);
|
|
190
|
+
_registerNode(Sprite, true);
|
|
188
191
|
// add getters setters
|
|
189
192
|
Factory.addGetterSetter(Sprite, 'animation');
|
|
190
193
|
/**
|
package/lib/shapes/Star.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ export interface StarConfig extends ShapeConfig {
|
|
|
32
32
|
*/
|
|
33
33
|
export declare class Star extends Shape<StarConfig> {
|
|
34
34
|
_sceneFunc(context: Context): void;
|
|
35
|
+
getSelfRect(): {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
};
|
|
35
41
|
getWidth(): number;
|
|
36
42
|
getHeight(): number;
|
|
37
43
|
setWidth(width: number): void;
|
package/lib/shapes/Star.js
CHANGED
|
@@ -39,6 +39,10 @@ export class Star extends Shape {
|
|
|
39
39
|
context.closePath();
|
|
40
40
|
context.fillStrokeShape(this);
|
|
41
41
|
}
|
|
42
|
+
getSelfRect() {
|
|
43
|
+
const radius = Math.max(Math.abs(this.innerRadius()), Math.abs(this.outerRadius()));
|
|
44
|
+
return { x: -radius, y: -radius, width: radius * 2, height: radius * 2 };
|
|
45
|
+
}
|
|
42
46
|
getWidth() {
|
|
43
47
|
return this.outerRadius() * 2;
|
|
44
48
|
}
|
|
@@ -55,7 +59,7 @@ export class Star extends Shape {
|
|
|
55
59
|
Star.prototype.className = 'Star';
|
|
56
60
|
Star.prototype._centroid = true;
|
|
57
61
|
Star.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
|
58
|
-
_registerNode(Star);
|
|
62
|
+
_registerNode(Star, true);
|
|
59
63
|
/**
|
|
60
64
|
* get/set number of points
|
|
61
65
|
* @name Konva.Star#numPoints
|
package/lib/shapes/Text.d.ts
CHANGED
|
@@ -82,8 +82,10 @@ export declare class Text extends Shape<TextConfig> {
|
|
|
82
82
|
_baselineShift: number;
|
|
83
83
|
constructor(config?: TextConfig);
|
|
84
84
|
_sceneFunc(context: SceneContext): void;
|
|
85
|
+
_getTextTop(): number;
|
|
85
86
|
_getUnderlineOffset(): number;
|
|
86
|
-
getSelfRect():
|
|
87
|
+
getSelfRect(): import("../types.ts").IRect;
|
|
88
|
+
_getSelfRectForDrawing(): {
|
|
87
89
|
x: number;
|
|
88
90
|
y: number;
|
|
89
91
|
width: number;
|
|
@@ -138,7 +140,8 @@ export declare class Text extends Shape<TextConfig> {
|
|
|
138
140
|
_shouldHandleEllipsis(currentHeightPx: number): boolean;
|
|
139
141
|
_tryToAddEllipsisToLastLine(): void;
|
|
140
142
|
getStrokeScaleEnabled(): boolean;
|
|
141
|
-
|
|
143
|
+
_getStrokePadding(): number;
|
|
144
|
+
_useBufferCanvas(forceFill?: boolean, opacity?: any): boolean;
|
|
142
145
|
direction: GetSet<string, this>;
|
|
143
146
|
fontFamily: GetSet<string, this>;
|
|
144
147
|
fontSize: GetSet<number, this>;
|
package/lib/shapes/Text.js
CHANGED
|
@@ -178,7 +178,7 @@ export class Text extends Shape {
|
|
|
178
178
|
if (!this.text()) {
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
181
|
-
let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize,
|
|
181
|
+
let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, direction = this.direction(), align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
|
|
182
182
|
let translateY = lineHeightPx / 2;
|
|
183
183
|
let baseline = MIDDLE;
|
|
184
184
|
if (!Konva.legacyTextRendering) {
|
|
@@ -199,14 +199,7 @@ export class Text extends Shape {
|
|
|
199
199
|
context.setAttr('font', this._getContextFont());
|
|
200
200
|
context.setAttr('textBaseline', baseline);
|
|
201
201
|
context.setAttr('textAlign', LEFT);
|
|
202
|
-
|
|
203
|
-
if (verticalAlign === MIDDLE) {
|
|
204
|
-
alignY = (this.getHeight() - textArrLen * lineHeightPx - padding * 2) / 2;
|
|
205
|
-
}
|
|
206
|
-
else if (verticalAlign === BOTTOM) {
|
|
207
|
-
alignY = this.getHeight() - textArrLen * lineHeightPx - padding * 2;
|
|
208
|
-
}
|
|
209
|
-
context.translate(padding, alignY + padding);
|
|
202
|
+
context.translate(padding, this._getTextTop());
|
|
210
203
|
// Start the callback with the same fill that normal drawing would use.
|
|
211
204
|
// Assigning that color again then needs no override, including black.
|
|
212
205
|
if (charRenderFunc) {
|
|
@@ -335,6 +328,16 @@ export class Text extends Shape {
|
|
|
335
328
|
}
|
|
336
329
|
}
|
|
337
330
|
}
|
|
331
|
+
_getTextTop() {
|
|
332
|
+
const padding = this.padding(), free = this.getHeight() -
|
|
333
|
+
this.textArr.length * this.lineHeight() * this.fontSize() -
|
|
334
|
+
padding * 2, verticalAlign = this.verticalAlign();
|
|
335
|
+
if (verticalAlign === MIDDLE)
|
|
336
|
+
return padding + free / 2;
|
|
337
|
+
if (verticalAlign === BOTTOM)
|
|
338
|
+
return padding + free;
|
|
339
|
+
return padding;
|
|
340
|
+
}
|
|
338
341
|
_getUnderlineOffset() {
|
|
339
342
|
var _a;
|
|
340
343
|
return ((_a = this.underlineOffset()) !== null && _a !== void 0 ? _a : Math.round(this.fontSize() / (!Konva.legacyTextRendering ? 4 : 2)));
|
|
@@ -346,21 +349,41 @@ export class Text extends Shape {
|
|
|
346
349
|
return rect;
|
|
347
350
|
}
|
|
348
351
|
// the underline of the last line is drawn below the text block
|
|
349
|
-
const fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize
|
|
350
|
-
let bottom = lines * lineHeightPx - lineHeightPx / 2
|
|
352
|
+
const fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize;
|
|
353
|
+
let bottom = this._getTextTop() + lines * lineHeightPx - lineHeightPx / 2;
|
|
351
354
|
if (!Konva.legacyTextRendering) {
|
|
352
355
|
bottom += this._baselineShift;
|
|
353
356
|
}
|
|
354
|
-
if (verticalAlign === MIDDLE) {
|
|
355
|
-
bottom += (rect.height - blockHeight) / 2;
|
|
356
|
-
}
|
|
357
|
-
else if (verticalAlign === BOTTOM) {
|
|
358
|
-
bottom += rect.height - blockHeight;
|
|
359
|
-
}
|
|
360
357
|
bottom += this._getUnderlineOffset() + getDecorationLineWidth(fontSize) / 2;
|
|
361
|
-
rect.height = Math.max(rect.height, bottom);
|
|
358
|
+
rect.height = Math.max(rect.y + rect.height, bottom) - rect.y;
|
|
362
359
|
return rect;
|
|
363
360
|
}
|
|
361
|
+
_getSelfRectForDrawing() {
|
|
362
|
+
// Lines can be wider than the box, negative spacing moves the pen back,
|
|
363
|
+
// and glyph ink passes the advance box (italics, accents): up to 0.6em
|
|
364
|
+
// in common fonts, so pad by 1em.
|
|
365
|
+
const rect = this.getSelfRect(), fontSize = this.fontSize(), padding = this.padding(), lineHeightPx = this.lineHeight() * fontSize, available = this.getWidth() - padding * 2, align = this.align(), blockHeight = this.textArr.length * lineHeightPx, top = this._getTextTop();
|
|
366
|
+
let left = rect.x, right = rect.x + rect.width;
|
|
367
|
+
for (const { text, width } of this.textArr) {
|
|
368
|
+
const x = padding +
|
|
369
|
+
(align === RIGHT
|
|
370
|
+
? available - width
|
|
371
|
+
: align === CENTER
|
|
372
|
+
? (available - width) / 2
|
|
373
|
+
: 0);
|
|
374
|
+
const back = Math.min(0, this.letterSpacing()) * text.length;
|
|
375
|
+
left = Math.min(left, x + back);
|
|
376
|
+
right = Math.max(right, x + width - back);
|
|
377
|
+
}
|
|
378
|
+
const underline = this.textDecoration().includes('underline');
|
|
379
|
+
const y = Math.min(rect.y, top + (underline ? Math.min(0, this._getUnderlineOffset()) : 0));
|
|
380
|
+
return {
|
|
381
|
+
x: left - fontSize,
|
|
382
|
+
y: y - fontSize,
|
|
383
|
+
width: right - left + fontSize * 2,
|
|
384
|
+
height: Math.max(rect.y + rect.height, top + blockHeight) - y + fontSize * 2,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
364
387
|
_hitFunc(context) {
|
|
365
388
|
const width = this.getWidth(), height = this.getHeight();
|
|
366
389
|
context.beginPath();
|
|
@@ -641,7 +664,11 @@ export class Text extends Shape {
|
|
|
641
664
|
getStrokeScaleEnabled() {
|
|
642
665
|
return true;
|
|
643
666
|
}
|
|
644
|
-
|
|
667
|
+
_getStrokePadding() {
|
|
668
|
+
// _strokeFunc uses a miter limit of two for glyph outlines.
|
|
669
|
+
return super._getStrokePadding(2);
|
|
670
|
+
}
|
|
671
|
+
_useBufferCanvas(forceFill, opacity = this.getAbsoluteOpacity()) {
|
|
645
672
|
if (this.attrs.perfectDrawEnabled === false)
|
|
646
673
|
return false;
|
|
647
674
|
const hasLine = this.textDecoration().indexOf('underline') !== -1 ||
|
|
@@ -650,10 +677,10 @@ export class Text extends Shape {
|
|
|
650
677
|
if (hasLine && hasShadow) {
|
|
651
678
|
return true;
|
|
652
679
|
}
|
|
653
|
-
if (hasShadow &&
|
|
680
|
+
if (hasShadow && opacity !== 1 && hasShadowOpacityBug()) {
|
|
654
681
|
return true;
|
|
655
682
|
}
|
|
656
|
-
return super._useBufferCanvas();
|
|
683
|
+
return super._useBufferCanvas(forceFill, opacity);
|
|
657
684
|
}
|
|
658
685
|
}
|
|
659
686
|
Text.prototype._fillFunc = _fillFunc;
|
|
@@ -662,7 +689,7 @@ Text.prototype.className = TEXT_UPPER;
|
|
|
662
689
|
// the decoration attrs are not in ATTR_CHANGE_LIST: they change the bounds
|
|
663
690
|
// through getSelfRect, but need no relayout
|
|
664
691
|
Text.prototype._attrsAffectingSize = ATTR_CHANGE_LIST.filter((attr) => attr !== 'width' && attr !== 'height').concat(['textDecoration', 'underlineOffset']);
|
|
665
|
-
_registerNode(Text);
|
|
692
|
+
_registerNode(Text, true);
|
|
666
693
|
// update text data for certain attr changes
|
|
667
694
|
Text.prototype.on(ATTR_CHANGE_LIST.map((attr) => attr + CHANGE_KONVA).join(' '), function () {
|
|
668
695
|
this._setTextData();
|
package/lib/shapes/TextPath.d.ts
CHANGED
|
@@ -106,6 +106,13 @@ export declare class TextPath extends Shape<TextPathConfig> {
|
|
|
106
106
|
width: number;
|
|
107
107
|
height: number;
|
|
108
108
|
};
|
|
109
|
+
getStrokeScaleEnabled(): boolean;
|
|
110
|
+
_getSelfRectForDrawing(): {
|
|
111
|
+
x: number;
|
|
112
|
+
y: number;
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
};
|
|
109
116
|
fontFamily: GetSet<string, this>;
|
|
110
117
|
fontSize: GetSet<number, this>;
|
|
111
118
|
fontStyle: GetSet<string, this>;
|
package/lib/shapes/TextPath.js
CHANGED
|
@@ -313,6 +313,21 @@ export class TextPath extends Shape {
|
|
|
313
313
|
height: rect.height + fontSize,
|
|
314
314
|
};
|
|
315
315
|
}
|
|
316
|
+
// Like Text: a glyph stroke is drawn with the text, so it always scales.
|
|
317
|
+
getStrokeScaleEnabled() {
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
_getSelfRectForDrawing() {
|
|
321
|
+
// getSelfRect() pads glyph anchors by half the font size; ascenders,
|
|
322
|
+
// accents and other baselines reach further from the path.
|
|
323
|
+
const rect = this.getSelfRect(), pad = this.fontSize();
|
|
324
|
+
return {
|
|
325
|
+
x: rect.x - pad,
|
|
326
|
+
y: rect.y - pad,
|
|
327
|
+
width: rect.width + pad * 2,
|
|
328
|
+
height: rect.height + pad * 2,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
316
331
|
}
|
|
317
332
|
TextPath.prototype._fillFunc = _fillFunc;
|
|
318
333
|
TextPath.prototype._strokeFunc = _strokeFunc;
|
|
@@ -331,7 +346,7 @@ TextPath.prototype._attrsAffectingSize = [
|
|
|
331
346
|
'fontVariant',
|
|
332
347
|
'direction',
|
|
333
348
|
];
|
|
334
|
-
_registerNode(TextPath);
|
|
349
|
+
_registerNode(TextPath, true);
|
|
335
350
|
TextPath.prototype.on('dataChange.konva', function () {
|
|
336
351
|
this._readDataAttribute();
|
|
337
352
|
this._setTextData();
|
|
@@ -44,6 +44,7 @@ const TRANSFORM_CHANGE_STR = [
|
|
|
44
44
|
'transformsEnabledChange',
|
|
45
45
|
'strokeWidthChange',
|
|
46
46
|
'strokeChange',
|
|
47
|
+
'selfRectFuncChange',
|
|
47
48
|
'strokeLinearGradientColorStopsChange',
|
|
48
49
|
'strokeScaleEnabledChange',
|
|
49
50
|
'strokeEnabledChange',
|
|
@@ -487,13 +488,14 @@ export class Transformer extends Group {
|
|
|
487
488
|
// Bounds may only be reused when they are a pure function of the node's
|
|
488
489
|
// own size: then every change reaches us either through _setAttr or
|
|
489
490
|
// through the size probe below. A shape with its own getSelfRect - Line
|
|
490
|
-
// mutates its points array in place, and a user subclass
|
|
491
|
-
// anything at all - may change with no signal, so it is
|
|
492
|
-
// time. Groups depend on their descendants, and a cached
|
|
493
|
-
// suppresses descendant transform-change notifications, so
|
|
494
|
-
// measured too.
|
|
491
|
+
// mutates its points array in place, and a user subclass or selfRectFunc
|
|
492
|
+
// can measure anything at all - may change with no signal, so it is
|
|
493
|
+
// measured every time. Groups depend on their descendants, and a cached
|
|
494
|
+
// ancestor suppresses descendant transform-change notifications, so
|
|
495
|
+
// both are measured too.
|
|
495
496
|
const cacheable = node instanceof Shape &&
|
|
496
497
|
node.getSelfRect === Shape.prototype.getSelfRect &&
|
|
498
|
+
!node.attrs.selfRectFunc &&
|
|
497
499
|
!node._hasCachedAncestor();
|
|
498
500
|
// width() and height() are the only inputs of the default getSelfRect and
|
|
499
501
|
// they can come from outside the attrs (an Image source that loads or
|
package/lib/shapes/Wedge.js
CHANGED
|
@@ -49,7 +49,7 @@ export class Wedge extends Shape {
|
|
|
49
49
|
Wedge.prototype.className = 'Wedge';
|
|
50
50
|
Wedge.prototype._centroid = true;
|
|
51
51
|
Wedge.prototype._attrsAffectingSize = ['radius'];
|
|
52
|
-
_registerNode(Wedge);
|
|
52
|
+
_registerNode(Wedge, true);
|
|
53
53
|
/**
|
|
54
54
|
* get/set radius
|
|
55
55
|
* @name Konva.Wedge#radius
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "konva",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.7.0",
|
|
4
4
|
"description": "HTML5 2d canvas library for interactive graphics, design editors, whiteboards, and diagrams.",
|
|
5
5
|
"author": "Anton Lavrenov",
|
|
6
6
|
"type": "module",
|
|
@@ -54,8 +54,7 @@
|
|
|
54
54
|
"tsc": "tsc",
|
|
55
55
|
"rollup": "rollup -c",
|
|
56
56
|
"clean": "rimraf ./lib ./test-build",
|
|
57
|
-
"watch": "rollup -c -w"
|
|
58
|
-
"size": "size-limit"
|
|
57
|
+
"watch": "rollup -c -w"
|
|
59
58
|
},
|
|
60
59
|
"targets": {
|
|
61
60
|
"none": {}
|
|
@@ -74,22 +73,8 @@
|
|
|
74
73
|
"url": "https://github.com/sponsors/lavrton"
|
|
75
74
|
}
|
|
76
75
|
],
|
|
77
|
-
"size-limit": [
|
|
78
|
-
{
|
|
79
|
-
"limit": "48 KB",
|
|
80
|
-
"path": "./lib/index.js"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
"limit": "26 KB",
|
|
84
|
-
"path": "./lib/Core.js"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"path": "./konva.min.js"
|
|
88
|
-
}
|
|
89
|
-
],
|
|
90
76
|
"devDependencies": {
|
|
91
77
|
"@parcel/transformer-image": "2.15.4",
|
|
92
|
-
"@size-limit/preset-big-lib": "^11.2.0",
|
|
93
78
|
"@types/mocha": "^10.0.10",
|
|
94
79
|
"canvas": "^3.2.1",
|
|
95
80
|
"chai": "6.2.2",
|
|
@@ -108,7 +93,6 @@
|
|
|
108
93
|
"rimraf": "^6.1.2",
|
|
109
94
|
"rollup": "^4.55.1",
|
|
110
95
|
"rollup-plugin-typescript2": "^0.37.0",
|
|
111
|
-
"size-limit": "^11.2.0",
|
|
112
96
|
"skia-canvas": "^3.0.4",
|
|
113
97
|
"stats.js": "0.17.0",
|
|
114
98
|
"tsx": "^4.21.0",
|