@shopify/react-native-skia 0.1.227 → 0.1.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cpp/api/JsiSkCanvas.h +2 -1
- package/cpp/api/JsiSkMatrix.h +27 -11
- package/cpp/api/JsiSkTypeface.h +1 -0
- package/cpp/rnskia/dom/props/MatrixProp.h +14 -3
- package/lib/commonjs/dom/types/Common.d.ts +2 -2
- package/lib/commonjs/dom/types/Common.js.map +1 -1
- package/lib/commonjs/external/reanimated/interpolators.d.ts +1 -0
- package/lib/commonjs/external/reanimated/interpolators.js +16 -3
- package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
- package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +2 -1
- package/lib/commonjs/external/reanimated/moduleWrapper.js +9 -7
- package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -1
- package/lib/commonjs/skia/core/Vector.d.ts +0 -5
- package/lib/commonjs/skia/core/Vector.js +1 -17
- package/lib/commonjs/skia/core/Vector.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.d.ts +2 -13
- package/lib/commonjs/skia/types/Matrix.js +1 -16
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.d.ts +51 -0
- package/lib/commonjs/skia/types/Matrix4.js +111 -12
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
- package/lib/commonjs/skia/web/Host.d.ts +2 -3
- package/lib/commonjs/skia/web/Host.js +4 -12
- package/lib/commonjs/skia/web/Host.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkCanvas.js +12 -12
- package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkColorFilterFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkColorFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.js +2 -2
- package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImage.js +6 -6
- package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +2 -2
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js +3 -3
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMaskFilterFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkMaskFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkMatrix.js +6 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPaint.js +3 -3
- package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPath.js +4 -4
- package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPathFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkPathFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPicture.js +1 -1
- package/lib/commonjs/skia/web/JsiSkPicture.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkShaderFactory.js +5 -5
- package/lib/commonjs/skia/web/JsiSkShaderFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkVerticesFactory.js +3 -3
- package/lib/commonjs/skia/web/JsiSkVerticesFactory.js.map +1 -1
- package/lib/module/dom/types/Common.d.ts +2 -2
- package/lib/module/dom/types/Common.js.map +1 -1
- package/lib/module/external/reanimated/interpolators.d.ts +1 -0
- package/lib/module/external/reanimated/interpolators.js +14 -4
- package/lib/module/external/reanimated/interpolators.js.map +1 -1
- package/lib/module/external/reanimated/moduleWrapper.d.ts +2 -1
- package/lib/module/external/reanimated/moduleWrapper.js +7 -6
- package/lib/module/external/reanimated/moduleWrapper.js.map +1 -1
- package/lib/module/skia/core/Vector.d.ts +0 -5
- package/lib/module/skia/core/Vector.js +0 -13
- package/lib/module/skia/core/Vector.js.map +1 -1
- package/lib/module/skia/types/Matrix.d.ts +2 -13
- package/lib/module/skia/types/Matrix.js +0 -14
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/types/Matrix4.d.ts +51 -0
- package/lib/module/skia/types/Matrix4.js +90 -16
- package/lib/module/skia/types/Matrix4.js.map +1 -1
- package/lib/module/skia/web/Host.d.ts +2 -3
- package/lib/module/skia/web/Host.js +2 -7
- package/lib/module/skia/web/Host.js.map +1 -1
- package/lib/module/skia/web/JsiSkCanvas.js +13 -13
- package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/module/skia/web/JsiSkColorFilterFactory.js +2 -2
- package/lib/module/skia/web/JsiSkColorFilterFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkFont.js +3 -3
- package/lib/module/skia/web/JsiSkFont.js.map +1 -1
- package/lib/module/skia/web/JsiSkImage.js +7 -7
- package/lib/module/skia/web/JsiSkImage.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.js +3 -3
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFilterFactory.js +4 -4
- package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkMaskFilterFactory.js +2 -2
- package/lib/module/skia/web/JsiSkMaskFilterFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkMatrix.d.ts +2 -2
- package/lib/module/skia/web/JsiSkMatrix.js +6 -1
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/module/skia/web/JsiSkPaint.js +4 -4
- package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/module/skia/web/JsiSkPath.js +5 -5
- package/lib/module/skia/web/JsiSkPath.js.map +1 -1
- package/lib/module/skia/web/JsiSkPathEffectFactory.js +2 -2
- package/lib/module/skia/web/JsiSkPathEffectFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkPathFactory.js +2 -2
- package/lib/module/skia/web/JsiSkPathFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkPicture.js +2 -2
- package/lib/module/skia/web/JsiSkPicture.js.map +1 -1
- package/lib/module/skia/web/JsiSkShaderFactory.js +6 -6
- package/lib/module/skia/web/JsiSkShaderFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkVerticesFactory.js +2 -2
- package/lib/module/skia/web/JsiSkVerticesFactory.js.map +1 -1
- package/lib/typescript/src/dom/types/Common.d.ts +2 -2
- package/lib/typescript/src/external/reanimated/interpolators.d.ts +1 -0
- package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +2 -1
- package/lib/typescript/src/skia/core/Vector.d.ts +0 -5
- package/lib/typescript/src/skia/types/Matrix.d.ts +2 -13
- package/lib/typescript/src/skia/types/Matrix4.d.ts +51 -0
- package/lib/typescript/src/skia/web/Host.d.ts +2 -3
- package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +2 -2
- package/package.json +2 -1
- package/src/dom/types/Common.ts +3 -1
- package/src/external/reanimated/interpolators.ts +20 -5
- package/src/external/reanimated/moduleWrapper.ts +6 -0
- package/src/skia/core/Vector.ts +0 -7
- package/src/skia/types/Matrix.ts +2 -13
- package/src/skia/types/Matrix4.ts +96 -18
- package/src/skia/web/Host.ts +4 -3
- package/src/skia/web/JsiSkCanvas.ts +22 -15
- package/src/skia/web/JsiSkColorFilterFactory.ts +5 -2
- package/src/skia/web/JsiSkFont.ts +3 -3
- package/src/skia/web/JsiSkImage.ts +14 -11
- package/src/skia/web/JsiSkImageFactory.ts +3 -3
- package/src/skia/web/JsiSkImageFilterFactory.ts +5 -5
- package/src/skia/web/JsiSkMaskFilterFactory.ts +6 -2
- package/src/skia/web/JsiSkMatrix.ts +12 -3
- package/src/skia/web/JsiSkPaint.ts +4 -4
- package/src/skia/web/JsiSkPath.ts +8 -5
- package/src/skia/web/JsiSkPathEffectFactory.ts +2 -2
- package/src/skia/web/JsiSkPathFactory.ts +2 -2
- package/src/skia/web/JsiSkPicture.ts +4 -4
- package/src/skia/web/JsiSkShaderFactory.ts +6 -6
- package/src/skia/web/JsiSkVerticesFactory.ts +2 -2
|
@@ -16,6 +16,5 @@ export declare abstract class BaseHostObject<T, N extends string> extends Host i
|
|
|
16
16
|
export declare abstract class HostObject<T, N extends string> extends BaseHostObject<T, N> {
|
|
17
17
|
static fromValue<T>(value: SkJSIInstance<string>): T;
|
|
18
18
|
}
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const optEnum: (value: number | undefined) => EmbindEnumEntity | undefined;
|
|
19
|
+
export declare const getEnum: (e: EmbindEnum, v: number) => EmbindEnumEntity;
|
|
20
|
+
export declare const optEnum: (e: EmbindEnum, value: number | undefined) => EmbindEnumEntity | undefined;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { CanvasKit, Matrix3x3 } from "canvaskit-wasm";
|
|
2
|
-
import type
|
|
2
|
+
import { type Matrix3, type Matrix4, type SkMatrix } from "../types";
|
|
3
3
|
import { HostObject } from "./Host";
|
|
4
4
|
export declare class JsiSkMatrix extends HostObject<Matrix3x3, "Matrix"> implements SkMatrix {
|
|
5
5
|
constructor(CanvasKit: CanvasKit, ref: Matrix3x3);
|
|
6
6
|
private preMultiply;
|
|
7
7
|
private postMultiply;
|
|
8
8
|
dispose: () => void;
|
|
9
|
-
concat(matrix: SkMatrix | number[]): this;
|
|
9
|
+
concat(matrix: SkMatrix | number[] | Matrix4 | Matrix3): this;
|
|
10
10
|
translate(x: number, y: number): this;
|
|
11
11
|
postTranslate(x: number, y: number): this;
|
|
12
12
|
scale(x: number, y?: number): this;
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
|
8
8
|
},
|
|
9
9
|
"title": "React Native Skia",
|
|
10
|
-
"version": "0.1.
|
|
10
|
+
"version": "0.1.228",
|
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
|
12
12
|
"main": "lib/module/index.js",
|
|
13
13
|
"files": [
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"eslint-config-react-native-wcandillon": "3.10.2",
|
|
95
95
|
"eslint-plugin-reanimated": "2.0.0",
|
|
96
96
|
"jest": "29.6.4",
|
|
97
|
+
"jest-diff": "^29.7.0",
|
|
97
98
|
"merge-dirs": "^0.2.1",
|
|
98
99
|
"pixelmatch": "^5.3.0",
|
|
99
100
|
"pngjs": "^6.0.0",
|
package/src/dom/types/Common.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { ReactNode } from "react";
|
|
|
3
3
|
import type {
|
|
4
4
|
BlendMode,
|
|
5
5
|
Color,
|
|
6
|
+
Matrix3,
|
|
7
|
+
Matrix4,
|
|
6
8
|
PaintStyle,
|
|
7
9
|
SkMatrix,
|
|
8
10
|
SkPaint,
|
|
@@ -66,7 +68,7 @@ export type CircleDef = PointCircleDef | ScalarCircleDef;
|
|
|
66
68
|
export interface TransformProps {
|
|
67
69
|
transform?: Transforms3d;
|
|
68
70
|
origin?: Vector;
|
|
69
|
-
matrix?: SkMatrix | number[];
|
|
71
|
+
matrix?: SkMatrix | Matrix4 | Matrix3 | number[];
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export interface PaintProps extends ChildrenProps {
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
FrameInfo,
|
|
4
4
|
SharedValue,
|
|
5
5
|
} from "react-native-reanimated";
|
|
6
|
-
import {
|
|
6
|
+
import { useCallback, useMemo } from "react";
|
|
7
7
|
|
|
8
8
|
import type { SkPath, SkPoint } from "../../skia/types";
|
|
9
9
|
import { interpolatePaths, interpolateVector } from "../../animation";
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
useAnimatedReaction,
|
|
14
14
|
useFrameCallback,
|
|
15
15
|
useSharedValue,
|
|
16
|
+
useDerivedValue,
|
|
16
17
|
} from "./moduleWrapper";
|
|
17
18
|
|
|
18
19
|
export const notifyChange = (value: SharedValue<unknown>) => {
|
|
@@ -23,12 +24,26 @@ export const notifyChange = (value: SharedValue<unknown>) => {
|
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
|
|
27
|
+
export const usePathValue = (cb: (path: SkPath) => void) => {
|
|
28
|
+
const pathInit = useMemo(() => Skia.Path.Make(), []);
|
|
29
|
+
const path = useSharedValue(pathInit);
|
|
30
|
+
useDerivedValue(() => {
|
|
31
|
+
path.value.reset();
|
|
32
|
+
cb(path.value);
|
|
33
|
+
notifyChange(path);
|
|
34
|
+
});
|
|
35
|
+
return path;
|
|
36
|
+
};
|
|
37
|
+
|
|
26
38
|
export const useClock = () => {
|
|
27
39
|
const clock = useSharedValue(0);
|
|
28
|
-
const callback =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
const callback = useCallback(
|
|
41
|
+
(info: FrameInfo) => {
|
|
42
|
+
"worklet";
|
|
43
|
+
clock.value = info.timeSinceFirstFrame;
|
|
44
|
+
},
|
|
45
|
+
[clock]
|
|
46
|
+
);
|
|
32
47
|
useFrameCallback(callback);
|
|
33
48
|
return clock;
|
|
34
49
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import type { DependencyList } from "react";
|
|
3
3
|
import type {
|
|
4
|
+
DerivedValue,
|
|
4
5
|
FrameCallback,
|
|
5
6
|
FrameInfo,
|
|
6
7
|
SharedValue,
|
|
@@ -42,6 +43,11 @@ export const useSharedValue: <T>(
|
|
|
42
43
|
oneWayReadsOnly?: boolean
|
|
43
44
|
) => SharedValue<T> = Reanimated2?.useSharedValue || throwOnMissingReanimated;
|
|
44
45
|
|
|
46
|
+
export const useDerivedValue: <T>(
|
|
47
|
+
processor: () => T,
|
|
48
|
+
dependencies?: DependencyList
|
|
49
|
+
) => DerivedValue<T> = Reanimated2?.useDerivedValue || throwOnMissingReanimated;
|
|
50
|
+
|
|
45
51
|
export const useFrameCallback: (
|
|
46
52
|
callback: (frameInfo: FrameInfo) => void,
|
|
47
53
|
autostart?: boolean
|
package/src/skia/core/Vector.ts
CHANGED
|
@@ -22,10 +22,3 @@ export const dist = (a: Vector, b: Vector) => {
|
|
|
22
22
|
"worklet";
|
|
23
23
|
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
24
24
|
};
|
|
25
|
-
export const translate = ({
|
|
26
|
-
x,
|
|
27
|
-
y,
|
|
28
|
-
}: Vector): [{ translateX: number }, { translateY: number }] => {
|
|
29
|
-
"worklet";
|
|
30
|
-
return [{ translateX: x }, { translateY: y }];
|
|
31
|
-
};
|
package/src/skia/types/Matrix.ts
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
import type { SkJSIInstance } from "./JsiInstance";
|
|
2
2
|
import type { SkCanvas } from "./Canvas";
|
|
3
|
-
import type { Transforms3d } from "./Matrix4";
|
|
3
|
+
import type { Matrix3, Matrix4, Transforms3d } from "./Matrix4";
|
|
4
4
|
import { processTransform3d } from "./Matrix4";
|
|
5
|
-
export enum MatrixIndex {
|
|
6
|
-
ScaleX = 0,
|
|
7
|
-
SkewX = 1,
|
|
8
|
-
TransX = 2,
|
|
9
|
-
SkewY = 3,
|
|
10
|
-
ScaleY = 4,
|
|
11
|
-
TransY = 5,
|
|
12
|
-
Persp0 = 6,
|
|
13
|
-
Persp1 = 7,
|
|
14
|
-
Persp2 = 8,
|
|
15
|
-
}
|
|
16
5
|
|
|
17
6
|
export const isMatrix = (obj: unknown): obj is SkMatrix =>
|
|
18
7
|
obj !== null && (obj as SkJSIInstance<string>).__typename__ === "Matrix";
|
|
19
8
|
|
|
20
9
|
export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
|
21
|
-
concat: (matrix: SkMatrix | number[]) => SkMatrix;
|
|
10
|
+
concat: (matrix: SkMatrix | Matrix4 | Matrix3 | number[]) => SkMatrix;
|
|
22
11
|
translate: (x: number, y: number) => SkMatrix;
|
|
23
12
|
scale: (x: number, y?: number) => SkMatrix;
|
|
24
13
|
skew: (x: number, y: number) => SkMatrix;
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
type Point = { x: number; y: number };
|
|
1
2
|
type Vec2 = readonly [number, number];
|
|
2
3
|
type Vec3 = readonly [number, number, number];
|
|
3
4
|
type Vec4 = readonly [number, number, number, number];
|
|
4
5
|
|
|
6
|
+
export type Matrix3 = readonly [
|
|
7
|
+
number,
|
|
8
|
+
number,
|
|
9
|
+
number,
|
|
10
|
+
number,
|
|
11
|
+
number,
|
|
12
|
+
number,
|
|
13
|
+
number,
|
|
14
|
+
number,
|
|
15
|
+
number
|
|
16
|
+
];
|
|
17
|
+
|
|
5
18
|
export type Matrix4 = readonly [
|
|
6
19
|
number,
|
|
7
20
|
number,
|
|
@@ -78,17 +91,18 @@ export const Matrix4 = (): Matrix4 => {
|
|
|
78
91
|
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
79
92
|
};
|
|
80
93
|
|
|
81
|
-
|
|
94
|
+
/**
|
|
95
|
+
* @worklet
|
|
96
|
+
*/
|
|
97
|
+
export const translate = (x: number, y: number, z: number = 0): Matrix4 => {
|
|
82
98
|
"worklet";
|
|
83
99
|
return [1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1];
|
|
84
100
|
};
|
|
85
101
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const perspective = (p: number): Matrix4 => {
|
|
102
|
+
/**
|
|
103
|
+
* @worklet
|
|
104
|
+
*/
|
|
105
|
+
export const perspective = (p: number): Matrix4 => {
|
|
92
106
|
"worklet";
|
|
93
107
|
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -1 / p, 1];
|
|
94
108
|
};
|
|
@@ -136,15 +150,6 @@ const rotatedUnitSinCos = (
|
|
|
136
150
|
];
|
|
137
151
|
};
|
|
138
152
|
|
|
139
|
-
const rotate = (axis: Vec3, value: number) => {
|
|
140
|
-
"worklet";
|
|
141
|
-
return rotatedUnitSinCos(
|
|
142
|
-
normalizeVec(axis),
|
|
143
|
-
Math.sin(value),
|
|
144
|
-
Math.cos(value)
|
|
145
|
-
);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
153
|
const matrixVecMul4 = (m: Matrix4, v: Vec4) => {
|
|
149
154
|
"worklet";
|
|
150
155
|
const [vx, vy, vz, vw] = v;
|
|
@@ -165,7 +170,10 @@ export const mapPoint3d = (m: Matrix4, v: Vec3) => {
|
|
|
165
170
|
return [r[0] / r[3], r[1] / r[3], r[2] / r[3]] as const;
|
|
166
171
|
};
|
|
167
172
|
|
|
168
|
-
|
|
173
|
+
/**
|
|
174
|
+
* @worklet
|
|
175
|
+
*/
|
|
176
|
+
export const multiply4 = (a: Matrix4, b: Matrix4): Matrix4 => {
|
|
169
177
|
"worklet";
|
|
170
178
|
const result = new Array(16).fill(0);
|
|
171
179
|
for (let i = 0; i < 4; i++) {
|
|
@@ -190,11 +198,81 @@ const skewX = (angle: number): Matrix4 => {
|
|
|
190
198
|
return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
191
199
|
};
|
|
192
200
|
|
|
193
|
-
|
|
201
|
+
/**
|
|
202
|
+
* @worklet
|
|
203
|
+
*/
|
|
204
|
+
export const toMatrix3 = (m: Matrix4) => {
|
|
194
205
|
"worklet";
|
|
195
206
|
return [m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]];
|
|
196
207
|
};
|
|
197
208
|
|
|
209
|
+
const rotate = (axis: Vec3, value: number) => {
|
|
210
|
+
"worklet";
|
|
211
|
+
return rotatedUnitSinCos(
|
|
212
|
+
normalizeVec(axis),
|
|
213
|
+
Math.sin(value),
|
|
214
|
+
Math.cos(value)
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @worklet
|
|
220
|
+
*/
|
|
221
|
+
export const pivot = (m: Matrix4, p: Point) => {
|
|
222
|
+
"worklet";
|
|
223
|
+
return multiply4(translate(p.x, p.y), multiply4(m, translate(-p.x, -p.y)));
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @worklet
|
|
228
|
+
*/
|
|
229
|
+
export const scale = (
|
|
230
|
+
sx: number,
|
|
231
|
+
sy: number,
|
|
232
|
+
sz: number = 1,
|
|
233
|
+
p?: Point
|
|
234
|
+
): Matrix4 => {
|
|
235
|
+
"worklet";
|
|
236
|
+
const m4: Matrix4 = [sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1];
|
|
237
|
+
if (p) {
|
|
238
|
+
return pivot(m4, p);
|
|
239
|
+
}
|
|
240
|
+
return m4;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const rotateAxis = (axis: Vec3, angle: number, p?: Point) => {
|
|
244
|
+
"worklet";
|
|
245
|
+
const result = rotate(axis, angle);
|
|
246
|
+
if (p) {
|
|
247
|
+
return pivot(result, p);
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @worklet
|
|
254
|
+
*/
|
|
255
|
+
export const rotateZ = (value: number, p?: Point) => {
|
|
256
|
+
"worklet";
|
|
257
|
+
return rotateAxis([0, 0, 1], value, p);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @worklet
|
|
262
|
+
*/
|
|
263
|
+
export const rotateX = (value: number, p?: Point) => {
|
|
264
|
+
"worklet";
|
|
265
|
+
return rotateAxis([1, 0, 0], value, p);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @worklet
|
|
270
|
+
*/
|
|
271
|
+
export const rotateY = (value: number, p?: Point) => {
|
|
272
|
+
"worklet";
|
|
273
|
+
return rotateAxis([0, 1, 0], value, p);
|
|
274
|
+
};
|
|
275
|
+
|
|
198
276
|
/**
|
|
199
277
|
* @worklet
|
|
200
278
|
*/
|
package/src/skia/web/Host.ts
CHANGED
|
@@ -41,10 +41,11 @@ export abstract class HostObject<T, N extends string> extends BaseHostObject<
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export const
|
|
44
|
+
export const getEnum = (e: EmbindEnum, v: number): EmbindEnumEntity =>
|
|
45
45
|
Object.values(e).find(({ value }) => value === v);
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
export const optEnum = (
|
|
48
|
+
e: EmbindEnum,
|
|
48
49
|
value: number | undefined
|
|
49
50
|
): EmbindEnumEntity | undefined =>
|
|
50
|
-
value === undefined ? undefined :
|
|
51
|
+
value === undefined ? undefined : getEnum(e, value);
|
|
@@ -25,7 +25,7 @@ import type {
|
|
|
25
25
|
SkVertices,
|
|
26
26
|
} from "../types";
|
|
27
27
|
|
|
28
|
-
import {
|
|
28
|
+
import { getEnum, HostObject } from "./Host";
|
|
29
29
|
import { JsiSkPaint } from "./JsiSkPaint";
|
|
30
30
|
import { JsiSkRect } from "./JsiSkRect";
|
|
31
31
|
import { JsiSkRRect } from "./JsiSkRRect";
|
|
@@ -113,8 +113,8 @@ export class JsiSkCanvas
|
|
|
113
113
|
JsiSkImage.fromValue(img),
|
|
114
114
|
left,
|
|
115
115
|
top,
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
getEnum(this.CanvasKit.FilterMode, fm),
|
|
117
|
+
getEnum(this.CanvasKit.MipmapMode, mm),
|
|
118
118
|
paint ? JsiSkPaint.fromValue(paint) : paint
|
|
119
119
|
);
|
|
120
120
|
}
|
|
@@ -130,7 +130,7 @@ export class JsiSkCanvas
|
|
|
130
130
|
JsiSkImage.fromValue(img),
|
|
131
131
|
Array.from(JsiSkRect.fromValue(this.CanvasKit, center)),
|
|
132
132
|
JsiSkRect.fromValue(this.CanvasKit, dest),
|
|
133
|
-
|
|
133
|
+
getEnum(this.CanvasKit.FilterMode, filter),
|
|
134
134
|
paint ? JsiSkPaint.fromValue(paint) : paint
|
|
135
135
|
);
|
|
136
136
|
}
|
|
@@ -165,8 +165,8 @@ export class JsiSkCanvas
|
|
|
165
165
|
JsiSkImage.fromValue(img),
|
|
166
166
|
JsiSkRect.fromValue(this.CanvasKit, src),
|
|
167
167
|
JsiSkRect.fromValue(this.CanvasKit, dest),
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
getEnum(this.CanvasKit.FilterMode, fm),
|
|
169
|
+
getEnum(this.CanvasKit.MipmapMode, mm),
|
|
170
170
|
paint ? JsiSkPaint.fromValue(paint) : paint
|
|
171
171
|
);
|
|
172
172
|
}
|
|
@@ -186,7 +186,7 @@ export class JsiSkCanvas
|
|
|
186
186
|
drawVertices(verts: SkVertices, mode: BlendMode, paint: SkPaint) {
|
|
187
187
|
this.ref.drawVertices(
|
|
188
188
|
JsiSkVertices.fromValue(verts),
|
|
189
|
-
|
|
189
|
+
getEnum(this.CanvasKit.BlendMode, mode),
|
|
190
190
|
JsiSkPaint.fromValue(paint)
|
|
191
191
|
);
|
|
192
192
|
}
|
|
@@ -202,7 +202,7 @@ export class JsiSkCanvas
|
|
|
202
202
|
cubics.map(({ x, y }) => [x, y]).flat(),
|
|
203
203
|
colors,
|
|
204
204
|
texs ? texs.flatMap((p) => Array.from(JsiSkPoint.fromValue(p))) : texs,
|
|
205
|
-
mode ?
|
|
205
|
+
mode ? getEnum(this.CanvasKit.BlendMode, mode) : null,
|
|
206
206
|
paint ? JsiSkPaint.fromValue(paint) : undefined
|
|
207
207
|
);
|
|
208
208
|
}
|
|
@@ -213,7 +213,7 @@ export class JsiSkCanvas
|
|
|
213
213
|
|
|
214
214
|
drawPoints(mode: PointMode, points: SkPoint[], paint: SkPaint) {
|
|
215
215
|
this.ref.drawPoints(
|
|
216
|
-
|
|
216
|
+
getEnum(this.CanvasKit.PointMode, mode),
|
|
217
217
|
points.map(({ x, y }) => [x, y]).flat(),
|
|
218
218
|
JsiSkPaint.fromValue(paint)
|
|
219
219
|
);
|
|
@@ -341,7 +341,10 @@ export class JsiSkCanvas
|
|
|
341
341
|
}
|
|
342
342
|
|
|
343
343
|
drawColor(color: SkColor, blendMode?: BlendMode) {
|
|
344
|
-
this.ref.drawColor(
|
|
344
|
+
this.ref.drawColor(
|
|
345
|
+
color,
|
|
346
|
+
blendMode ? getEnum(this.CanvasKit.BlendMode, blendMode) : undefined
|
|
347
|
+
);
|
|
345
348
|
}
|
|
346
349
|
|
|
347
350
|
clear(color: SkColor) {
|
|
@@ -349,13 +352,17 @@ export class JsiSkCanvas
|
|
|
349
352
|
}
|
|
350
353
|
|
|
351
354
|
clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean) {
|
|
352
|
-
this.ref.clipPath(
|
|
355
|
+
this.ref.clipPath(
|
|
356
|
+
JsiSkPath.fromValue(path),
|
|
357
|
+
getEnum(this.CanvasKit.PathOp, op),
|
|
358
|
+
doAntiAlias
|
|
359
|
+
);
|
|
353
360
|
}
|
|
354
361
|
|
|
355
362
|
clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean) {
|
|
356
363
|
this.ref.clipRect(
|
|
357
364
|
JsiSkRect.fromValue(this.CanvasKit, rect),
|
|
358
|
-
|
|
365
|
+
getEnum(this.CanvasKit.PathOp, op),
|
|
359
366
|
doAntiAlias
|
|
360
367
|
);
|
|
361
368
|
}
|
|
@@ -363,7 +370,7 @@ export class JsiSkCanvas
|
|
|
363
370
|
clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean) {
|
|
364
371
|
this.ref.clipRRect(
|
|
365
372
|
JsiSkRRect.fromValue(this.CanvasKit, rrect),
|
|
366
|
-
|
|
373
|
+
getEnum(this.CanvasKit.PathOp, op),
|
|
367
374
|
doAntiAlias
|
|
368
375
|
);
|
|
369
376
|
}
|
|
@@ -381,8 +388,8 @@ export class JsiSkCanvas
|
|
|
381
388
|
width: imageInfo.width,
|
|
382
389
|
height: imageInfo.height,
|
|
383
390
|
colorSpace: this.CanvasKit.ColorSpace.SRGB,
|
|
384
|
-
alphaType:
|
|
385
|
-
colorType:
|
|
391
|
+
alphaType: getEnum(this.CanvasKit.AlphaType, imageInfo.alphaType),
|
|
392
|
+
colorType: getEnum(this.CanvasKit.ColorType, imageInfo.colorType),
|
|
386
393
|
};
|
|
387
394
|
return this.ref.readPixels(srcX, srcY, pxInfo);
|
|
388
395
|
}
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
BlendMode,
|
|
9
9
|
} from "../types";
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { getEnum, Host } from "./Host";
|
|
12
12
|
import { JsiSkColorFilter } from "./JsiSkColorFilter";
|
|
13
13
|
|
|
14
14
|
export class JsiSkColorFilterFactory
|
|
@@ -29,7 +29,10 @@ export class JsiSkColorFilterFactory
|
|
|
29
29
|
MakeBlend(color: SkColor, mode: BlendMode) {
|
|
30
30
|
return new JsiSkColorFilter(
|
|
31
31
|
this.CanvasKit,
|
|
32
|
-
this.CanvasKit.ColorFilter.MakeBlend(
|
|
32
|
+
this.CanvasKit.ColorFilter.MakeBlend(
|
|
33
|
+
color,
|
|
34
|
+
getEnum(this.CanvasKit.BlendMode, mode)
|
|
35
|
+
)
|
|
33
36
|
);
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
SkTypeface,
|
|
11
11
|
} from "../types";
|
|
12
12
|
|
|
13
|
-
import { HostObject, NotImplementedOnRNWeb,
|
|
13
|
+
import { HostObject, NotImplementedOnRNWeb, getEnum } from "./Host";
|
|
14
14
|
import { JsiSkPaint } from "./JsiSkPaint";
|
|
15
15
|
import { JsiSkPoint } from "./JsiSkPoint";
|
|
16
16
|
import { JsiSkRect } from "./JsiSkRect";
|
|
@@ -100,7 +100,7 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
setEdging(edging: FontEdging) {
|
|
103
|
-
this.ref.setEdging(
|
|
103
|
+
this.ref.setEdging(getEnum(this.CanvasKit.FontEdging, edging));
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
setEmbeddedBitmaps(embeddedBitmaps: boolean) {
|
|
@@ -108,7 +108,7 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
setHinting(hinting: FontHinting) {
|
|
111
|
-
this.ref.setHinting(
|
|
111
|
+
this.ref.setHinting(getEnum(this.CanvasKit.FontHinting, hinting));
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
setLinearMetrics(linearMetrics: boolean) {
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
ImageInfo,
|
|
16
16
|
} from "../types";
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { getEnum, HostObject } from "./Host";
|
|
19
19
|
import { JsiSkMatrix } from "./JsiSkMatrix";
|
|
20
20
|
import { JsiSkShader } from "./JsiSkShader";
|
|
21
21
|
|
|
@@ -77,10 +77,10 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
|
77
77
|
return new JsiSkShader(
|
|
78
78
|
this.CanvasKit,
|
|
79
79
|
this.ref.makeShaderOptions(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
getEnum(this.CanvasKit.TileMode, tx),
|
|
81
|
+
getEnum(this.CanvasKit.TileMode, ty),
|
|
82
|
+
getEnum(this.CanvasKit.FilterMode, fm),
|
|
83
|
+
getEnum(this.CanvasKit.MipmapMode, mm),
|
|
84
84
|
localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined
|
|
85
85
|
)
|
|
86
86
|
);
|
|
@@ -96,8 +96,8 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
|
96
96
|
return new JsiSkShader(
|
|
97
97
|
this.CanvasKit,
|
|
98
98
|
this.ref.makeShaderCubic(
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
getEnum(this.CanvasKit.TileMode, tx),
|
|
100
|
+
getEnum(this.CanvasKit.TileMode, ty),
|
|
101
101
|
B,
|
|
102
102
|
C,
|
|
103
103
|
localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined
|
|
@@ -108,9 +108,12 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
|
108
108
|
encodeToBytes(fmt?: ImageFormat, quality?: number) {
|
|
109
109
|
let result: Uint8Array | null;
|
|
110
110
|
if (fmt && quality) {
|
|
111
|
-
result = this.ref.encodeToBytes(
|
|
111
|
+
result = this.ref.encodeToBytes(
|
|
112
|
+
getEnum(this.CanvasKit.ImageFormat, fmt),
|
|
113
|
+
quality
|
|
114
|
+
);
|
|
112
115
|
} else if (fmt) {
|
|
113
|
-
result = this.ref.encodeToBytes(
|
|
116
|
+
result = this.ref.encodeToBytes(getEnum(this.CanvasKit.ImageFormat, fmt));
|
|
114
117
|
} else {
|
|
115
118
|
result = this.ref.encodeToBytes();
|
|
116
119
|
}
|
|
@@ -131,11 +134,11 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
|
131
134
|
colorSpace: this.CanvasKit.ColorSpace.SRGB,
|
|
132
135
|
width: imageInfo?.width ?? info.width,
|
|
133
136
|
height: imageInfo?.height ?? info.height,
|
|
134
|
-
alphaType:
|
|
137
|
+
alphaType: getEnum(
|
|
135
138
|
this.CanvasKit.AlphaType,
|
|
136
139
|
(imageInfo ?? info).alphaType
|
|
137
140
|
),
|
|
138
|
-
colorType:
|
|
141
|
+
colorType: getEnum(
|
|
139
142
|
this.CanvasKit.ColorType,
|
|
140
143
|
(imageInfo ?? info).colorType
|
|
141
144
|
),
|
|
@@ -3,7 +3,7 @@ import type { CanvasKit } from "canvaskit-wasm";
|
|
|
3
3
|
import type { SkData, ImageInfo, SkImage } from "../types";
|
|
4
4
|
import type { ImageFactory } from "../types/Image/ImageFactory";
|
|
5
5
|
|
|
6
|
-
import { Host,
|
|
6
|
+
import { Host, getEnum } from "./Host";
|
|
7
7
|
import { JsiSkImage } from "./JsiSkImage";
|
|
8
8
|
import { JsiSkData } from "./JsiSkData";
|
|
9
9
|
|
|
@@ -33,9 +33,9 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
|
33
33
|
// see toSkImageInfo() from canvaskit
|
|
34
34
|
const image = this.CanvasKit.MakeImage(
|
|
35
35
|
{
|
|
36
|
-
alphaType:
|
|
36
|
+
alphaType: getEnum(this.CanvasKit.AlphaType, info.alphaType),
|
|
37
37
|
colorSpace: this.CanvasKit.ColorSpace.SRGB,
|
|
38
|
-
colorType:
|
|
38
|
+
colorType: getEnum(this.CanvasKit.ColorType, info.colorType),
|
|
39
39
|
height: info.height,
|
|
40
40
|
width: info.width,
|
|
41
41
|
},
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
TileMode,
|
|
14
14
|
} from "../types";
|
|
15
15
|
|
|
16
|
-
import { Host, NotImplementedOnRNWeb,
|
|
16
|
+
import { Host, NotImplementedOnRNWeb, getEnum } from "./Host";
|
|
17
17
|
import { JsiSkImageFilter } from "./JsiSkImageFilter";
|
|
18
18
|
import { JsiSkColorFilter } from "./JsiSkColorFilter";
|
|
19
19
|
|
|
@@ -42,8 +42,8 @@ export class JsiSkImageFilterFactory
|
|
|
42
42
|
const inputFilter =
|
|
43
43
|
input === null ? null : JsiSkImageFilter.fromValue<ImageFilter>(input);
|
|
44
44
|
const filter = this.CanvasKit.ImageFilter.MakeDisplacementMap(
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
getEnum(this.CanvasKit.ColorChannel, channelX),
|
|
46
|
+
getEnum(this.CanvasKit.ColorChannel, channelY),
|
|
47
47
|
scale,
|
|
48
48
|
JsiSkImageFilter.fromValue(in1),
|
|
49
49
|
inputFilter
|
|
@@ -69,7 +69,7 @@ export class JsiSkImageFilterFactory
|
|
|
69
69
|
this.CanvasKit.ImageFilter.MakeBlur(
|
|
70
70
|
sigmaX,
|
|
71
71
|
sigmaY,
|
|
72
|
-
|
|
72
|
+
getEnum(this.CanvasKit.TileMode, mode),
|
|
73
73
|
input === null ? null : JsiSkImageFilter.fromValue(input)
|
|
74
74
|
)
|
|
75
75
|
);
|
|
@@ -199,7 +199,7 @@ export class JsiSkImageFilterFactory
|
|
|
199
199
|
);
|
|
200
200
|
}
|
|
201
201
|
const filter = this.CanvasKit.ImageFilter.MakeBlend(
|
|
202
|
-
|
|
202
|
+
getEnum(this.CanvasKit.BlendMode, mode),
|
|
203
203
|
JsiSkImageFilter.fromValue(background),
|
|
204
204
|
inputFilter
|
|
205
205
|
);
|
|
@@ -3,7 +3,7 @@ import type { CanvasKit } from "canvaskit-wasm";
|
|
|
3
3
|
import type { BlurStyle } from "../types";
|
|
4
4
|
import type { MaskFilterFactory } from "../types/MaskFilter";
|
|
5
5
|
|
|
6
|
-
import { Host,
|
|
6
|
+
import { Host, getEnum } from "./Host";
|
|
7
7
|
import { JsiSkMaskFilter } from "./JsiSkMaskFilter";
|
|
8
8
|
|
|
9
9
|
export class JsiSkMaskFilterFactory extends Host implements MaskFilterFactory {
|
|
@@ -14,7 +14,11 @@ export class JsiSkMaskFilterFactory extends Host implements MaskFilterFactory {
|
|
|
14
14
|
MakeBlur(style: BlurStyle, sigma: number, respectCTM: boolean) {
|
|
15
15
|
return new JsiSkMaskFilter(
|
|
16
16
|
this.CanvasKit,
|
|
17
|
-
this.CanvasKit.MaskFilter.MakeBlur(
|
|
17
|
+
this.CanvasKit.MaskFilter.MakeBlur(
|
|
18
|
+
getEnum(this.CanvasKit.BlurStyle, style),
|
|
19
|
+
sigma,
|
|
20
|
+
respectCTM
|
|
21
|
+
)
|
|
18
22
|
);
|
|
19
23
|
}
|
|
20
24
|
}
|