konva 10.1.0 → 10.2.0

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
@@ -13,7 +13,7 @@ export const glob = typeof global !== 'undefined'
13
13
  : {};
14
14
  export const Konva = {
15
15
  _global: glob,
16
- version: '10.1.0',
16
+ version: '10.2.0',
17
17
  isBrowser: detectBrowser(),
18
18
  isUnminified: /param/.test(function (param) { }.toString()),
19
19
  dblClickWindow: 400,
@@ -15,6 +15,7 @@ export interface TransformerConfig extends ContainerConfig {
15
15
  rotationSnaps?: Array<number>;
16
16
  rotationSnapTolerance?: number;
17
17
  rotateAnchorOffset?: number;
18
+ rotateAnchorAngle?: number;
18
19
  rotateAnchorCursor?: string;
19
20
  borderEnabled?: boolean;
20
21
  borderStroke?: string;
@@ -106,6 +107,7 @@ export declare class Transformer extends Group {
106
107
  rotateEnabled: GetSet<boolean, this>;
107
108
  rotateLineVisible: GetSet<boolean, this>;
108
109
  rotateAnchorOffset: GetSet<number, this>;
110
+ rotateAnchorAngle: GetSet<number, this>;
109
111
  rotationSnapTolerance: GetSet<number, this>;
110
112
  rotateAnchorCursor: GetSet<string, this>;
111
113
  padding: GetSet<number, this>;
@@ -11,6 +11,7 @@ const EVENTS_NAME = 'tr-konva';
11
11
  const ATTR_CHANGE_LIST = [
12
12
  'resizeEnabledChange',
13
13
  'rotateAnchorOffsetChange',
14
+ 'rotateAnchorAngleChange',
14
15
  'rotateEnabledChange',
15
16
  'enabledAnchorsChange',
16
17
  'anchorSizeChange',
@@ -409,11 +410,38 @@ export class Transformer extends Group {
409
410
  sceneFunc(ctx, shape) {
410
411
  const tr = shape.getParent();
411
412
  const padding = tr.padding();
413
+ const width = shape.width();
414
+ const height = shape.height();
412
415
  ctx.beginPath();
413
- ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
414
- ctx.moveTo(shape.width() / 2, -padding);
416
+ ctx.rect(-padding, -padding, width + padding * 2, height + padding * 2);
415
417
  if (tr.rotateEnabled() && tr.rotateLineVisible()) {
416
- ctx.lineTo(shape.width() / 2, -tr.rotateAnchorOffset() * Util._sign(shape.height()) - padding);
418
+ const rotateAnchorAngle = tr.rotateAnchorAngle();
419
+ const rotateAnchorOffset = tr.rotateAnchorOffset();
420
+ const rad = Util.degToRad(rotateAnchorAngle);
421
+ const dirX = Math.sin(rad);
422
+ const dirY = -Math.cos(rad);
423
+ const cx = width / 2;
424
+ const cy = height / 2;
425
+ let t = Infinity;
426
+ if (dirY < 0) {
427
+ t = Math.min(t, -cy / dirY);
428
+ }
429
+ else if (dirY > 0) {
430
+ t = Math.min(t, (height - cy) / dirY);
431
+ }
432
+ if (dirX < 0) {
433
+ t = Math.min(t, -cx / dirX);
434
+ }
435
+ else if (dirX > 0) {
436
+ t = Math.min(t, (width - cx) / dirX);
437
+ }
438
+ const edgeX = cx + dirX * t;
439
+ const edgeY = cy + dirY * t;
440
+ const sign = Util._sign(height);
441
+ const endX = edgeX + dirX * rotateAnchorOffset * sign;
442
+ const endY = edgeY + dirY * rotateAnchorOffset * sign;
443
+ ctx.moveTo(edgeX, edgeY);
444
+ ctx.lineTo(endX, endY);
417
445
  }
418
446
  ctx.fillStrokeShape(shape);
419
447
  },
@@ -495,7 +523,8 @@ export class Transformer extends Group {
495
523
  const attrs = this._getNodeRect();
496
524
  x = anchorNode.x() - attrs.width / 2;
497
525
  y = -anchorNode.y() + attrs.height / 2;
498
- let delta = Math.atan2(-y, x) + Math.PI / 2;
526
+ const rotateAnchorAngleRad = Konva.getAngle(this.rotateAnchorAngle());
527
+ let delta = Math.atan2(-y, x) + Math.PI / 2 - rotateAnchorAngleRad;
499
528
  if (attrs.height < 0) {
500
529
  delta -= Math.PI;
501
530
  }
@@ -890,9 +919,32 @@ export class Transformer extends Group {
890
919
  offsetY: anchorSize / 2 - padding,
891
920
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-right') >= 0,
892
921
  });
922
+ const rotateAnchorAngle = this.rotateAnchorAngle();
923
+ const rotateAnchorOffset = this.rotateAnchorOffset();
924
+ const rad = Util.degToRad(rotateAnchorAngle);
925
+ const dirX = Math.sin(rad);
926
+ const dirY = -Math.cos(rad);
927
+ const cx = width / 2;
928
+ const cy = height / 2;
929
+ let t = Infinity;
930
+ if (dirY < 0) {
931
+ t = Math.min(t, -cy / dirY);
932
+ }
933
+ else if (dirY > 0) {
934
+ t = Math.min(t, (height - cy) / dirY);
935
+ }
936
+ if (dirX < 0) {
937
+ t = Math.min(t, -cx / dirX);
938
+ }
939
+ else if (dirX > 0) {
940
+ t = Math.min(t, (width - cx) / dirX);
941
+ }
942
+ const edgeX = cx + dirX * t;
943
+ const edgeY = cy + dirY * t;
944
+ const sign = Util._sign(height);
893
945
  this._batchChangeChild('.rotater', {
894
- x: width / 2,
895
- y: -this.rotateAnchorOffset() * Util._sign(height) - padding,
946
+ x: edgeX + dirX * rotateAnchorOffset * sign,
947
+ y: edgeY + dirY * rotateAnchorOffset * sign - padding * dirY,
896
948
  visible: this.rotateEnabled(),
897
949
  });
898
950
  this._batchChangeChild('.back', {
@@ -980,6 +1032,7 @@ Factory.addGetterSetter(Transformer, 'rotateEnabled', true);
980
1032
  Factory.addGetterSetter(Transformer, 'rotateLineVisible', true);
981
1033
  Factory.addGetterSetter(Transformer, 'rotationSnaps', []);
982
1034
  Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, getNumberValidator());
1035
+ Factory.addGetterSetter(Transformer, 'rotateAnchorAngle', 0, getNumberValidator());
983
1036
  Factory.addGetterSetter(Transformer, 'rotateAnchorCursor', 'crosshair');
984
1037
  Factory.addGetterSetter(Transformer, 'rotationSnapTolerance', 5, getNumberValidator());
985
1038
  Factory.addGetterSetter(Transformer, 'borderEnabled', true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "10.1.0",
3
+ "version": "10.2.0",
4
4
  "description": "HTML5 2d canvas library.",
5
5
  "author": "Anton Lavrenov",
6
6
  "type": "module",