Skip to content

Commit 2b8ca80

Browse files
committed
Factorize input matrix type
1 parent 8ae339b commit 2b8ca80

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

package/src/dom/types/Common.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import type { ReactNode } from "react";
33
import type {
44
BlendMode,
55
Color,
6-
Matrix3,
7-
Matrix4,
6+
InputMatrix,
87
PaintStyle,
9-
SkMatrix,
108
SkPaint,
119
SkPath,
1210
SkRect,
@@ -68,7 +66,7 @@ export type CircleDef = PointCircleDef | ScalarCircleDef;
6866
export interface TransformProps {
6967
transform?: Transforms3d;
7068
origin?: Vector;
71-
matrix?: SkMatrix | Matrix4 | Matrix3 | number[];
69+
matrix?: InputMatrix;
7270
}
7371

7472
export interface PaintProps extends ChildrenProps {

package/src/skia/types/Canvas.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import type { SkColor } from "./Color";
88
import type { SkRRect } from "./RRect";
99
import type { BlendMode } from "./Paint/BlendMode";
1010
import type { SkPoint, PointMode } from "./Point";
11-
import type { SkMatrix } from "./Matrix";
11+
import type { InputMatrix } from "./Matrix";
1212
import type { SkImageFilter } from "./ImageFilter";
1313
import type { SkVertices } from "./Vertices";
1414
import type { SkTextBlob } from "./TextBlob";
1515
import type { SkPicture } from "./Picture";
16-
import type { Matrix4, Matrix3 } from "./Matrix4";
1716

1817
export enum ClipOp {
1918
Difference,
@@ -486,7 +485,7 @@ export interface SkCanvas {
486485
* Replaces current matrix with m premultiplied with the existing matrix.
487486
* @param m
488487
*/
489-
concat(m: SkMatrix | number[] | Matrix4 | Matrix3): void;
488+
concat(m: InputMatrix): void;
490489

491490
/**
492491
* Draws the given picture using the current clip, current matrix, and the provided paint.

package/src/skia/types/Matrix.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const isMatrix = (obj: unknown): obj is SkMatrix =>
77
obj !== null && (obj as SkJSIInstance<string>).__typename__ === "Matrix";
88

99
export interface SkMatrix extends SkJSIInstance<"Matrix"> {
10-
concat: (matrix: SkMatrix | Matrix4 | Matrix3 | number[]) => SkMatrix;
10+
concat: (matrix: InputMatrix) => SkMatrix;
1111
translate: (x: number, y: number) => SkMatrix;
1212
scale: (x: number, y?: number) => SkMatrix;
1313
skew: (x: number, y: number) => SkMatrix;
@@ -20,6 +20,8 @@ export interface SkMatrix extends SkJSIInstance<"Matrix"> {
2020
get: () => number[];
2121
}
2222

23+
export type InputMatrix = SkMatrix | Matrix3 | Matrix4 | number[];
24+
2325
export interface TransformProp {
2426
transform?: Transforms3d;
2527
}

package/src/skia/types/Path/Path.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import type { SkRect } from "../Rect";
22
import type { SkPoint } from "../Point";
33
import type { SkRRect } from "../RRect";
44
import type { StrokeJoin, StrokeCap } from "../Paint";
5-
import type { SkMatrix } from "../Matrix";
5+
import type { InputMatrix, SkMatrix } from "../Matrix";
66
import type { SkJSIInstance } from "../JsiInstance";
7-
import { Matrix3, Matrix4 } from "../Matrix4";
87

98
/**
109
* Options used for Path.stroke(). If an option is omitted, a sensible default will be used.
@@ -541,7 +540,7 @@ export interface SkPath extends SkJSIInstance<"Path"> {
541540
/**
542541
* Transforms the path by the specified matrix.
543542
*/
544-
transform(m3: SkMatrix | number[] | Matrix3 | Matrix4): SkPath;
543+
transform(m3: InputMatrix): SkPath;
545544

546545
/**
547546
* Interpolates between Path with point array of equal size.

package/src/skia/web/JsiSkMatrix.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { CanvasKit, Matrix3x3 } from "canvaskit-wasm";
22

3-
import { toMatrix3, type Matrix3, type Matrix4, type SkMatrix } from "../types";
3+
import { toMatrix3 } from "../types";
4+
import type { SkMatrix, InputMatrix, Matrix4 } from "../types";
45

56
import { HostObject } from "./Host";
67

7-
const isMatrixHostObject = (
8-
obj: SkMatrix | number[] | Matrix4 | Matrix3
9-
): obj is SkMatrix => !Array.isArray(obj);
8+
const isMatrixHostObject = (obj: InputMatrix): obj is SkMatrix =>
9+
!Array.isArray(obj);
1010

1111
export class JsiSkMatrix
1212
extends HostObject<Matrix3x3, "Matrix">
@@ -28,7 +28,7 @@ export class JsiSkMatrix
2828
// Do nothing - the matrix is represenetd by a Float32Array
2929
};
3030

31-
concat(matrix: SkMatrix | number[] | Matrix4 | Matrix3) {
31+
concat(matrix: InputMatrix) {
3232
this.preMultiply(
3333
// eslint-disable-next-line no-nested-ternary
3434
isMatrixHostObject(matrix)

0 commit comments

Comments
 (0)