@shopify/react-native-skia 0.1.228 → 0.1.229
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/dom/types/Common.d.ts +2 -2
- package/lib/commonjs/dom/types/Common.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +7 -13
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/types/Canvas.d.ts +2 -2
- package/lib/commonjs/skia/types/Canvas.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.d.ts +2 -1
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.d.ts +9 -1
- package/lib/commonjs/skia/types/Matrix4.js +49 -3
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
- package/lib/commonjs/skia/types/Path/Path.d.ts +2 -2
- package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkMatrix.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/renderer/Canvas.js +7 -12
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/types/Canvas.d.ts +2 -2
- package/lib/module/skia/types/Canvas.js.map +1 -1
- package/lib/module/skia/types/Matrix.d.ts +2 -1
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/types/Matrix4.d.ts +9 -1
- package/lib/module/skia/types/Matrix4.js +42 -2
- package/lib/module/skia/types/Matrix4.js.map +1 -1
- package/lib/module/skia/types/Path/Path.d.ts +2 -2
- package/lib/module/skia/types/Path/Path.js.map +1 -1
- package/lib/module/skia/web/JsiSkMatrix.d.ts +2 -2
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/typescript/src/dom/types/Common.d.ts +2 -2
- package/lib/typescript/src/skia/types/Canvas.d.ts +2 -2
- package/lib/typescript/src/skia/types/Matrix.d.ts +2 -1
- package/lib/typescript/src/skia/types/Matrix4.d.ts +9 -1
- package/lib/typescript/src/skia/types/Path/Path.d.ts +2 -2
- package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +2 -2
- package/package.json +1 -1
- package/src/dom/types/Common.ts +2 -4
- package/src/renderer/Canvas.tsx +6 -13
- package/src/skia/types/Canvas.ts +2 -2
- package/src/skia/types/Matrix.ts +3 -1
- package/src/skia/types/Matrix4.ts +94 -63
- package/src/skia/types/Path/Path.ts +2 -2
- package/src/skia/web/JsiSkMatrix.ts +5 -5
@@ -3,7 +3,7 @@ import type { SkCanvas } from "./Canvas";
|
|
3
3
|
import type { Matrix3, Matrix4, Transforms3d } from "./Matrix4";
|
4
4
|
export declare const isMatrix: (obj: unknown) => obj is SkMatrix;
|
5
5
|
export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
6
|
-
concat: (matrix:
|
6
|
+
concat: (matrix: InputMatrix) => SkMatrix;
|
7
7
|
translate: (x: number, y: number) => SkMatrix;
|
8
8
|
scale: (x: number, y?: number) => SkMatrix;
|
9
9
|
skew: (x: number, y: number) => SkMatrix;
|
@@ -15,6 +15,7 @@ export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
|
15
15
|
identity: () => SkMatrix;
|
16
16
|
get: () => number[];
|
17
17
|
}
|
18
|
+
export type InputMatrix = SkMatrix | Matrix3 | Matrix4 | number[];
|
18
19
|
export interface TransformProp {
|
19
20
|
transform?: Transforms3d;
|
20
21
|
}
|
@@ -86,5 +86,13 @@ export declare const rotateY: (value: number, p?: Point) => Matrix4;
|
|
86
86
|
/**
|
87
87
|
* @worklet
|
88
88
|
*/
|
89
|
-
export declare const processTransform3d: (transforms: Transforms3d) =>
|
89
|
+
export declare const processTransform3d: (transforms: Transforms3d) => Matrix4;
|
90
|
+
/**
|
91
|
+
* @worklet
|
92
|
+
*/
|
93
|
+
export declare const convertToColumnMajor: (rowMajorMatrix: Matrix4) => number[];
|
94
|
+
/**
|
95
|
+
* @worklet
|
96
|
+
*/
|
97
|
+
export declare const convertToAffineMatrix: (m4: number[]) => number[];
|
90
98
|
export {};
|
@@ -2,7 +2,7 @@ import type { SkRect } from "../Rect";
|
|
2
2
|
import type { SkPoint } from "../Point";
|
3
3
|
import type { SkRRect } from "../RRect";
|
4
4
|
import type { StrokeJoin, StrokeCap } from "../Paint";
|
5
|
-
import type { SkMatrix } from "../Matrix";
|
5
|
+
import type { InputMatrix, SkMatrix } from "../Matrix";
|
6
6
|
import type { SkJSIInstance } from "../JsiInstance";
|
7
7
|
/**
|
8
8
|
* Options used for Path.stroke(). If an option is omitted, a sensible default will be used.
|
@@ -440,7 +440,7 @@ export interface SkPath extends SkJSIInstance<"Path"> {
|
|
440
440
|
/**
|
441
441
|
* Transforms the path by the specified matrix.
|
442
442
|
*/
|
443
|
-
transform(m3:
|
443
|
+
transform(m3: InputMatrix): SkPath;
|
444
444
|
/**
|
445
445
|
* Interpolates between Path with point array of equal size.
|
446
446
|
* Copy verb array and weights to result, and set result path to a weighted
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import type { CanvasKit, Matrix3x3 } from "canvaskit-wasm";
|
2
|
-
import
|
2
|
+
import type { SkMatrix, InputMatrix } 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:
|
9
|
+
concat(matrix: InputMatrix): 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
package/src/dom/types/Common.ts
CHANGED
@@ -3,10 +3,8 @@ import type { ReactNode } from "react";
|
|
3
3
|
import type {
|
4
4
|
BlendMode,
|
5
5
|
Color,
|
6
|
-
|
7
|
-
Matrix4,
|
6
|
+
InputMatrix,
|
8
7
|
PaintStyle,
|
9
|
-
SkMatrix,
|
10
8
|
SkPaint,
|
11
9
|
SkPath,
|
12
10
|
SkRect,
|
@@ -68,7 +66,7 @@ export type CircleDef = PointCircleDef | ScalarCircleDef;
|
|
68
66
|
export interface TransformProps {
|
69
67
|
transform?: Transforms3d;
|
70
68
|
origin?: Vector;
|
71
|
-
matrix?:
|
69
|
+
matrix?: InputMatrix;
|
72
70
|
}
|
73
71
|
|
74
72
|
export interface PaintProps extends ChildrenProps {
|
package/src/renderer/Canvas.tsx
CHANGED
@@ -14,11 +14,11 @@ import type {
|
|
14
14
|
} from "react";
|
15
15
|
import type { LayoutChangeEvent } from "react-native";
|
16
16
|
|
17
|
-
import { SkiaDomView
|
17
|
+
import { SkiaDomView } from "../views";
|
18
|
+
import { SkiaDomView as SkiaDomViewWeb } from "../views/SkiaDomView.web";
|
18
19
|
import { Skia } from "../skia/Skia";
|
19
20
|
import type { TouchHandler, SkiaBaseViewProps } from "../views";
|
20
21
|
import type { SkiaValue } from "../values/types";
|
21
|
-
import { JsiDrawingContext } from "../dom/types";
|
22
22
|
|
23
23
|
import { SkiaRoot } from "./Reconciler";
|
24
24
|
import { NATIVE_DOM } from "./HostComponents";
|
@@ -116,23 +116,16 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
|
116
116
|
/>
|
117
117
|
);
|
118
118
|
} else {
|
119
|
-
// This is for debugging
|
120
|
-
const recorder = Skia.PictureRecorder();
|
121
|
-
const canvas = recorder.beginRecording(
|
122
|
-
Skia.XYWHRect(0, 0, 2_000_000, 2_000_000)
|
123
|
-
);
|
124
|
-
const ctx = new JsiDrawingContext(Skia, canvas);
|
125
|
-
root.dom.render(ctx);
|
126
|
-
const picture = recorder.finishRecordingAsPicture();
|
127
119
|
return (
|
128
|
-
<
|
120
|
+
<SkiaDomViewWeb
|
129
121
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
130
122
|
ref={ref as any}
|
131
123
|
style={style}
|
124
|
+
root={root.dom}
|
125
|
+
onTouch={onTouch}
|
126
|
+
onLayout={onLayout}
|
132
127
|
mode={mode}
|
133
128
|
debug={debug}
|
134
|
-
picture={picture}
|
135
|
-
onLayout={onLayout}
|
136
129
|
{...props}
|
137
130
|
/>
|
138
131
|
);
|
package/src/skia/types/Canvas.ts
CHANGED
@@ -8,7 +8,7 @@ import type { SkColor } from "./Color";
|
|
8
8
|
import type { SkRRect } from "./RRect";
|
9
9
|
import type { BlendMode } from "./Paint/BlendMode";
|
10
10
|
import type { SkPoint, PointMode } from "./Point";
|
11
|
-
import type {
|
11
|
+
import type { InputMatrix } from "./Matrix";
|
12
12
|
import type { SkImageFilter } from "./ImageFilter";
|
13
13
|
import type { SkVertices } from "./Vertices";
|
14
14
|
import type { SkTextBlob } from "./TextBlob";
|
@@ -485,7 +485,7 @@ export interface SkCanvas {
|
|
485
485
|
* Replaces current matrix with m premultiplied with the existing matrix.
|
486
486
|
* @param m
|
487
487
|
*/
|
488
|
-
concat(m:
|
488
|
+
concat(m: InputMatrix): void;
|
489
489
|
|
490
490
|
/**
|
491
491
|
* Draws the given picture using the current clip, current matrix, and the provided paint.
|
package/src/skia/types/Matrix.ts
CHANGED
@@ -7,7 +7,7 @@ export const isMatrix = (obj: unknown): obj is SkMatrix =>
|
|
7
7
|
obj !== null && (obj as SkJSIInstance<string>).__typename__ === "Matrix";
|
8
8
|
|
9
9
|
export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
10
|
-
concat: (matrix:
|
10
|
+
concat: (matrix: InputMatrix) => SkMatrix;
|
11
11
|
translate: (x: number, y: number) => SkMatrix;
|
12
12
|
scale: (x: number, y?: number) => SkMatrix;
|
13
13
|
skew: (x: number, y: number) => SkMatrix;
|
@@ -20,6 +20,8 @@ export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
|
20
20
|
get: () => number[];
|
21
21
|
}
|
22
22
|
|
23
|
+
export type InputMatrix = SkMatrix | Matrix3 | Matrix4 | number[];
|
24
|
+
|
23
25
|
export interface TransformProp {
|
24
26
|
transform?: Transforms3d;
|
25
27
|
}
|
@@ -278,67 +278,98 @@ export const rotateY = (value: number, p?: Point) => {
|
|
278
278
|
*/
|
279
279
|
export const processTransform3d = (transforms: Transforms3d) => {
|
280
280
|
"worklet";
|
281
|
-
return
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
281
|
+
return transforms.reduce((acc, val) => {
|
282
|
+
const key = Object.keys(val)[0] as Transform3dName;
|
283
|
+
const transform = val as Pick<Transformations, typeof key>;
|
284
|
+
if (key === "translateX") {
|
285
|
+
const value = transform[key];
|
286
|
+
return multiply4(acc, translate(value, 0, 0));
|
287
|
+
}
|
288
|
+
if (key === "translate") {
|
289
|
+
const [x, y, z = 0] = transform[key];
|
290
|
+
return multiply4(acc, translate(x, y, z));
|
291
|
+
}
|
292
|
+
if (key === "translateY") {
|
293
|
+
const value = transform[key];
|
294
|
+
return multiply4(acc, translate(0, value, 0));
|
295
|
+
}
|
296
|
+
if (key === "translateZ") {
|
297
|
+
const value = transform[key];
|
298
|
+
return multiply4(acc, translate(0, 0, value));
|
299
|
+
}
|
300
|
+
if (key === "scale") {
|
301
|
+
const value = transform[key];
|
302
|
+
return multiply4(acc, scale(value, value, 1));
|
303
|
+
}
|
304
|
+
if (key === "scaleX") {
|
305
|
+
const value = transform[key];
|
306
|
+
return multiply4(acc, scale(value, 1, 1));
|
307
|
+
}
|
308
|
+
if (key === "scaleY") {
|
309
|
+
const value = transform[key];
|
310
|
+
return multiply4(acc, scale(1, value, 1));
|
311
|
+
}
|
312
|
+
if (key === "skewX") {
|
313
|
+
const value = transform[key];
|
314
|
+
return multiply4(acc, skewX(value));
|
315
|
+
}
|
316
|
+
if (key === "skewY") {
|
317
|
+
const value = transform[key];
|
318
|
+
return multiply4(acc, skewY(value));
|
319
|
+
}
|
320
|
+
if (key === "rotateX") {
|
321
|
+
const value = transform[key];
|
322
|
+
return multiply4(acc, rotate([1, 0, 0], value));
|
323
|
+
}
|
324
|
+
if (key === "rotateY") {
|
325
|
+
const value = transform[key];
|
326
|
+
return multiply4(acc, rotate([0, 1, 0], value));
|
327
|
+
}
|
328
|
+
if (key === "perspective") {
|
329
|
+
const value = transform[key];
|
330
|
+
return multiply4(acc, perspective(value));
|
331
|
+
}
|
332
|
+
if (key === "rotate" || key === "rotateZ") {
|
333
|
+
const value = transform[key];
|
334
|
+
return multiply4(acc, rotate([0, 0, 1], value));
|
335
|
+
}
|
336
|
+
if (key === "matrix") {
|
337
|
+
const value = transform[key];
|
338
|
+
return multiply4(acc, value);
|
339
|
+
}
|
340
|
+
return exhaustiveCheck(key);
|
341
|
+
}, Matrix4());
|
342
|
+
};
|
343
|
+
|
344
|
+
/**
|
345
|
+
* @worklet
|
346
|
+
*/
|
347
|
+
export const convertToColumnMajor = (rowMajorMatrix: Matrix4) => {
|
348
|
+
"worklet";
|
349
|
+
|
350
|
+
const colMajorMatrix = new Array<number>(16);
|
351
|
+
const size = 4;
|
352
|
+
for (let row = 0; row < size; row++) {
|
353
|
+
for (let col = 0; col < size; col++) {
|
354
|
+
colMajorMatrix[col * size + row] = rowMajorMatrix[row * size + col];
|
355
|
+
}
|
356
|
+
}
|
357
|
+
return colMajorMatrix;
|
358
|
+
};
|
359
|
+
|
360
|
+
/**
|
361
|
+
* @worklet
|
362
|
+
*/
|
363
|
+
export const convertToAffineMatrix = (m4: number[]) => {
|
364
|
+
"worklet";
|
365
|
+
// Extracting the relevant components from the 4x4 matrix
|
366
|
+
const a = m4[0]; // Scale X
|
367
|
+
const b = m4[1]; // Skew Y
|
368
|
+
const c = m4[4]; // Skew X
|
369
|
+
const d = m4[5]; // Scale Y
|
370
|
+
const tx = m4[12]; // Translate X
|
371
|
+
const ty = m4[13]; // Translate Y
|
372
|
+
|
373
|
+
// Returning the 6-element affine transformation matrix
|
374
|
+
return [a, b, c, d, tx, ty];
|
344
375
|
};
|
@@ -2,7 +2,7 @@ import type { SkRect } from "../Rect";
|
|
2
2
|
import type { SkPoint } from "../Point";
|
3
3
|
import type { SkRRect } from "../RRect";
|
4
4
|
import type { StrokeJoin, StrokeCap } from "../Paint";
|
5
|
-
import type { SkMatrix } from "../Matrix";
|
5
|
+
import type { InputMatrix, SkMatrix } from "../Matrix";
|
6
6
|
import type { SkJSIInstance } from "../JsiInstance";
|
7
7
|
|
8
8
|
/**
|
@@ -540,7 +540,7 @@ export interface SkPath extends SkJSIInstance<"Path"> {
|
|
540
540
|
/**
|
541
541
|
* Transforms the path by the specified matrix.
|
542
542
|
*/
|
543
|
-
transform(m3:
|
543
|
+
transform(m3: InputMatrix): SkPath;
|
544
544
|
|
545
545
|
/**
|
546
546
|
* Interpolates between Path with point array of equal size.
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import type { CanvasKit, Matrix3x3 } from "canvaskit-wasm";
|
2
2
|
|
3
|
-
import { toMatrix3
|
3
|
+
import { toMatrix3 } from "../types";
|
4
|
+
import type { SkMatrix, InputMatrix, Matrix4 } from "../types";
|
4
5
|
|
5
6
|
import { HostObject } from "./Host";
|
6
7
|
|
7
|
-
const isMatrixHostObject = (
|
8
|
-
obj
|
9
|
-
): obj is SkMatrix => !Array.isArray(obj);
|
8
|
+
const isMatrixHostObject = (obj: InputMatrix): obj is SkMatrix =>
|
9
|
+
!Array.isArray(obj);
|
10
10
|
|
11
11
|
export class JsiSkMatrix
|
12
12
|
extends HostObject<Matrix3x3, "Matrix">
|
@@ -28,7 +28,7 @@ export class JsiSkMatrix
|
|
28
28
|
// Do nothing - the matrix is represenetd by a Float32Array
|
29
29
|
};
|
30
30
|
|
31
|
-
concat(matrix:
|
31
|
+
concat(matrix: InputMatrix) {
|
32
32
|
this.preMultiply(
|
33
33
|
// eslint-disable-next-line no-nested-ternary
|
34
34
|
isMatrixHostObject(matrix)
|