@shopify/react-native-skia 0.1.236 → 0.1.237
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkApi.h +2 -0
- package/cpp/api/JsiSkCanvas.h +36 -0
- package/cpp/api/JsiSkRSXform.h +35 -7
- package/cpp/rnskia/dom/JsiDomApi.h +2 -0
- package/cpp/rnskia/dom/nodes/JsiAtlasNode.h +60 -0
- package/cpp/rnskia/dom/props/RSXformProp.h +52 -0
- package/cpp/rnskia/dom/props/RectProp.h +31 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +2 -1
- package/lib/commonjs/dom/nodes/JsiSkDOM.js +4 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/AtlasNode.d.ts +8 -0
- package/lib/commonjs/dom/nodes/drawings/AtlasNode.js +47 -0
- package/lib/commonjs/dom/nodes/drawings/AtlasNode.js.map +1 -0
- package/lib/commonjs/dom/nodes/drawings/index.d.ts +1 -0
- package/lib/commonjs/dom/nodes/drawings/index.js +13 -0
- package/lib/commonjs/dom/nodes/drawings/index.js.map +1 -1
- package/lib/commonjs/dom/types/Drawings.d.ts +7 -1
- package/lib/commonjs/dom/types/Drawings.js.map +1 -1
- package/lib/commonjs/dom/types/NodeType.d.ts +1 -0
- package/lib/commonjs/dom/types/NodeType.js +1 -0
- package/lib/commonjs/dom/types/NodeType.js.map +1 -1
- package/lib/commonjs/dom/types/SkDOM.d.ts +2 -1
- package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
- package/lib/commonjs/external/reanimated/buffers.d.ts +5 -0
- package/lib/commonjs/external/reanimated/buffers.js +48 -0
- package/lib/commonjs/external/reanimated/buffers.js.map +1 -0
- package/lib/commonjs/external/reanimated/index.d.ts +1 -0
- package/lib/commonjs/external/reanimated/index.js +13 -0
- package/lib/commonjs/external/reanimated/index.js.map +1 -1
- package/lib/commonjs/external/reanimated/textures.js +3 -17
- package/lib/commonjs/external/reanimated/textures.js.map +1 -1
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +8 -1
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
- package/lib/commonjs/mock/index.js +5 -0
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/HostComponents.d.ts +3 -1
- package/lib/commonjs/renderer/HostComponents.js +3 -0
- package/lib/commonjs/renderer/HostComponents.js.map +1 -1
- package/lib/commonjs/renderer/Offscreen.d.ts +4 -2
- package/lib/commonjs/renderer/Offscreen.js +23 -18
- package/lib/commonjs/renderer/Offscreen.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/Atlas.d.ts +4 -0
- package/lib/commonjs/renderer/components/shapes/Atlas.js +17 -0
- package/lib/commonjs/renderer/components/shapes/Atlas.js.map +1 -0
- package/lib/commonjs/renderer/components/shapes/index.d.ts +1 -0
- package/lib/commonjs/renderer/components/shapes/index.js +13 -0
- package/lib/commonjs/renderer/components/shapes/index.js.map +1 -1
- package/lib/commonjs/skia/core/AnimatedImage.d.ts +1 -1
- package/lib/commonjs/skia/core/AnimatedImage.js +4 -1
- package/lib/commonjs/skia/core/AnimatedImage.js.map +1 -1
- package/lib/commonjs/skia/core/Data.d.ts +1 -1
- package/lib/commonjs/skia/core/Data.js +11 -4
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/Rect.d.ts +2 -2
- package/lib/commonjs/skia/types/Canvas.d.ts +16 -1
- package/lib/commonjs/skia/types/Canvas.js.map +1 -1
- package/lib/commonjs/skia/types/Image/Image.d.ts +8 -0
- package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
- package/lib/commonjs/skia/types/RSXform.d.ts +7 -1
- package/lib/commonjs/skia/types/RSXform.js.map +1 -1
- package/lib/commonjs/skia/types/Rect.d.ts +4 -0
- package/lib/commonjs/skia/types/Rect.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +3 -2
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +2 -1
- package/lib/commonjs/skia/web/JsiSkCanvas.js +19 -0
- package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkRSXform.d.ts +8 -2
- package/lib/commonjs/skia/web/JsiSkRSXform.js +33 -2
- package/lib/commonjs/skia/web/JsiSkRSXform.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkRect.d.ts +3 -2
- package/lib/commonjs/skia/web/JsiSkRect.js +7 -0
- package/lib/commonjs/skia/web/JsiSkRect.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js +2 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +5 -0
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/dom/nodes/JsiSkDOM.d.ts +2 -1
- package/lib/module/dom/nodes/JsiSkDOM.js +5 -1
- package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/module/dom/nodes/drawings/AtlasNode.d.ts +8 -0
- package/lib/module/dom/nodes/drawings/AtlasNode.js +34 -0
- package/lib/module/dom/nodes/drawings/AtlasNode.js.map +1 -0
- package/lib/module/dom/nodes/drawings/index.d.ts +1 -0
- package/lib/module/dom/nodes/drawings/index.js +1 -0
- package/lib/module/dom/nodes/drawings/index.js.map +1 -1
- package/lib/module/dom/types/Drawings.d.ts +7 -1
- package/lib/module/dom/types/Drawings.js.map +1 -1
- package/lib/module/dom/types/NodeType.d.ts +1 -0
- package/lib/module/dom/types/NodeType.js +1 -0
- package/lib/module/dom/types/NodeType.js.map +1 -1
- package/lib/module/dom/types/SkDOM.d.ts +2 -1
- package/lib/module/dom/types/SkDOM.js.map +1 -1
- package/lib/module/external/reanimated/buffers.d.ts +5 -0
- package/lib/module/external/reanimated/buffers.js +27 -0
- package/lib/module/external/reanimated/buffers.js.map +1 -0
- package/lib/module/external/reanimated/index.d.ts +1 -0
- package/lib/module/external/reanimated/index.js +1 -0
- package/lib/module/external/reanimated/index.js.map +1 -1
- package/lib/module/external/reanimated/textures.js +5 -16
- package/lib/module/external/reanimated/textures.js.map +1 -1
- package/lib/module/external/reanimated/useAnimatedImageValue.js +7 -1
- package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
- package/lib/module/mock/index.js +5 -0
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/HostComponents.d.ts +3 -1
- package/lib/module/renderer/HostComponents.js +3 -0
- package/lib/module/renderer/HostComponents.js.map +1 -1
- package/lib/module/renderer/Offscreen.d.ts +4 -2
- package/lib/module/renderer/Offscreen.js +15 -13
- package/lib/module/renderer/Offscreen.js.map +1 -1
- package/lib/module/renderer/components/shapes/Atlas.d.ts +4 -0
- package/lib/module/renderer/components/shapes/Atlas.js +5 -0
- package/lib/module/renderer/components/shapes/Atlas.js.map +1 -0
- package/lib/module/renderer/components/shapes/index.d.ts +1 -0
- package/lib/module/renderer/components/shapes/index.js +1 -0
- package/lib/module/renderer/components/shapes/index.js.map +1 -1
- package/lib/module/skia/core/AnimatedImage.d.ts +1 -1
- package/lib/module/skia/core/AnimatedImage.js +4 -1
- package/lib/module/skia/core/AnimatedImage.js.map +1 -1
- package/lib/module/skia/core/Data.d.ts +1 -1
- package/lib/module/skia/core/Data.js +11 -4
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Rect.d.ts +2 -2
- package/lib/module/skia/types/Canvas.d.ts +16 -1
- package/lib/module/skia/types/Canvas.js.map +1 -1
- package/lib/module/skia/types/Image/Image.d.ts +8 -0
- package/lib/module/skia/types/Image/Image.js.map +1 -1
- package/lib/module/skia/types/RSXform.d.ts +7 -1
- package/lib/module/skia/types/RSXform.js.map +1 -1
- package/lib/module/skia/types/Rect.d.ts +4 -0
- package/lib/module/skia/types/Rect.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +3 -2
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/web/JsiSkCanvas.d.ts +2 -1
- package/lib/module/skia/web/JsiSkCanvas.js +18 -0
- package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/module/skia/web/JsiSkRSXform.d.ts +8 -2
- package/lib/module/skia/web/JsiSkRSXform.js +34 -3
- package/lib/module/skia/web/JsiSkRSXform.js.map +1 -1
- package/lib/module/skia/web/JsiSkRect.d.ts +3 -2
- package/lib/module/skia/web/JsiSkRect.js +7 -0
- package/lib/module/skia/web/JsiSkRect.js.map +1 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js +2 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +5 -0
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -1
- package/lib/typescript/src/dom/nodes/drawings/AtlasNode.d.ts +8 -0
- package/lib/typescript/src/dom/nodes/drawings/index.d.ts +1 -0
- package/lib/typescript/src/dom/types/Drawings.d.ts +7 -1
- package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
- package/lib/typescript/src/dom/types/SkDOM.d.ts +2 -1
- package/lib/typescript/src/external/reanimated/buffers.d.ts +5 -0
- package/lib/typescript/src/external/reanimated/index.d.ts +1 -0
- package/lib/typescript/src/renderer/HostComponents.d.ts +3 -1
- package/lib/typescript/src/renderer/Offscreen.d.ts +4 -2
- package/lib/typescript/src/renderer/components/shapes/Atlas.d.ts +4 -0
- package/lib/typescript/src/renderer/components/shapes/index.d.ts +1 -0
- package/lib/typescript/src/skia/core/AnimatedImage.d.ts +1 -1
- package/lib/typescript/src/skia/core/Data.d.ts +1 -1
- package/lib/typescript/src/skia/core/Rect.d.ts +2 -2
- package/lib/typescript/src/skia/types/Canvas.d.ts +16 -1
- package/lib/typescript/src/skia/types/Image/Image.d.ts +8 -0
- package/lib/typescript/src/skia/types/RSXform.d.ts +7 -1
- package/lib/typescript/src/skia/types/Rect.d.ts +4 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +3 -2
- package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +2 -1
- package/lib/typescript/src/skia/web/JsiSkRSXform.d.ts +8 -2
- package/lib/typescript/src/skia/web/JsiSkRect.d.ts +3 -2
- package/package.json +1 -1
- package/src/dom/nodes/JsiSkDOM.ts +8 -0
- package/src/dom/nodes/drawings/AtlasNode.ts +24 -0
- package/src/dom/nodes/drawings/index.ts +1 -0
- package/src/dom/types/Drawings.ts +9 -0
- package/src/dom/types/NodeType.ts +1 -0
- package/src/dom/types/SkDOM.ts +2 -0
- package/src/external/reanimated/buffers.ts +53 -0
- package/src/external/reanimated/index.ts +1 -0
- package/src/external/reanimated/textures.tsx +7 -19
- package/src/external/reanimated/useAnimatedImageValue.ts +15 -4
- package/src/mock/index.ts +5 -0
- package/src/renderer/HostComponents.ts +6 -1
- package/src/renderer/Offscreen.tsx +20 -16
- package/src/renderer/components/shapes/Atlas.tsx +8 -0
- package/src/renderer/components/shapes/index.ts +1 -0
- package/src/skia/core/AnimatedImage.ts +3 -2
- package/src/skia/core/Data.ts +8 -4
- package/src/skia/types/Canvas.ts +32 -1
- package/src/skia/types/Image/Image.ts +10 -0
- package/src/skia/types/RSXform.ts +7 -1
- package/src/skia/types/Rect.ts +6 -0
- package/src/skia/types/Skia.ts +10 -2
- package/src/skia/web/JsiSkCanvas.ts +60 -23
- package/src/skia/web/JsiSkRSXform.ts +28 -4
- package/src/skia/web/JsiSkRect.ts +12 -2
- package/src/skia/web/JsiSkTextBlobFactory.ts +5 -5
- package/src/skia/web/JsiSkia.ts +15 -0
@@ -1,26 +1,11 @@
|
|
1
1
|
import type { ReactElement } from "react";
|
2
2
|
|
3
3
|
import { JsiDrawingContext } from "../dom/types";
|
4
|
+
import type { SkPicture, SkSize } from "../skia/types";
|
4
5
|
import { Skia } from "../skia";
|
5
6
|
|
6
7
|
import { SkiaRoot } from "./Reconciler";
|
7
8
|
|
8
|
-
export const drawAsImage = (
|
9
|
-
element: ReactElement,
|
10
|
-
width: number,
|
11
|
-
height: number
|
12
|
-
) => {
|
13
|
-
const picture = drawAsPicture(element);
|
14
|
-
const surface = Skia.Surface.MakeOffscreen(width, height);
|
15
|
-
if (!surface) {
|
16
|
-
throw new Error("Could not create offscreen surface");
|
17
|
-
}
|
18
|
-
const canvas = surface.getCanvas();
|
19
|
-
canvas.drawPicture(picture);
|
20
|
-
surface.flush();
|
21
|
-
return surface.makeImageSnapshot();
|
22
|
-
};
|
23
|
-
|
24
9
|
export const drawAsPicture = (element: ReactElement) => {
|
25
10
|
const recorder = Skia.PictureRecorder();
|
26
11
|
const canvas = recorder.beginRecording();
|
@@ -31,3 +16,22 @@ export const drawAsPicture = (element: ReactElement) => {
|
|
31
16
|
const picture = recorder.finishRecordingAsPicture();
|
32
17
|
return picture;
|
33
18
|
};
|
19
|
+
|
20
|
+
export const drawAsImage = (element: ReactElement, size: SkSize) => {
|
21
|
+
return drawAsImageFromPicture(drawAsPicture(element), size);
|
22
|
+
};
|
23
|
+
|
24
|
+
// TODO: We're not sure yet why PixelRatio is not needed here.
|
25
|
+
const pd = 1;
|
26
|
+
export const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {
|
27
|
+
"worklet";
|
28
|
+
const surface = Skia.Surface.MakeOffscreen(
|
29
|
+
size.width * pd,
|
30
|
+
size.height * pd
|
31
|
+
)!;
|
32
|
+
const canvas = surface.getCanvas();
|
33
|
+
canvas.scale(pd, pd);
|
34
|
+
canvas.drawPicture(picture);
|
35
|
+
surface.flush();
|
36
|
+
return surface.makeImageSnapshot();
|
37
|
+
};
|
@@ -12,5 +12,6 @@ const animatedImgFactory = Skia.AnimatedImage.MakeAnimatedImageFromEncoded.bind(
|
|
12
12
|
* */
|
13
13
|
export const useAnimatedImage = (
|
14
14
|
source: DataSourceParam,
|
15
|
-
onError?: (err: Error) => void
|
16
|
-
|
15
|
+
onError?: (err: Error) => void,
|
16
|
+
managed = true
|
17
|
+
) => useRawData(source, animatedImgFactory, onError, managed);
|
package/src/skia/core/Data.ts
CHANGED
@@ -40,7 +40,8 @@ export const loadData = <T>(
|
|
40
40
|
|
41
41
|
const useLoading = <T extends SkJSIInstance<string>>(
|
42
42
|
source: DataSourceParam,
|
43
|
-
loader: () => Promise<T | null
|
43
|
+
loader: () => Promise<T | null>,
|
44
|
+
manage = true
|
44
45
|
) => {
|
45
46
|
const mounted = useRef(false);
|
46
47
|
const [data, setData] = useState<T | null>(null);
|
@@ -54,7 +55,9 @@ const useLoading = <T extends SkJSIInstance<string>>(
|
|
54
55
|
}
|
55
56
|
});
|
56
57
|
return () => {
|
57
|
-
|
58
|
+
if (manage) {
|
59
|
+
dataRef.current?.dispose();
|
60
|
+
}
|
58
61
|
mounted.current = false;
|
59
62
|
};
|
60
63
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
@@ -94,8 +97,9 @@ export const useCollectionLoading = <T extends SkJSIInstance<string>>(
|
|
94
97
|
export const useRawData = <T extends SkJSIInstance<string>>(
|
95
98
|
source: DataSourceParam,
|
96
99
|
factory: (data: SkData) => T | null,
|
97
|
-
onError?: (err: Error) => void
|
98
|
-
|
100
|
+
onError?: (err: Error) => void,
|
101
|
+
manage = true
|
102
|
+
) => useLoading(source, () => loadData<T>(source, factory, onError), manage);
|
99
103
|
|
100
104
|
const identity = (data: SkData) => data;
|
101
105
|
|
package/src/skia/types/Canvas.ts
CHANGED
@@ -2,7 +2,14 @@ import type { SkPaint } from "./Paint";
|
|
2
2
|
import type { SkRect } from "./Rect";
|
3
3
|
import type { SkFont } from "./Font";
|
4
4
|
import type { SkPath } from "./Path";
|
5
|
-
import type {
|
5
|
+
import type {
|
6
|
+
SkImage,
|
7
|
+
MipmapMode,
|
8
|
+
FilterMode,
|
9
|
+
ImageInfo,
|
10
|
+
CubicResampler,
|
11
|
+
FilterOptions,
|
12
|
+
} from "./Image";
|
6
13
|
import type { SkSVG } from "./SVG";
|
7
14
|
import type { SkColor } from "./Color";
|
8
15
|
import type { InputRRect } from "./RRect";
|
@@ -13,6 +20,7 @@ import type { SkImageFilter } from "./ImageFilter";
|
|
13
20
|
import type { SkVertices } from "./Vertices";
|
14
21
|
import type { SkTextBlob } from "./TextBlob";
|
15
22
|
import type { SkPicture } from "./Picture";
|
23
|
+
import type { SkRSXform } from "./RSXform";
|
16
24
|
|
17
25
|
export enum ClipOp {
|
18
26
|
Difference,
|
@@ -493,6 +501,29 @@ export interface SkCanvas {
|
|
493
501
|
*/
|
494
502
|
drawPicture(skp: SkPicture): void;
|
495
503
|
|
504
|
+
/**
|
505
|
+
* This method is used to draw an atlas on the canvas.
|
506
|
+
*
|
507
|
+
* @method drawAtlas
|
508
|
+
* @param {SkImage} atlas - The image to be drawn.
|
509
|
+
* @param {SkRect[]} srcs - The source rectangles.
|
510
|
+
* @param {SkRSXform[]} dsts - The destination transformations.
|
511
|
+
* @param {SkPaint} paint - The paint used for drawing.
|
512
|
+
* @param {BlendMode} [blendMode] - The blend mode used for drawing. Optional.
|
513
|
+
* @param {SkColor[]} [colors] - The colors used for drawing. Optional.
|
514
|
+
* @param {CubicResampler | FilterOptions} [sampling] - The sampling options. Optional.
|
515
|
+
* @returns {void} This method does not return anything.
|
516
|
+
*/
|
517
|
+
drawAtlas(
|
518
|
+
atlas: SkImage,
|
519
|
+
srcs: SkRect[],
|
520
|
+
dsts: SkRSXform[],
|
521
|
+
paint: SkPaint,
|
522
|
+
blendMode?: BlendMode,
|
523
|
+
colors?: SkColor[],
|
524
|
+
sampling?: CubicResampler | FilterOptions
|
525
|
+
): void;
|
526
|
+
|
496
527
|
/** Read Image pixels
|
497
528
|
*
|
498
529
|
* @param srcX - x-axis upper left corner of the rectangle to read from
|
@@ -5,6 +5,16 @@ import type { SkShader } from "../Shader";
|
|
5
5
|
|
6
6
|
import type { ImageInfo } from "./ImageFactory";
|
7
7
|
|
8
|
+
export interface CubicResampler {
|
9
|
+
B: number;
|
10
|
+
C: number;
|
11
|
+
}
|
12
|
+
|
13
|
+
export interface FilterOptions {
|
14
|
+
filter: FilterMode;
|
15
|
+
mipmap?: MipmapMode;
|
16
|
+
}
|
17
|
+
|
8
18
|
export enum FilterMode {
|
9
19
|
Nearest,
|
10
20
|
Linear,
|
@@ -1,3 +1,9 @@
|
|
1
1
|
import type { SkJSIInstance } from "./JsiInstance";
|
2
2
|
|
3
|
-
export
|
3
|
+
export interface SkRSXform extends SkJSIInstance<"RSXform"> {
|
4
|
+
readonly scos: number;
|
5
|
+
readonly ssin: number;
|
6
|
+
readonly tx: number;
|
7
|
+
readonly ty: number;
|
8
|
+
set(scos: number, ssin: number, tx: number, ty: number): void;
|
9
|
+
}
|
package/src/skia/types/Rect.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import type { SkJSIInstance } from "./JsiInstance";
|
2
|
+
|
1
3
|
export interface SkRect {
|
2
4
|
readonly x: number;
|
3
5
|
readonly y: number;
|
@@ -5,6 +7,10 @@ export interface SkRect {
|
|
5
7
|
readonly height: number;
|
6
8
|
}
|
7
9
|
|
10
|
+
export interface SkHostRect extends SkRect, SkJSIInstance<"Rect"> {
|
11
|
+
setXYWH(x: number, y: number, width: number, height: number): void;
|
12
|
+
}
|
13
|
+
|
8
14
|
export const isRect = (def: unknown): def is SkRect => {
|
9
15
|
"worklet";
|
10
16
|
if (typeof def === "object" && def !== null) {
|
package/src/skia/types/Skia.ts
CHANGED
@@ -6,7 +6,7 @@ import type { SkTypeface, TypefaceFactory } from "./Typeface";
|
|
6
6
|
import type { ImageFactory } from "./Image";
|
7
7
|
import type { MaskFilterFactory } from "./MaskFilter";
|
8
8
|
import type { SkPaint } from "./Paint";
|
9
|
-
import type { SkRect } from "./Rect";
|
9
|
+
import type { SkHostRect, SkRect } from "./Rect";
|
10
10
|
import type { SkRRect } from "./RRect";
|
11
11
|
import type {
|
12
12
|
RuntimeEffectFactory,
|
@@ -36,10 +36,18 @@ import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
|
|
36
36
|
*/
|
37
37
|
export interface Skia {
|
38
38
|
Point: (x: number, y: number) => SkPoint;
|
39
|
-
XYWHRect: (x: number, y: number, width: number, height: number) =>
|
39
|
+
XYWHRect: (x: number, y: number, width: number, height: number) => SkHostRect;
|
40
40
|
RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;
|
41
41
|
RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;
|
42
42
|
RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
|
43
|
+
RSXformFromRadians: (
|
44
|
+
scale: number,
|
45
|
+
radians: number,
|
46
|
+
tx: number,
|
47
|
+
ty: number,
|
48
|
+
px: number,
|
49
|
+
py: number
|
50
|
+
) => SkRSXform;
|
43
51
|
Color: (color: Color) => SkColor;
|
44
52
|
ContourMeasureIter: (
|
45
53
|
path: SkPath,
|
@@ -1,28 +1,31 @@
|
|
1
1
|
import type { Canvas, CanvasKit } from "canvaskit-wasm";
|
2
2
|
|
3
|
-
import
|
4
|
-
BlendMode,
|
5
|
-
ClipOp,
|
6
|
-
FilterMode,
|
7
|
-
MipmapMode,
|
8
|
-
PointMode,
|
9
|
-
SaveLayerFlag,
|
10
|
-
ImageInfo,
|
11
|
-
SkCanvas,
|
12
|
-
SkColor,
|
13
|
-
SkFont,
|
14
|
-
SkImage,
|
15
|
-
SkImageFilter,
|
16
|
-
SkMatrix,
|
17
|
-
SkPaint,
|
18
|
-
SkPath,
|
19
|
-
SkPicture,
|
20
|
-
SkPoint,
|
21
|
-
SkRect,
|
22
|
-
InputRRect,
|
23
|
-
SkSVG,
|
24
|
-
SkTextBlob,
|
25
|
-
SkVertices,
|
3
|
+
import {
|
4
|
+
type BlendMode,
|
5
|
+
type ClipOp,
|
6
|
+
type FilterMode,
|
7
|
+
type MipmapMode,
|
8
|
+
type PointMode,
|
9
|
+
type SaveLayerFlag,
|
10
|
+
type ImageInfo,
|
11
|
+
type SkCanvas,
|
12
|
+
type SkColor,
|
13
|
+
type SkFont,
|
14
|
+
type SkImage,
|
15
|
+
type SkImageFilter,
|
16
|
+
type SkMatrix,
|
17
|
+
type SkPaint,
|
18
|
+
type SkPath,
|
19
|
+
type SkPicture,
|
20
|
+
type SkPoint,
|
21
|
+
type SkRect,
|
22
|
+
type InputRRect,
|
23
|
+
type SkSVG,
|
24
|
+
type SkTextBlob,
|
25
|
+
type SkVertices,
|
26
|
+
type SkRSXform,
|
27
|
+
type CubicResampler,
|
28
|
+
type FilterOptions,
|
26
29
|
} from "../types";
|
27
30
|
|
28
31
|
import { getEnum, HostObject } from "./Host";
|
@@ -38,6 +41,7 @@ import { JsiSkPicture } from "./JsiSkPicture";
|
|
38
41
|
import { JsiSkMatrix } from "./JsiSkMatrix";
|
39
42
|
import { JsiSkImageFilter } from "./JsiSkImageFilter";
|
40
43
|
import { JsiSkPoint } from "./JsiSkPoint";
|
44
|
+
import { JsiSkRSXform } from "./JsiSkRSXform";
|
41
45
|
|
42
46
|
export class JsiSkCanvas
|
43
47
|
extends HostObject<Canvas, "Canvas">
|
@@ -383,6 +387,39 @@ export class JsiSkCanvas
|
|
383
387
|
this.ref.drawPicture(JsiSkPicture.fromValue(skp));
|
384
388
|
}
|
385
389
|
|
390
|
+
drawAtlas(
|
391
|
+
atlas: SkImage,
|
392
|
+
srcs: SkRect[],
|
393
|
+
dsts: SkRSXform[],
|
394
|
+
paint: SkPaint,
|
395
|
+
blendMode?: BlendMode,
|
396
|
+
colors?: SkColor[],
|
397
|
+
_sampling?: CubicResampler | FilterOptions
|
398
|
+
) {
|
399
|
+
const src = srcs.flatMap((s) =>
|
400
|
+
Array.from(JsiSkRect.fromValue(this.CanvasKit, s))
|
401
|
+
);
|
402
|
+
const dst = dsts.flatMap((s) => Array.from(JsiSkRSXform.fromValue(s)));
|
403
|
+
let cls: Uint32Array | undefined;
|
404
|
+
if (colors) {
|
405
|
+
cls = new Uint32Array(colors.length);
|
406
|
+
for (let i = 0; i < colors.length; i++) {
|
407
|
+
const [r, g, b, a] = colors[i];
|
408
|
+
cls[i] = this.CanvasKit.ColorAsInt(r * 255, g * 255, b * 255, a * 255);
|
409
|
+
}
|
410
|
+
}
|
411
|
+
this.ref.drawAtlas(
|
412
|
+
JsiSkImage.fromValue(atlas),
|
413
|
+
src,
|
414
|
+
dst,
|
415
|
+
JsiSkPaint.fromValue(paint),
|
416
|
+
blendMode
|
417
|
+
? getEnum(this.CanvasKit.BlendMode, blendMode)
|
418
|
+
: this.CanvasKit.BlendMode.DstOver,
|
419
|
+
cls
|
420
|
+
);
|
421
|
+
}
|
422
|
+
|
386
423
|
readPixels(srcX: number, srcY: number, imageInfo: ImageInfo) {
|
387
424
|
const pxInfo = {
|
388
425
|
width: imageInfo.width,
|
@@ -2,19 +2,43 @@ import type { CanvasKit } from "canvaskit-wasm";
|
|
2
2
|
|
3
3
|
import type { SkRSXform } from "../types";
|
4
4
|
|
5
|
-
import {
|
5
|
+
import { BaseHostObject } from "./Host";
|
6
6
|
|
7
7
|
export type RSXform = Float32Array;
|
8
8
|
|
9
9
|
export class JsiSkRSXform
|
10
|
-
extends
|
10
|
+
extends BaseHostObject<RSXform, "RSXform">
|
11
11
|
implements SkRSXform
|
12
12
|
{
|
13
|
+
static fromValue(rsxform: SkRSXform) {
|
14
|
+
if (rsxform instanceof JsiSkRSXform) {
|
15
|
+
return rsxform.ref;
|
16
|
+
}
|
17
|
+
return Float32Array.of(rsxform.scos, rsxform.ssin, rsxform.tx, rsxform.ty);
|
18
|
+
}
|
19
|
+
|
13
20
|
constructor(CanvasKit: CanvasKit, ref: RSXform) {
|
14
21
|
super(CanvasKit, ref, "RSXform");
|
15
22
|
}
|
16
|
-
|
23
|
+
set(scos: number, ssin: number, tx: number, ty: number) {
|
24
|
+
this.ref[0] = scos;
|
25
|
+
this.ref[1] = ssin;
|
26
|
+
this.ref[2] = tx;
|
27
|
+
this.ref[3] = ty;
|
28
|
+
}
|
29
|
+
get scos() {
|
30
|
+
return this.ref[0];
|
31
|
+
}
|
32
|
+
get ssin() {
|
33
|
+
return this.ref[1];
|
34
|
+
}
|
35
|
+
get tx() {
|
36
|
+
return this.ref[2];
|
37
|
+
}
|
38
|
+
get ty() {
|
39
|
+
return this.ref[3];
|
40
|
+
}
|
17
41
|
dispose = () => {
|
18
|
-
//
|
42
|
+
// nothing to do here, RSXform is a Float32Array
|
19
43
|
};
|
20
44
|
}
|
@@ -1,10 +1,13 @@
|
|
1
1
|
import type { CanvasKit, Rect } from "canvaskit-wasm";
|
2
2
|
|
3
|
-
import type { SkRect } from "../types";
|
3
|
+
import type { SkHostRect, SkRect } from "../types";
|
4
4
|
|
5
5
|
import { BaseHostObject } from "./Host";
|
6
6
|
|
7
|
-
export class JsiSkRect
|
7
|
+
export class JsiSkRect
|
8
|
+
extends BaseHostObject<Rect, "Rect">
|
9
|
+
implements SkHostRect
|
10
|
+
{
|
8
11
|
static fromValue(CanvasKit: CanvasKit, rect: SkRect) {
|
9
12
|
if (rect instanceof JsiSkRect) {
|
10
13
|
return rect.ref;
|
@@ -20,6 +23,13 @@ export class JsiSkRect extends BaseHostObject<Rect, "Rect"> implements SkRect {
|
|
20
23
|
super(CanvasKit, ref, "Rect");
|
21
24
|
}
|
22
25
|
|
26
|
+
setXYWH(x: number, y: number, width: number, height: number): void {
|
27
|
+
this.ref[0] = x;
|
28
|
+
this.ref[1] = y;
|
29
|
+
this.ref[2] = x + width;
|
30
|
+
this.ref[3] = y + height;
|
31
|
+
}
|
32
|
+
|
23
33
|
get x() {
|
24
34
|
return this.ref[0];
|
25
35
|
}
|
@@ -7,7 +7,6 @@ import type { SkRSXform } from "../types/RSXform";
|
|
7
7
|
import { Host } from "./Host";
|
8
8
|
import { JsiSkFont } from "./JsiSkFont";
|
9
9
|
import { JsiSkTextBlob } from "./JsiSkTextBlob";
|
10
|
-
import type { RSXform } from "./JsiSkRSXform";
|
11
10
|
import { JsiSkRSXform } from "./JsiSkRSXform";
|
12
11
|
|
13
12
|
export class JsiSkTextBlobFactory extends Host implements TextBlobFactory {
|
@@ -34,20 +33,21 @@ export class JsiSkTextBlobFactory extends Host implements TextBlobFactory {
|
|
34
33
|
this.CanvasKit,
|
35
34
|
this.CanvasKit.TextBlob.MakeFromRSXform(
|
36
35
|
str,
|
37
|
-
rsxforms
|
38
|
-
.map((f) => Array.from(JsiSkRSXform.fromValue<RSXform>(f)))
|
39
|
-
.flat(),
|
36
|
+
rsxforms.map((f) => Array.from(JsiSkRSXform.fromValue(f))).flat(),
|
40
37
|
JsiSkFont.fromValue(font)
|
41
38
|
)
|
42
39
|
);
|
43
40
|
}
|
44
41
|
|
45
42
|
MakeFromRSXformGlyphs(glyphs: number[], rsxforms: SkRSXform[], font: SkFont) {
|
43
|
+
const transforms = rsxforms.flatMap((s) =>
|
44
|
+
Array.from(JsiSkRSXform.fromValue(s))
|
45
|
+
);
|
46
46
|
return new JsiSkTextBlob(
|
47
47
|
this.CanvasKit,
|
48
48
|
this.CanvasKit.TextBlob.MakeFromRSXformGlyphs(
|
49
49
|
glyphs,
|
50
|
-
|
50
|
+
transforms,
|
51
51
|
JsiSkFont.fromValue(font)
|
52
52
|
)
|
53
53
|
);
|
package/src/skia/web/JsiSkia.ts
CHANGED
@@ -52,6 +52,21 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
52
52
|
new JsiSkRRect(CanvasKit, rect, rx, ry),
|
53
53
|
RSXform: (scos: number, ssin: number, tx: number, ty: number) =>
|
54
54
|
new JsiSkRSXform(CanvasKit, Float32Array.of(scos, ssin, tx, ty)),
|
55
|
+
RSXformFromRadians: (
|
56
|
+
scale: number,
|
57
|
+
r: number,
|
58
|
+
tx: number,
|
59
|
+
ty: number,
|
60
|
+
px: number,
|
61
|
+
py: number
|
62
|
+
) => {
|
63
|
+
const s = Math.sin(r) * scale;
|
64
|
+
const c = Math.cos(r) * scale;
|
65
|
+
return new JsiSkRSXform(
|
66
|
+
CanvasKit,
|
67
|
+
Float32Array.of(c, s, tx - c * px + s * py, ty - s * px - c * py)
|
68
|
+
);
|
69
|
+
},
|
55
70
|
Color,
|
56
71
|
ContourMeasureIter: (
|
57
72
|
path: SkPath,
|