Skip to content

Commit

Permalink
Merge branch 'konvajs:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iaosee authored Dec 27, 2023
2 parents 1db8c55 + a8efcd5 commit 54894d4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

### 9.3.0 (2023-12-20)

- New attribute `rotateLineVisible` for `Konva.Transformer` to show/hide rotate line

### 9.2.3 (2023-10-31)

- Better `Konva.Transformer` work when it has `flipEnabled = false`.
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "konva",
"version": "9.2.3",
"version": "9.3.0",
"author": "Anton Lavrenov",
"files": [
"README.md",
Expand Down Expand Up @@ -60,8 +60,8 @@
],
"devDependencies": {
"@parcel/transformer-image": "2.10.1",
"@size-limit/preset-big-lib": "^10.0.1",
"@types/mocha": "^10.0.3",
"@size-limit/preset-big-lib": "^11.0.1",
"@types/mocha": "^10.0.6",
"canvas": "^2.11.2",
"chai": "4.3.10",
"filehound": "^1.17.6",
Expand All @@ -80,15 +80,15 @@
"mocha-headless-chrome": "^4.0.0",
"parcel": "2.10.1",
"process": "^0.11.10",
"rollup": "^4.2.0",
"rollup": "^4.9.1",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-typescript2": "^0.36.0",
"size-limit": "^10.0.1",
"size-limit": "^11.0.1",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"keywords": [
"canvas",
Expand Down
2 changes: 1 addition & 1 deletion src/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export abstract class Container<
obj.children = [];

this.getChildren().forEach((child) => {
obj.children.push(child.toObject());
obj.children!.push(child.toObject());
});

return obj;
Expand Down
33 changes: 22 additions & 11 deletions src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export interface NodeConfig {
opacity?: number;
scale?: Vector2d;
scaleX?: number;
skewX?: number;
skewY?: number;
scaleY?: number;
rotation?: number;
rotationDeg?: number;
Expand Down Expand Up @@ -911,7 +913,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
* @returns {Object}
*/
getAttrs() {
return this.attrs || {};
return (this.attrs || {}) as Config & Record<string, any>;
}
/**
* set multiple attrs at once using an object literal
Expand Down Expand Up @@ -1481,15 +1483,21 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
* @returns {Object}
*/
toObject() {
var obj = {} as any,
attrs = this.getAttrs(),
var attrs = this.getAttrs() as any,
key,
val,
getter,
defaultValue,
nonPlainObject;

obj.attrs = {};
const obj: {
attrs: Config & Record<string, any>;
className: string;
children?: Array<any>;
} = {
attrs: {} as Config & Record<string, any>,
className: this.getClassName(),
};

for (key in attrs) {
val = attrs[key];
Expand All @@ -1507,12 +1515,11 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
// restore attr value
attrs[key] = val;
if (defaultValue !== val) {
obj.attrs[key] = val;
(obj.attrs as any)[key] = val;
}
}

obj.className = this.getClassName();
return Util._prepareToStringify(obj);
return Util._prepareToStringify(obj) as typeof obj;
}
/**
* convert Node into a JSON string. Returns a JSON string.
Expand Down Expand Up @@ -2088,10 +2095,14 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
try {
const callback = config?.callback;
if (callback) delete config.callback;
this.toCanvas(config).toBlob((blob) => {
resolve(blob);
callback?.(blob);
}, config?.mimeType, config?.quality);
this.toCanvas(config).toBlob(
(blob) => {
resolve(blob);
callback?.(blob);
},
config?.mimeType,
config?.quality
);
} catch (err) {
reject(err);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ export const Util = {
});
return newStart;
},
_prepareToStringify(obj) {
_prepareToStringify<T>(obj: any): T | null {
var desc;

obj.visitedByCircularReferenceRemoval = true;
Expand Down
26 changes: 25 additions & 1 deletion src/shapes/Transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Box extends IRect {
export interface TransformerConfig extends ContainerConfig {
resizeEnabled?: boolean;
rotateEnabled?: boolean;
rotateLineVisible?: boolean;
rotationSnaps?: Array<number>;
rotationSnapTolerance?: number;
rotateAnchorOffset?: number;
Expand All @@ -41,6 +42,12 @@ export interface TransformerConfig extends ContainerConfig {
boundBoxFunc?: (oldBox: Box, newBox: Box) => Box;
useSingleNodeRotation?: boolean;
shouldOverdrawWholeArea?: boolean;
anchorDragBoundFunc?: (
oldPos: Vector2d,
newPos: Vector2d,
evt: any
) => Vector2d;
anchorStyleFunc?: (anchor: Shape) => void;
}

var EVENTS_NAME = 'tr-konva';
Expand Down Expand Up @@ -205,6 +212,7 @@ function getSnap(snaps: Array<number>, newRotationRad: number, tol: number) {
* @param {Object} config
* @param {Boolean} [config.resizeEnabled] Default is true
* @param {Boolean} [config.rotateEnabled] Default is true
* @param {Boolean} [config.rotateLineVisible] Default is true
* @param {Array} [config.rotationSnaps] Array of angles for rotation snaps. Default is []
* @param {Number} [config.rotationSnapTolerance] Snapping tolerance. If closer than this it will snap. Default is 5
* @param {Number} [config.rotateAnchorOffset] Default is 50
Expand Down Expand Up @@ -614,7 +622,7 @@ export class Transformer extends Group {
shape.height() + padding * 2
);
ctx.moveTo(shape.width() / 2, -padding);
if (tr.rotateEnabled()) {
if (tr.rotateEnabled() && tr.rotateLineVisible()) {
ctx.lineTo(
shape.width() / 2,
-tr.rotateAnchorOffset() * Util._sign(shape.height()) - padding
Expand Down Expand Up @@ -1289,6 +1297,7 @@ export class Transformer extends Group {
anchorSize: GetSet<number, this>;
resizeEnabled: GetSet<boolean, this>;
rotateEnabled: GetSet<boolean, this>;
rotateLineVisible: GetSet<boolean, this>;
rotateAnchorOffset: GetSet<number, this>;
rotationSnapTolerance: GetSet<number, this>;
rotateAnchorCursor: GetSet<string, this>;
Expand Down Expand Up @@ -1422,6 +1431,21 @@ Factory.addGetterSetter(Transformer, 'anchorSize', 10, getNumberValidator());
*/
Factory.addGetterSetter(Transformer, 'rotateEnabled', true);

/**
* get/set visibility of a little line that connects transformer and rotate anchor.
* @name Konva.Transformer#rotateLineVisible
* @method
* @param {Boolean} enabled
* @returns {Boolean}
* @example
* // get
* var rotateLineVisible = transformer.rotateLineVisible();
*
* // set
* transformer.rotateLineVisible(false);
*/
Factory.addGetterSetter(Transformer, 'rotateLineVisible', true);

/**
* get/set rotation snaps angles.
* @name Konva.Transformer#rotationSnaps
Expand Down

0 comments on commit 54894d4

Please sign in to comment.