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/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.10',
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
- window.addEventListener('focus', () => {
698
+ document.addEventListener('visibilitychange', () => {
699
699
  exports.stages.forEach((stage) => {
700
700
  stage.batchDraw();
701
701
  });
@@ -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): 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): any;
24
- static getPointOnLine(dist: any, P1x: any, P1y: any, P2x: any, P2y: any, fromX?: any, fromY?: any): any;
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;
@@ -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
- if (fromX === undefined) {
187
- fromX = P1x;
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
- pt = {
201
- x: fromX,
202
- y: fromY + rise,
203
- };
204
- }
205
- else if ((fromY - P1y) / (fromX - P1x + 0.00000001) === m) {
206
- pt = {
207
- x: fromX + run,
208
- y: fromY + rise,
209
- };
210
- }
211
- else {
212
- var ix, iy;
213
- var len = this.getLineLength(P1x, P1y, P2x, P2y);
214
- var u = (fromX - P1x) * (P2x - P1x) + (fromY - P1y) * (P2y - P1y);
215
- u = u / (len * len);
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) {
@@ -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): any;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "9.3.10",
3
+ "version": "9.3.12",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",