From ffc58d248bbb9351066546d15e703f64b274ac2a Mon Sep 17 00:00:00 2001 From: kyechan99 Date: Thu, 18 Jul 2024 18:46:56 +0900 Subject: [PATCH 1/4] fix: specify type Text.measureSize --- src/shapes/Text.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shapes/Text.ts b/src/shapes/Text.ts index 07418fa0..ddd65559 100644 --- a/src/shapes/Text.ts +++ b/src/shapes/Text.ts @@ -392,13 +392,13 @@ export class Text extends Shape { * That method can't handle multiline text. * @method * @name Konva.Text#measureSize - * @param {String} [text] text to measure - * @returns {Object} { width , height} of measured text + * @param {String} text text to measure + * @returns {Object} { width , height } of measured text */ - measureSize(text) { + measureSize(text: string) { var _context = getDummyContext(), fontSize = this.fontSize(), - metrics; + metrics: TextMetrics; _context.save(); _context.font = this._getContextFont(); From e7dfe86a394283420377cdf2db99a412f1b4bf06 Mon Sep 17 00:00:00 2001 From: kyechan99 Date: Thu, 18 Jul 2024 18:59:33 +0900 Subject: [PATCH 2/4] fix: specify return type Path.getPoint static methods --- src/shapes/Path.ts | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/shapes/Path.ts b/src/shapes/Path.ts index e91f5400..d860b853 100644 --- a/src/shapes/Path.ts +++ b/src/shapes/Path.ts @@ -2,7 +2,7 @@ import { Factory } from '../Factory'; import { Shape, ShapeConfig } from '../Shape'; import { _registerNode } from '../Global'; -import { GetSet, PathSegment } from '../types'; +import { GetSet, PathSegment, Vector2d } from '../types'; import { getCubicArcLength, getQuadraticArcLength, @@ -235,7 +235,10 @@ export class Path extends Shape { return pathLength; } - static getPointAtLengthOfDataArray(length: number, dataArray) { + static getPointAtLengthOfDataArray( + length: number, + dataArray + ): Vector2d | null { var point, i = 0, ii = dataArray.length; @@ -319,7 +322,7 @@ export class Path extends Shape { return null; } - static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX?, fromY?) { + static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX?, fromY?): Vector2d { fromX = fromX ?? P1x; fromY = fromY ?? P1y; @@ -354,7 +357,17 @@ export class Path extends Shape { return { x: ix + adjustedRun, y: iy + adjustedRise }; } - static getPointOnCubicBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y) { + static getPointOnCubicBezier( + pct, + P1x, + P1y, + P2x, + P2y, + P3x, + P3y, + P4x, + P4y + ): Vector2d { function CB1(t) { return t * t * t; } @@ -375,7 +388,15 @@ export class Path extends Shape { y: y, }; } - static getPointOnQuadraticBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y) { + static getPointOnQuadraticBezier( + pct, + P1x, + P1y, + P2x, + P2y, + P3x, + P3y + ): Vector2d { function QB1(t) { return t * t; } From c6a09c885754e82fd03e5e307829359765c0fd09 Mon Sep 17 00:00:00 2001 From: kyechan99 Date: Fri, 19 Jul 2024 10:15:51 +0900 Subject: [PATCH 3/4] fix: revert changes Path.gitPoint static methods --- src/shapes/Path.ts | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/src/shapes/Path.ts b/src/shapes/Path.ts index d860b853..e91f5400 100644 --- a/src/shapes/Path.ts +++ b/src/shapes/Path.ts @@ -2,7 +2,7 @@ import { Factory } from '../Factory'; import { Shape, ShapeConfig } from '../Shape'; import { _registerNode } from '../Global'; -import { GetSet, PathSegment, Vector2d } from '../types'; +import { GetSet, PathSegment } from '../types'; import { getCubicArcLength, getQuadraticArcLength, @@ -235,10 +235,7 @@ export class Path extends Shape { return pathLength; } - static getPointAtLengthOfDataArray( - length: number, - dataArray - ): Vector2d | null { + static getPointAtLengthOfDataArray(length: number, dataArray) { var point, i = 0, ii = dataArray.length; @@ -322,7 +319,7 @@ export class Path extends Shape { return null; } - static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX?, fromY?): Vector2d { + static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX?, fromY?) { fromX = fromX ?? P1x; fromY = fromY ?? P1y; @@ -357,17 +354,7 @@ export class Path extends Shape { return { x: ix + adjustedRun, y: iy + adjustedRise }; } - static getPointOnCubicBezier( - pct, - P1x, - P1y, - P2x, - P2y, - P3x, - P3y, - P4x, - P4y - ): Vector2d { + static getPointOnCubicBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y) { function CB1(t) { return t * t * t; } @@ -388,15 +375,7 @@ export class Path extends Shape { y: y, }; } - static getPointOnQuadraticBezier( - pct, - P1x, - P1y, - P2x, - P2y, - P3x, - P3y - ): Vector2d { + static getPointOnQuadraticBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y) { function QB1(t) { return t * t; } From ad0c15a3ac7322ec89c3bae2b1a3a4b982f00cd7 Mon Sep 17 00:00:00 2001 From: kyechan99 Date: Fri, 19 Jul 2024 23:47:56 +0900 Subject: [PATCH 4/4] fix: specify return type Path.getPoint* methods --- src/shapes/Path.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/shapes/Path.ts b/src/shapes/Path.ts index e91f5400..67a905e2 100644 --- a/src/shapes/Path.ts +++ b/src/shapes/Path.ts @@ -235,8 +235,8 @@ export class Path extends Shape { return pathLength; } - static getPointAtLengthOfDataArray(length: number, dataArray) { - var point, + static getPointAtLengthOfDataArray(length: number, dataArray: PathSegment[]) { + var points: number[], i = 0, ii = dataArray.length; @@ -250,18 +250,18 @@ export class Path extends Shape { } if (i === ii) { - point = dataArray[i - 1].points.slice(-2); + points = dataArray[i - 1].points.slice(-2); return { - x: point[0], - y: point[1], + x: points[0], + y: points[1], }; } if (length < 0.01) { - point = dataArray[i].points.slice(0, 2); + points = dataArray[i].points.slice(0, 2); return { - x: point[0], - y: point[1], + x: points[0], + y: points[1], }; } @@ -319,7 +319,15 @@ export class Path extends Shape { return null; } - static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX?, fromY?) { + static getPointOnLine( + dist: number, + P1x: number, + P1y: number, + P2x: number, + P2y: number, + fromX?: number, + fromY?: number + ) { fromX = fromX ?? P1x; fromY = fromY ?? P1y;