konva 9.2.0 → 9.2.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.
@@ -341,7 +341,7 @@ class Path extends Shape_1.Shape {
341
341
  if (isNaN(p[0])) {
342
342
  break;
343
343
  }
344
- var cmd = null;
344
+ var cmd = '';
345
345
  var points = [];
346
346
  var startX = cpx, startY = cpy;
347
347
  var prevCmd, ctlPtx, ctlPty;
@@ -1,5 +1,5 @@
1
1
  import { Shape, ShapeConfig } from '../Shape.js';
2
- import { GetSet } from '../types.js';
2
+ import { GetSet, Vector2d } from '../types.js';
3
3
  import { Context } from '../Context.js';
4
4
  export interface RegularPolygonConfig extends ShapeConfig {
5
5
  sides: number;
@@ -7,10 +7,10 @@ export interface RegularPolygonConfig extends ShapeConfig {
7
7
  }
8
8
  export declare class RegularPolygon extends Shape<RegularPolygonConfig> {
9
9
  _sceneFunc(context: Context): void;
10
- _getPoints(): any[];
10
+ _getPoints(): Vector2d[];
11
11
  getSelfRect(): {
12
- x: any;
13
- y: any;
12
+ x: number;
13
+ y: number;
14
14
  width: number;
15
15
  height: number;
16
16
  };
@@ -47,6 +47,7 @@ export declare class Text extends Shape<TextConfig> {
47
47
  _shouldHandleEllipsis(currentHeightPx: number): boolean;
48
48
  _tryToAddEllipsisToLastLine(): void;
49
49
  getStrokeScaleEnabled(): boolean;
50
+ _useBufferCanvas(): boolean;
50
51
  fontFamily: GetSet<string, this>;
51
52
  fontSize: GetSet<number, this>;
52
53
  fontStyle: GetSet<string, this>;
@@ -343,6 +343,15 @@ class Text extends Shape_1.Shape {
343
343
  getStrokeScaleEnabled() {
344
344
  return true;
345
345
  }
346
+ _useBufferCanvas() {
347
+ const hasLine = this.textDecoration().indexOf('underline') !== -1 ||
348
+ this.textDecoration().indexOf('line-through') !== -1;
349
+ const hasShadow = this.hasShadow();
350
+ if (hasLine && hasShadow) {
351
+ return true;
352
+ }
353
+ return super._useBufferCanvas();
354
+ }
346
355
  }
347
356
  exports.Text = Text;
348
357
  Text.prototype._fillFunc = _fillFunc;
@@ -1,6 +1,7 @@
1
1
  import { Context } from '../Context.js';
2
2
  import { Shape, ShapeConfig } from '../Shape.js';
3
- import { GetSet, Vector2d } from '../types.js';
3
+ import { Text } from './Text.js';
4
+ import { GetSet, PathSegment, Vector2d } from '../types.js';
4
5
  export interface TextPathConfig extends ShapeConfig {
5
6
  text?: string;
6
7
  data?: string;
@@ -11,7 +12,7 @@ export interface TextPathConfig extends ShapeConfig {
11
12
  }
12
13
  export declare class TextPath extends Shape<TextPathConfig> {
13
14
  dummyCanvas: HTMLCanvasElement;
14
- dataArray: any[];
15
+ dataArray: PathSegment[];
15
16
  glyphInfo: Array<{
16
17
  transposeX: number;
17
18
  transposeY: number;
@@ -32,13 +33,13 @@ export declare class TextPath extends Shape<TextPathConfig> {
32
33
  _hitFunc(context: Context): void;
33
34
  getTextWidth(): number;
34
35
  getTextHeight(): number;
35
- setText(text: string): any;
36
- _getContextFont(): any;
36
+ setText(text: string): Text;
37
+ _getContextFont(): string;
37
38
  _getTextSize(text: string): {
38
39
  width: number;
39
40
  height: number;
40
41
  };
41
- _setTextData(): any;
42
+ _setTextData(): null | undefined;
42
43
  getSelfRect(): {
43
44
  x: number;
44
45
  y: number;
@@ -13,6 +13,7 @@ export interface TransformerConfig extends ContainerConfig {
13
13
  rotationSnaps?: Array<number>;
14
14
  rotationSnapTolerance?: number;
15
15
  rotateAnchorOffset?: number;
16
+ rotateAnchorCursor?: string;
16
17
  borderEnabled?: boolean;
17
18
  borderStroke?: string;
18
19
  borderStrokeWidth?: number;
@@ -35,7 +36,7 @@ export interface TransformerConfig extends ContainerConfig {
35
36
  }
36
37
  export declare class Transformer extends Group {
37
38
  _nodes: Array<Node>;
38
- _movingAnchorName: string;
39
+ _movingAnchorName: string | null;
39
40
  _transforming: boolean;
40
41
  _anchorDragOffset: Vector2d;
41
42
  sin: number;
@@ -49,7 +50,7 @@ export declare class Transformer extends Group {
49
50
  setNodes(nodes?: Array<Node>): this;
50
51
  _proxyDrag(node: Node): void;
51
52
  getNodes(): Node<import("../Node.js").NodeConfig>[];
52
- getActiveAnchor(): string;
53
+ getActiveAnchor(): string | null;
53
54
  detach(): void;
54
55
  _resetTransformCache(): void;
55
56
  _getNodeRect(): any;
@@ -97,6 +98,7 @@ export declare class Transformer extends Group {
97
98
  rotateEnabled: GetSet<boolean, this>;
98
99
  rotateAnchorOffset: GetSet<number, this>;
99
100
  rotationSnapTolerance: GetSet<number, this>;
101
+ rotateAnchorCursor: GetSet<string, this>;
100
102
  padding: GetSet<number, this>;
101
103
  borderEnabled: GetSet<boolean, this>;
102
104
  borderStroke: GetSet<string, this>;
@@ -55,9 +55,9 @@ var ANGLES = {
55
55
  'bottom-right': 135,
56
56
  };
57
57
  const TOUCH_DEVICE = 'ontouchstart' in Global_1.Konva._global;
58
- function getCursor(anchorName, rad) {
58
+ function getCursor(anchorName, rad, rotateCursor) {
59
59
  if (anchorName === 'rotater') {
60
- return 'crosshair';
60
+ return rotateCursor;
61
61
  }
62
62
  rad += Util_1.Util.degToRad(ANGLES[anchorName] || 0);
63
63
  var angle = ((Util_1.Util.radToDeg(rad) % 360) + 360) % 360;
@@ -118,8 +118,12 @@ function rotateAroundPoint(shape, angleRad, point) {
118
118
  const y = point.y +
119
119
  (shape.x - point.x) * Math.sin(angleRad) +
120
120
  (shape.y - point.y) * Math.cos(angleRad);
121
- return Object.assign(Object.assign({}, shape), { rotation: shape.rotation + angleRad, x,
122
- y });
121
+ return {
122
+ ...shape,
123
+ rotation: shape.rotation + angleRad,
124
+ x,
125
+ y,
126
+ };
123
127
  }
124
128
  function rotateAroundCenter(shape, deltaRad) {
125
129
  const center = getCenter(shape);
@@ -140,6 +144,7 @@ function getSnap(snaps, newRotationRad, tol) {
140
144
  class Transformer extends Group_1.Group {
141
145
  constructor(config) {
142
146
  super(config);
147
+ this._movingAnchorName = null;
143
148
  this._transforming = false;
144
149
  this._createElements();
145
150
  this._handleMouseMove = this._handleMouseMove.bind(this);
@@ -318,7 +323,7 @@ class Transformer extends Group_1.Group {
318
323
  });
319
324
  const tr = new Util_1.Transform();
320
325
  tr.rotate(-Global_1.Konva.getAngle(this.rotation()));
321
- var minX, minY, maxX, maxY;
326
+ var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
322
327
  totalPoints.forEach(function (point) {
323
328
  var transformed = tr.point(point);
324
329
  if (minX === undefined) {
@@ -354,9 +359,9 @@ class Transformer extends Group_1.Group {
354
359
  }
355
360
  _createElements() {
356
361
  this._createBack();
357
- ANCHORS_NAMES.forEach(function (name) {
362
+ ANCHORS_NAMES.forEach((name) => {
358
363
  this._createAnchor(name);
359
- }.bind(this));
364
+ });
360
365
  this._createAnchor('rotater');
361
366
  }
362
367
  _createAnchor(name) {
@@ -382,7 +387,8 @@ class Transformer extends Group_1.Group {
382
387
  });
383
388
  anchor.on('mouseenter', () => {
384
389
  var rad = Global_1.Konva.getAngle(this.rotation());
385
- var cursor = getCursor(name, rad);
390
+ var rotateCursor = this.rotateAnchorCursor();
391
+ var cursor = getCursor(name, rad, rotateCursor);
386
392
  anchor.getStage().content &&
387
393
  (anchor.getStage().content.style.cursor = cursor);
388
394
  this._cursorChange = true;
@@ -400,16 +406,16 @@ class Transformer extends Group_1.Group {
400
406
  width: 0,
401
407
  height: 0,
402
408
  draggable: true,
403
- sceneFunc(ctx) {
404
- var tr = this.getParent();
409
+ sceneFunc(ctx, shape) {
410
+ var tr = shape.getParent();
405
411
  var padding = tr.padding();
406
412
  ctx.beginPath();
407
- ctx.rect(-padding, -padding, this.width() + padding * 2, this.height() + padding * 2);
408
- ctx.moveTo(this.width() / 2, -padding);
413
+ ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
414
+ ctx.moveTo(shape.width() / 2, -padding);
409
415
  if (tr.rotateEnabled()) {
410
- ctx.lineTo(this.width() / 2, -tr.rotateAnchorOffset() * Util_1.Util._sign(this.height()) - padding);
416
+ ctx.lineTo(shape.width() / 2, -tr.rotateAnchorOffset() * Util_1.Util._sign(shape.height()) - padding);
411
417
  }
412
- ctx.fillStrokeShape(this);
418
+ ctx.fillStrokeShape(shape);
413
419
  },
414
420
  hitFunc: (ctx, shape) => {
415
421
  if (!this.shouldOverdrawWholeArea()) {
@@ -963,6 +969,7 @@ Factory_1.Factory.addGetterSetter(Transformer, 'anchorSize', 10, (0, Validators_
963
969
  Factory_1.Factory.addGetterSetter(Transformer, 'rotateEnabled', true);
964
970
  Factory_1.Factory.addGetterSetter(Transformer, 'rotationSnaps', []);
965
971
  Factory_1.Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, (0, Validators_1.getNumberValidator)());
972
+ Factory_1.Factory.addGetterSetter(Transformer, 'rotateAnchorCursor', 'crosshair');
966
973
  Factory_1.Factory.addGetterSetter(Transformer, 'rotationSnapTolerance', 5, (0, Validators_1.getNumberValidator)());
967
974
  Factory_1.Factory.addGetterSetter(Transformer, 'borderEnabled', true);
968
975
  Factory_1.Factory.addGetterSetter(Transformer, 'anchorStroke', 'rgb(0, 161, 255)');
package/lib/types.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface Vector2d {
9
9
  export interface PathSegment {
10
10
  command: 'm' | 'M' | 'l' | 'L' | 'v' | 'V' | 'h' | 'H' | 'z' | 'Z' | 'c' | 'C' | 'q' | 'Q' | 't' | 'T' | 's' | 'S' | 'a' | 'A';
11
11
  start: Vector2d;
12
- points: Vector2d[];
12
+ points: number[];
13
13
  pathLength: number;
14
14
  }
15
15
  export interface IRect {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "9.2.0",
3
+ "version": "9.2.1",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",
@@ -59,11 +59,11 @@
59
59
  }
60
60
  ],
61
61
  "devDependencies": {
62
- "@parcel/transformer-image": "2.8.3",
63
- "@size-limit/preset-big-lib": "^8.2.4",
62
+ "@parcel/transformer-image": "2.9.3",
63
+ "@size-limit/preset-big-lib": "^8.2.6",
64
64
  "@types/mocha": "^10.0.1",
65
65
  "canvas": "^2.11.2",
66
- "chai": "4.3.7",
66
+ "chai": "4.3.8",
67
67
  "filehound": "^1.17.6",
68
68
  "gulp": "^4.0.2",
69
69
  "gulp-concat": "^2.6.1",
@@ -78,17 +78,17 @@
78
78
  "gulp-util": "^3.0.8",
79
79
  "mocha": "10.2.0",
80
80
  "mocha-headless-chrome": "^4.0.0",
81
- "parcel": "2.8.3",
81
+ "parcel": "2.9.3",
82
82
  "process": "^0.11.10",
83
- "rollup": "^3.20.2",
83
+ "rollup": "^3.28.1",
84
84
  "rollup-plugin-commonjs": "^10.1.0",
85
85
  "rollup-plugin-node-resolve": "^5.2.0",
86
86
  "rollup-plugin-sourcemaps": "^0.6.3",
87
- "rollup-plugin-typescript2": "^0.34.1",
88
- "size-limit": "^8.2.4",
87
+ "rollup-plugin-typescript2": "^0.35.0",
88
+ "size-limit": "^8.2.6",
89
89
  "ts-mocha": "^10.0.0",
90
90
  "ts-node": "^10.9.1",
91
- "typescript": "^5.0.4"
91
+ "typescript": "^5.2.2"
92
92
  },
93
93
  "keywords": [
94
94
  "canvas",