konva 9.3.10 → 9.3.12
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 +4 -0
- package/konva.js +44 -55
- package/konva.min.js +3 -3
- package/lib/Global.js +1 -1
- package/lib/Shape.d.ts +3 -3
- package/lib/Shape.js +10 -1
- package/lib/Stage.js +1 -1
- package/lib/shapes/Path.d.ts +12 -3
- package/lib/shapes/Path.js +21 -43
- package/lib/shapes/TextPath.d.ts +4 -1
- package/lib/shapes/Transformer.js +3 -0
- package/package.json +1 -1
package/lib/Global.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.glob = typeof global !== 'undefined'
|
|
|
16
16
|
: {};
|
|
17
17
|
exports.Konva = {
|
|
18
18
|
_global: exports.glob,
|
|
19
|
-
version: '9.3.
|
|
19
|
+
version: '9.3.12',
|
|
20
20
|
isBrowser: detectBrowser(),
|
|
21
21
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
22
22
|
dblClickWindow: 400,
|
package/lib/Shape.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type ShapeConfigHandler<TTarget> = {
|
|
|
8
8
|
export type LineJoin = 'round' | 'bevel' | 'miter';
|
|
9
9
|
export type LineCap = 'butt' | 'round' | 'square';
|
|
10
10
|
export interface ShapeConfig extends NodeConfig {
|
|
11
|
-
fill?: string;
|
|
11
|
+
fill?: string | CanvasGradient;
|
|
12
12
|
fillPatternImage?: HTMLImageElement;
|
|
13
13
|
fillPatternX?: number;
|
|
14
14
|
fillPatternY?: number;
|
|
@@ -126,7 +126,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
|
|
|
126
126
|
dash: GetSet<number[], this>;
|
|
127
127
|
dashEnabled: GetSet<boolean, this>;
|
|
128
128
|
dashOffset: GetSet<number, this>;
|
|
129
|
-
fill: GetSet<string, this>;
|
|
129
|
+
fill: GetSet<string | CanvasGradient, this>;
|
|
130
130
|
fillEnabled: GetSet<boolean, this>;
|
|
131
131
|
fillLinearGradientColorStops: GetSet<Array<number | string>, this>;
|
|
132
132
|
fillLinearGradientStartPoint: GetSet<Vector2d, this>;
|
|
@@ -175,7 +175,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
|
|
|
175
175
|
shadowOffsetY: GetSet<number, this>;
|
|
176
176
|
shadowOpacity: GetSet<number, this>;
|
|
177
177
|
shadowBlur: GetSet<number, this>;
|
|
178
|
-
stroke: GetSet<string, this>;
|
|
178
|
+
stroke: GetSet<string | CanvasGradient, this>;
|
|
179
179
|
strokeEnabled: GetSet<boolean, this>;
|
|
180
180
|
fillAfterStrokeEnabled: GetSet<boolean, this>;
|
|
181
181
|
strokeScaleEnabled: GetSet<boolean, this>;
|
package/lib/Shape.js
CHANGED
|
@@ -271,8 +271,17 @@ class Shape extends Node_1.Node {
|
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
273
|
getClientRect(config = {}) {
|
|
274
|
+
let hasCachedParent = false;
|
|
275
|
+
let parent = this.getParent();
|
|
276
|
+
while (parent) {
|
|
277
|
+
if (parent.isCached()) {
|
|
278
|
+
hasCachedParent = true;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
parent = parent.getParent();
|
|
282
|
+
}
|
|
274
283
|
const skipTransform = config.skipTransform;
|
|
275
|
-
const relativeTo = config.relativeTo;
|
|
284
|
+
const relativeTo = config.relativeTo || (hasCachedParent && this.getStage()) || undefined;
|
|
276
285
|
const fillRect = this.getSelfRect();
|
|
277
286
|
const applyStroke = !config.skipStroke && this.hasStroke();
|
|
278
287
|
const strokeWidth = (applyStroke && this.strokeWidth()) || 0;
|
package/lib/Stage.js
CHANGED
|
@@ -695,7 +695,7 @@ Stage.prototype.nodeType = STAGE;
|
|
|
695
695
|
(0, Global_2._registerNode)(Stage);
|
|
696
696
|
Factory_1.Factory.addGetterSetter(Stage, 'container');
|
|
697
697
|
if (Global_1.Konva.isBrowser) {
|
|
698
|
-
|
|
698
|
+
document.addEventListener('visibilitychange', () => {
|
|
699
699
|
exports.stages.forEach((stage) => {
|
|
700
700
|
stage.batchDraw();
|
|
701
701
|
});
|
package/lib/shapes/Path.d.ts
CHANGED
|
@@ -16,12 +16,21 @@ export declare class Path extends Shape<PathConfig> {
|
|
|
16
16
|
height: number;
|
|
17
17
|
};
|
|
18
18
|
getLength(): number;
|
|
19
|
-
getPointAtLength(length: any):
|
|
19
|
+
getPointAtLength(length: any): {
|
|
20
|
+
x: any;
|
|
21
|
+
y: any;
|
|
22
|
+
} | null;
|
|
20
23
|
data: GetSet<string, this>;
|
|
21
24
|
static getLineLength(x1: any, y1: any, x2: any, y2: any): number;
|
|
22
25
|
static getPathLength(dataArray: PathSegment[]): number;
|
|
23
|
-
static getPointAtLengthOfDataArray(length: number, dataArray: any):
|
|
24
|
-
|
|
26
|
+
static getPointAtLengthOfDataArray(length: number, dataArray: any): {
|
|
27
|
+
x: any;
|
|
28
|
+
y: any;
|
|
29
|
+
} | null;
|
|
30
|
+
static getPointOnLine(dist: any, P1x: any, P1y: any, P2x: any, P2y: any, fromX?: any, fromY?: any): {
|
|
31
|
+
x: any;
|
|
32
|
+
y: any;
|
|
33
|
+
};
|
|
25
34
|
static getPointOnCubicBezier(pct: any, P1x: any, P1y: any, P2x: any, P2y: any, P3x: any, P3y: any, P4x: any, P4y: any): {
|
|
26
35
|
x: number;
|
|
27
36
|
y: number;
|
package/lib/shapes/Path.js
CHANGED
|
@@ -183,51 +183,29 @@ class Path extends Shape_1.Shape {
|
|
|
183
183
|
return null;
|
|
184
184
|
}
|
|
185
185
|
static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
fromX = fromX !== null && fromX !== void 0 ? fromX : P1x;
|
|
187
|
+
fromY = fromY !== null && fromY !== void 0 ? fromY : P1y;
|
|
188
|
+
const len = this.getLineLength(P1x, P1y, P2x, P2y);
|
|
189
|
+
if (len < 1e-10) {
|
|
190
|
+
return { x: P1x, y: P1y };
|
|
188
191
|
}
|
|
189
|
-
if (fromY === undefined) {
|
|
190
|
-
fromY = P1y;
|
|
191
|
-
}
|
|
192
|
-
var m = (P2y - P1y) / (P2x - P1x + 0.00000001);
|
|
193
|
-
var run = Math.sqrt((dist * dist) / (1 + m * m));
|
|
194
|
-
if (P2x < P1x) {
|
|
195
|
-
run *= -1;
|
|
196
|
-
}
|
|
197
|
-
var rise = m * run;
|
|
198
|
-
var pt;
|
|
199
192
|
if (P2x === P1x) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
ix = P1x + u * (P2x - P1x);
|
|
217
|
-
iy = P1y + u * (P2y - P1y);
|
|
218
|
-
var pRise = this.getLineLength(fromX, fromY, ix, iy);
|
|
219
|
-
var pRun = Math.sqrt(dist * dist - pRise * pRise);
|
|
220
|
-
run = Math.sqrt((pRun * pRun) / (1 + m * m));
|
|
221
|
-
if (P2x < P1x) {
|
|
222
|
-
run *= -1;
|
|
223
|
-
}
|
|
224
|
-
rise = m * run;
|
|
225
|
-
pt = {
|
|
226
|
-
x: ix + run,
|
|
227
|
-
y: iy + rise,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
return pt;
|
|
193
|
+
return { x: fromX, y: fromY + (P2y > P1y ? dist : -dist) };
|
|
194
|
+
}
|
|
195
|
+
const m = (P2y - P1y) / (P2x - P1x);
|
|
196
|
+
const run = Math.sqrt((dist * dist) / (1 + m * m)) * (P2x < P1x ? -1 : 1);
|
|
197
|
+
const rise = m * run;
|
|
198
|
+
if (Math.abs(fromY - P1y - m * (fromX - P1x)) < 1e-10) {
|
|
199
|
+
return { x: fromX + run, y: fromY + rise };
|
|
200
|
+
}
|
|
201
|
+
const u = ((fromX - P1x) * (P2x - P1x) + (fromY - P1y) * (P2y - P1y)) / (len * len);
|
|
202
|
+
const ix = P1x + u * (P2x - P1x);
|
|
203
|
+
const iy = P1y + u * (P2y - P1y);
|
|
204
|
+
const pRise = this.getLineLength(fromX, fromY, ix, iy);
|
|
205
|
+
const pRun = Math.sqrt(dist * dist - pRise * pRise);
|
|
206
|
+
const adjustedRun = Math.sqrt((pRun * pRun) / (1 + m * m)) * (P2x < P1x ? -1 : 1);
|
|
207
|
+
const adjustedRise = m * adjustedRun;
|
|
208
|
+
return { x: ix + adjustedRun, y: iy + adjustedRise };
|
|
231
209
|
}
|
|
232
210
|
static getPointOnCubicBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y) {
|
|
233
211
|
function CB1(t) {
|
package/lib/shapes/TextPath.d.ts
CHANGED
|
@@ -27,7 +27,10 @@ export declare class TextPath extends Shape<TextPathConfig> {
|
|
|
27
27
|
textHeight: number;
|
|
28
28
|
constructor(config?: TextPathConfig);
|
|
29
29
|
_getTextPathLength(): number;
|
|
30
|
-
_getPointAtLength(length: number):
|
|
30
|
+
_getPointAtLength(length: number): {
|
|
31
|
+
x: any;
|
|
32
|
+
y: any;
|
|
33
|
+
} | null;
|
|
31
34
|
_readDataAttribute(): void;
|
|
32
35
|
_sceneFunc(context: Context): void;
|
|
33
36
|
_hitFunc(context: Context): void;
|
|
@@ -444,6 +444,9 @@ class Transformer extends Group_1.Group {
|
|
|
444
444
|
});
|
|
445
445
|
}
|
|
446
446
|
_handleMouseDown(e) {
|
|
447
|
+
if (this._transforming) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
447
450
|
this._movingAnchorName = e.target.name().split(' ')[0];
|
|
448
451
|
var attrs = this._getNodeRect();
|
|
449
452
|
var width = attrs.width;
|