From 56ff555fdb6f91ba134ca7fd43c88554d590ef19 Mon Sep 17 00:00:00 2001 From: risingbirdsong Date: Tue, 30 Jun 2020 12:22:34 -0700 Subject: [PATCH] added animation option interface to replace type any. tested various options out with the .to method and the options i included in the interface were the ones that were clearly animating, excluded options that seemed to have no animation effect. included offset y and x because they do animate, though they may not be appropriate in the interface. not exhaustive, may be missing options which should be included. --- src/Node.ts | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Node.ts b/src/Node.ts index 8a3b2bb9..4c29f76b 100644 --- a/src/Node.ts +++ b/src/Node.ts @@ -418,10 +418,10 @@ export abstract class Node { y -= offset; var cachedSceneCanvas = new SceneCanvas({ - pixelRatio: pixelRatio, - width: width, - height: height, - }), + pixelRatio: pixelRatio, + width: width, + height: height, + }), cachedFilterCanvas = new SceneCanvas({ pixelRatio: pixelRatio, width: 0, @@ -645,8 +645,8 @@ export abstract class Node { if (typeof filter !== 'function') { Util.error( 'Filter should be type of function, but got ' + - typeof filter + - ' instead. Please check correct filters' + typeof filter + + ' instead. Please check correct filters' ); continue; } @@ -656,8 +656,8 @@ export abstract class Node { } catch (e) { Util.error( 'Unable to apply filter. ' + - e.message + - ' This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.' + e.message + + ' This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.' ); } @@ -1427,10 +1427,10 @@ export abstract class Node { if (zIndex < 0 || zIndex >= this.parent.children.length) { Util.warn( 'Unexpected value ' + - zIndex + - ' for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to ' + - (this.parent.children.length - 1) + - '.' + zIndex + + ' for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to ' + + (this.parent.children.length - 1) + + '.' ); } var index = this.index; @@ -1598,8 +1598,8 @@ export abstract class Node { if (!Util.isValidSelector(sel)) { Util.warn( 'Selector "' + - sel + - '" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".' + sel + + '" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".' ); Util.warn( 'If you have a custom shape with such className, please change it to start with upper letter like "Triangle".' @@ -2525,7 +2525,7 @@ export abstract class Node { skewX: GetSet; skewY: GetSet; - to: (params: any) => void; + to: (params: animOptions) => void; transformsEnabled: GetSet; @@ -2572,8 +2572,8 @@ export abstract class Node { if (!_NODES_REGISTRY[className]) { Util.warn( 'Can not find a node with class name "' + - className + - '". Fallback to "Shape".' + className + + '". Fallback to "Shape".' ); className = 'Shape'; } @@ -2592,6 +2592,22 @@ export abstract class Node { } } +interface animOptions { + x?: number + y?: number; + height?: number; + width?: number; + skewX?: number; + skewY?: number; + scaleY?: number; + scaleX?: number; + rotation?: number; + opacity?: number; + offsetY?: number; + offsetX?: number; + brightness?: number; +} + Node.prototype.nodeType = 'Node'; Node.prototype._attrsAffectingSize = [];