konva 9.2.1 → 9.2.3

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/Context.d.ts CHANGED
@@ -2,7 +2,10 @@ import { Canvas } from './Canvas.js';
2
2
  import { Shape } from './Shape.js';
3
3
  import { IRect } from './types.js';
4
4
  import type { Node } from './Node.js';
5
- declare var CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled"];
5
+ declare var CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "letterSpacing", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "direction", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled"];
6
+ interface ExtendedCanvasRenderingContext2D extends CanvasRenderingContext2D {
7
+ letterSpacing: string;
8
+ }
6
9
  export declare class Context {
7
10
  canvas: Canvas;
8
11
  _context: CanvasRenderingContext2D;
@@ -64,7 +67,7 @@ export declare class Context {
64
67
  _enableTrace(): void;
65
68
  _applyGlobalCompositeOperation(node: any): void;
66
69
  }
67
- type CanvasContextProps = Pick<CanvasRenderingContext2D, (typeof CONTEXT_PROPERTIES)[number]>;
70
+ type CanvasContextProps = Pick<ExtendedCanvasRenderingContext2D, (typeof CONTEXT_PROPERTIES)[number]>;
68
71
  export interface Context extends CanvasContextProps {
69
72
  }
70
73
  export declare class SceneContext extends Context {
package/lib/Context.js CHANGED
@@ -57,11 +57,13 @@ var CONTEXT_PROPERTIES = [
57
57
  'shadowBlur',
58
58
  'shadowOffsetX',
59
59
  'shadowOffsetY',
60
+ 'letterSpacing',
60
61
  'lineCap',
61
62
  'lineDashOffset',
62
63
  'lineJoin',
63
64
  'lineWidth',
64
65
  'miterLimit',
66
+ 'direction',
65
67
  'font',
66
68
  'textAlign',
67
69
  'textBaseline',
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.2.1',
19
+ version: '9.2.3',
20
20
  isBrowser: detectBrowser(),
21
21
  isUnminified: /param/.test(function (param) { }.toString()),
22
22
  dblClickWindow: 400,
package/lib/Shape.d.ts CHANGED
@@ -110,8 +110,8 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
110
110
  height: number;
111
111
  };
112
112
  getClientRect(config?: ShapeGetClientRectConfig): {
113
- width: any;
114
- height: any;
113
+ width: number;
114
+ height: number;
115
115
  x: number;
116
116
  y: number;
117
117
  };
@@ -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;
@@ -48,6 +49,7 @@ export declare class Text extends Shape<TextConfig> {
48
49
  _tryToAddEllipsisToLastLine(): void;
49
50
  getStrokeScaleEnabled(): boolean;
50
51
  _useBufferCanvas(): boolean;
52
+ direction: GetSet<string, this>;
51
53
  fontFamily: GetSet<string, this>;
52
54
  fontSize: GetSet<number, this>;
53
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;
@@ -368,6 +376,7 @@ Text.prototype._attrsAffectingSize = [
368
376
  (0, Global_1._registerNode)(Text);
369
377
  Factory_1.Factory.overWriteSetter(Text, 'width', (0, Validators_1.getNumberOrAutoValidator)());
370
378
  Factory_1.Factory.overWriteSetter(Text, 'height', (0, Validators_1.getNumberOrAutoValidator)());
379
+ Factory_1.Factory.addGetterSetter(Text, 'direction', INHERIT);
371
380
  Factory_1.Factory.addGetterSetter(Text, 'fontFamily', 'Arial');
372
381
  Factory_1.Factory.addGetterSetter(Text, 'fontSize', 12, (0, Validators_1.getNumberValidator)());
373
382
  Factory_1.Factory.addGetterSetter(Text, 'fontStyle', NORMAL);
@@ -688,7 +688,6 @@ class Transformer extends Group_1.Group {
688
688
  this.update();
689
689
  return;
690
690
  }
691
- const allowNegativeScale = this.flipEnabled();
692
691
  var t = new Util_1.Transform();
693
692
  t.rotate(Global_1.Konva.getAngle(this.rotation()));
694
693
  if (this._movingAnchorName &&
@@ -704,10 +703,6 @@ class Transformer extends Group_1.Group {
704
703
  this._movingAnchorName = this._movingAnchorName.replace('left', 'right');
705
704
  this._anchorDragOffset.x -= offset.x;
706
705
  this._anchorDragOffset.y -= offset.y;
707
- if (!allowNegativeScale) {
708
- this.update();
709
- return;
710
- }
711
706
  }
712
707
  else if (this._movingAnchorName &&
713
708
  newAttrs.width < 0 &&
@@ -720,10 +715,6 @@ class Transformer extends Group_1.Group {
720
715
  this._anchorDragOffset.x -= offset.x;
721
716
  this._anchorDragOffset.y -= offset.y;
722
717
  newAttrs.width += this.padding() * 2;
723
- if (!allowNegativeScale) {
724
- this.update();
725
- return;
726
- }
727
718
  }
728
719
  if (this._movingAnchorName &&
729
720
  newAttrs.height < 0 &&
@@ -738,10 +729,6 @@ class Transformer extends Group_1.Group {
738
729
  this._anchorDragOffset.x -= offset.x;
739
730
  this._anchorDragOffset.y -= offset.y;
740
731
  newAttrs.height += this.padding() * 2;
741
- if (!allowNegativeScale) {
742
- this.update();
743
- return;
744
- }
745
732
  }
746
733
  else if (this._movingAnchorName &&
747
734
  newAttrs.height < 0 &&
@@ -754,10 +741,6 @@ class Transformer extends Group_1.Group {
754
741
  this._anchorDragOffset.x -= offset.x;
755
742
  this._anchorDragOffset.y -= offset.y;
756
743
  newAttrs.height += this.padding() * 2;
757
- if (!allowNegativeScale) {
758
- this.update();
759
- return;
760
- }
761
744
  }
762
745
  if (this.boundBoxFunc()) {
763
746
  const bounded = this.boundBoxFunc()(oldAttrs, newAttrs);
@@ -774,9 +757,19 @@ class Transformer extends Group_1.Group {
774
757
  oldTr.rotate(oldAttrs.rotation);
775
758
  oldTr.scale(oldAttrs.width / baseSize, oldAttrs.height / baseSize);
776
759
  const newTr = new Util_1.Transform();
777
- newTr.translate(newAttrs.x, newAttrs.y);
778
- newTr.rotate(newAttrs.rotation);
779
- newTr.scale(newAttrs.width / baseSize, newAttrs.height / baseSize);
760
+ const newScaleX = newAttrs.width / baseSize;
761
+ const newScaleY = newAttrs.height / baseSize;
762
+ if (this.flipEnabled() === false) {
763
+ newTr.translate(newAttrs.x, newAttrs.y);
764
+ newTr.rotate(newAttrs.rotation);
765
+ newTr.translate(newAttrs.width < 0 ? newAttrs.width : 0, newAttrs.height < 0 ? newAttrs.height : 0);
766
+ newTr.scale(Math.abs(newScaleX), Math.abs(newScaleY));
767
+ }
768
+ else {
769
+ newTr.translate(newAttrs.x, newAttrs.y);
770
+ newTr.rotate(newAttrs.rotation);
771
+ newTr.scale(newScaleX, newScaleY);
772
+ }
780
773
  const delta = newTr.multiply(oldTr.invert());
781
774
  this._nodes.forEach((node) => {
782
775
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "9.2.1",
3
+ "version": "9.2.3",
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.9.3",
63
- "@size-limit/preset-big-lib": "^8.2.6",
64
- "@types/mocha": "^10.0.1",
62
+ "@parcel/transformer-image": "2.10.1",
63
+ "@size-limit/preset-big-lib": "^10.0.1",
64
+ "@types/mocha": "^10.0.3",
65
65
  "canvas": "^2.11.2",
66
- "chai": "4.3.8",
66
+ "chai": "4.3.10",
67
67
  "filehound": "^1.17.6",
68
68
  "gulp": "^4.0.2",
69
69
  "gulp-concat": "^2.6.1",
@@ -78,14 +78,14 @@
78
78
  "gulp-util": "^3.0.8",
79
79
  "mocha": "10.2.0",
80
80
  "mocha-headless-chrome": "^4.0.0",
81
- "parcel": "2.9.3",
81
+ "parcel": "2.10.1",
82
82
  "process": "^0.11.10",
83
- "rollup": "^3.28.1",
83
+ "rollup": "^4.2.0",
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.35.0",
88
- "size-limit": "^8.2.6",
87
+ "rollup-plugin-typescript2": "^0.36.0",
88
+ "size-limit": "^10.0.1",
89
89
  "ts-mocha": "^10.0.0",
90
90
  "ts-node": "^10.9.1",
91
91
  "typescript": "^5.2.2"