konva 9.2.0 → 9.2.2

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
  };
@@ -3,6 +3,7 @@ import { Shape, ShapeConfig } from '../Shape.js';
3
3
  import { GetSet } from '../types.js';
4
4
  export declare function stringToArray(string: string): string[];
5
5
  export interface TextConfig extends ShapeConfig {
6
+ direction?: string;
6
7
  text?: string;
7
8
  fontFamily?: string;
8
9
  fontSize?: number;
@@ -47,6 +48,8 @@ export declare class Text extends Shape<TextConfig> {
47
48
  _shouldHandleEllipsis(currentHeightPx: number): boolean;
48
49
  _tryToAddEllipsisToLastLine(): void;
49
50
  getStrokeScaleEnabled(): boolean;
51
+ _useBufferCanvas(): boolean;
52
+ direction: GetSet<string, this>;
50
53
  fontFamily: GetSet<string, this>;
51
54
  fontSize: GetSet<number, this>;
52
55
  fontStyle: GetSet<string, this>;
@@ -10,7 +10,8 @@ function stringToArray(string) {
10
10
  return Array.from(string);
11
11
  }
12
12
  exports.stringToArray = stringToArray;
13
- var AUTO = 'auto', CENTER = 'center', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST = [
13
+ var AUTO = 'auto', CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', LTR = 'ltr', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST = [
14
+ 'direction',
14
15
  'fontFamily',
15
16
  'fontSize',
16
17
  'fontStyle',
@@ -79,11 +80,15 @@ class Text extends Shape_1.Shape {
79
80
  if (!this.text()) {
80
81
  return;
81
82
  }
82
- var padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
83
+ var padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
84
+ direction = direction === INHERIT ? context.direction : direction;
83
85
  var translateY = 0;
84
86
  var translateY = lineHeightPx / 2;
85
87
  var lineTranslateX = 0;
86
88
  var lineTranslateY = 0;
89
+ if (direction === RTL) {
90
+ context.setAttr('direction', direction);
91
+ }
87
92
  context.setAttr('font', this._getContextFont());
88
93
  context.setAttr('textBaseline', MIDDLE);
89
94
  context.setAttr('textAlign', LEFT);
@@ -137,7 +142,7 @@ class Text extends Shape_1.Shape {
137
142
  context.stroke();
138
143
  context.restore();
139
144
  }
140
- if (letterSpacing !== 0 || align === JUSTIFY) {
145
+ if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) {
141
146
  spacesNumber = text.split(' ').length - 1;
142
147
  var array = stringToArray(text);
143
148
  for (var li = 0; li < array.length; li++) {
@@ -153,6 +158,9 @@ class Text extends Shape_1.Shape {
153
158
  }
154
159
  }
155
160
  else {
161
+ if (letterSpacing !== 0) {
162
+ context.setAttr('letterSpacing', `${letterSpacing}px`);
163
+ }
156
164
  this._partialTextX = lineTranslateX;
157
165
  this._partialTextY = translateY + lineTranslateY;
158
166
  this._partialText = text;
@@ -343,6 +351,15 @@ class Text extends Shape_1.Shape {
343
351
  getStrokeScaleEnabled() {
344
352
  return true;
345
353
  }
354
+ _useBufferCanvas() {
355
+ const hasLine = this.textDecoration().indexOf('underline') !== -1 ||
356
+ this.textDecoration().indexOf('line-through') !== -1;
357
+ const hasShadow = this.hasShadow();
358
+ if (hasLine && hasShadow) {
359
+ return true;
360
+ }
361
+ return super._useBufferCanvas();
362
+ }
346
363
  }
347
364
  exports.Text = Text;
348
365
  Text.prototype._fillFunc = _fillFunc;
@@ -359,6 +376,7 @@ Text.prototype._attrsAffectingSize = [
359
376
  (0, Global_1._registerNode)(Text);
360
377
  Factory_1.Factory.overWriteSetter(Text, 'width', (0, Validators_1.getNumberOrAutoValidator)());
361
378
  Factory_1.Factory.overWriteSetter(Text, 'height', (0, Validators_1.getNumberOrAutoValidator)());
379
+ Factory_1.Factory.addGetterSetter(Text, 'direction', INHERIT);
362
380
  Factory_1.Factory.addGetterSetter(Text, 'fontFamily', 'Arial');
363
381
  Factory_1.Factory.addGetterSetter(Text, 'fontSize', 12, (0, Validators_1.getNumberValidator)());
364
382
  Factory_1.Factory.addGetterSetter(Text, 'fontStyle', NORMAL);
@@ -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.2",
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",