mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
Improvements to Node
Adding a few TypeScript type annotations related to Transform, plus re-using the existing local parent reference when calculating the Node's absolute opacity.
This commit is contained in:
14
src/Node.ts
14
src/Node.ts
@@ -1315,7 +1315,7 @@ export abstract class Node {
|
|||||||
var absOpacity = this.opacity();
|
var absOpacity = this.opacity();
|
||||||
var parent = this.getParent();
|
var parent = this.getParent();
|
||||||
if (parent && !parent._isUnderCache) {
|
if (parent && !parent._isUnderCache) {
|
||||||
absOpacity *= this.getParent().getAbsoluteOpacity();
|
absOpacity *= parent.getAbsoluteOpacity();
|
||||||
}
|
}
|
||||||
return absOpacity;
|
return absOpacity;
|
||||||
}
|
}
|
||||||
@@ -1552,16 +1552,16 @@ export abstract class Node {
|
|||||||
* @name Konva.Node#getAbsoluteTransform
|
* @name Konva.Node#getAbsoluteTransform
|
||||||
* @returns {Konva.Transform}
|
* @returns {Konva.Transform}
|
||||||
*/
|
*/
|
||||||
getAbsoluteTransform(top?) {
|
getAbsoluteTransform(top?: Node): Transform {
|
||||||
// if using an argument, we can't cache the result.
|
// if using an argument, we can't cache the result.
|
||||||
if (top) {
|
if (top) {
|
||||||
return this._getAbsoluteTransform(top);
|
return this._getAbsoluteTransform(top);
|
||||||
} else {
|
} else {
|
||||||
// if no argument, we can cache the result
|
// if no argument, we can cache the result
|
||||||
return this._getCache(ABSOLUTE_TRANSFORM, this._getAbsoluteTransform);
|
return this._getCache(ABSOLUTE_TRANSFORM, this._getAbsoluteTransform) as Transform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_getAbsoluteTransform(top) {
|
_getAbsoluteTransform(top?: Node): Transform {
|
||||||
var at = new Transform();
|
var at = new Transform();
|
||||||
|
|
||||||
// start with stage and traverse downwards to self
|
// start with stage and traverse downwards to self
|
||||||
@@ -1624,10 +1624,10 @@ export abstract class Node {
|
|||||||
* @name Konva.Node#getTransform
|
* @name Konva.Node#getTransform
|
||||||
* @returns {Konva.Transform}
|
* @returns {Konva.Transform}
|
||||||
*/
|
*/
|
||||||
getTransform() {
|
getTransform(): Transform {
|
||||||
return this._getCache(TRANSFORM, this._getTransform);
|
return this._getCache(TRANSFORM, this._getTransform) as Transform;
|
||||||
}
|
}
|
||||||
_getTransform() {
|
_getTransform(): Transform {
|
||||||
var m = new Transform(),
|
var m = new Transform(),
|
||||||
x = this.x(),
|
x = this.x(),
|
||||||
y = this.y(),
|
y = this.y(),
|
||||||
|
Reference in New Issue
Block a user