@shopify/react-native-skia 0.1.116 → 0.1.120
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkApi.h +13 -9
- package/cpp/api/JsiSkCanvas.h +9 -1
- package/cpp/api/JsiSkPicture.h +71 -0
- package/cpp/api/JsiSkPictureFactory.h +50 -0
- package/cpp/api/JsiSkPictureRecorder.h +53 -0
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +3 -6
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +2 -4
- package/ios/RNSkia-iOS/SkiaDrawView.mm +3 -2
- package/lib/commonjs/renderer/Canvas.js +22 -36
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/HostConfig.js +3 -25
- package/lib/commonjs/renderer/HostConfig.js.map +1 -1
- package/lib/commonjs/renderer/components/{Defs.js → Drawing.js} +13 -12
- package/lib/commonjs/renderer/components/Drawing.js.map +1 -0
- package/lib/commonjs/renderer/components/Group.js +7 -4
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +1 -21
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/renderer/components/Picture.js +35 -0
- package/lib/commonjs/renderer/components/Picture.js.map +1 -0
- package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js +5 -34
- package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js.map +1 -1
- package/lib/commonjs/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +19 -8
- package/lib/commonjs/renderer/components/imageFilters/Shadow.js.map +1 -0
- package/lib/commonjs/renderer/components/imageFilters/index.js +4 -17
- package/lib/commonjs/renderer/components/imageFilters/index.js.map +1 -1
- package/lib/commonjs/renderer/components/index.js +17 -4
- package/lib/commonjs/renderer/components/index.js.map +1 -1
- package/lib/commonjs/renderer/components/maskFilters/Blur.js +1 -1
- package/lib/commonjs/renderer/components/maskFilters/Blur.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/Box.js +126 -0
- package/lib/commonjs/renderer/components/shapes/Box.js.map +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/renderer/index.js +13 -0
- package/lib/commonjs/renderer/index.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Declaration.js +12 -1
- package/lib/commonjs/renderer/nodes/Declaration.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Drawing.js +9 -24
- package/lib/commonjs/renderer/nodes/Drawing.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Node.js +9 -16
- package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
- package/lib/commonjs/renderer/processors/Paint.js +24 -26
- package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
- package/lib/commonjs/renderer/processors/math/Math.js +19 -1
- package/lib/commonjs/renderer/processors/math/Math.js.map +1 -1
- package/lib/commonjs/renderer/processors/math/Matrix3.js +11 -5
- package/lib/commonjs/renderer/processors/math/Matrix3.js.map +1 -1
- package/lib/commonjs/renderer/typeddash.js +26 -2
- package/lib/commonjs/renderer/typeddash.js.map +1 -1
- package/lib/commonjs/renderer/useContextBridge.js +35 -0
- package/lib/commonjs/renderer/useContextBridge.js.map +1 -0
- package/lib/commonjs/skia/Canvas.js.map +1 -1
- package/lib/commonjs/skia/Picture/Picture.js +6 -0
- package/lib/commonjs/skia/Picture/Picture.js.map +1 -0
- package/lib/commonjs/skia/Picture/PictureFactory.js +6 -0
- package/lib/commonjs/skia/Picture/PictureFactory.js.map +1 -0
- package/lib/commonjs/skia/Picture/PictureRecorder.js +6 -0
- package/lib/commonjs/skia/Picture/PictureRecorder.js.map +1 -0
- package/lib/commonjs/skia/Picture/index.js +58 -0
- package/lib/commonjs/skia/Picture/index.js.map +1 -0
- package/lib/commonjs/skia/Picture/usePicture.js +30 -0
- package/lib/commonjs/skia/Picture/usePicture.js.map +1 -0
- package/lib/commonjs/skia/Skia.js +2 -0
- package/lib/commonjs/skia/Skia.js.map +1 -1
- package/lib/commonjs/skia/index.js +14 -0
- package/lib/commonjs/skia/index.js.map +1 -1
- package/lib/commonjs/values/hooks/useDerivedValue.js +2 -2
- package/lib/commonjs/values/hooks/useDerivedValue.js.map +1 -1
- package/lib/commonjs/views/SkiaView.js +6 -5
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.js +20 -32
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/HostConfig.js +2 -24
- package/lib/module/renderer/HostConfig.js.map +1 -1
- package/lib/module/renderer/components/Drawing.js +17 -0
- package/lib/module/renderer/components/Drawing.js.map +1 -0
- package/lib/module/renderer/components/Group.js +8 -6
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +2 -22
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/renderer/components/Picture.js +21 -0
- package/lib/module/renderer/components/Picture.js.map +1 -0
- package/lib/module/renderer/components/imageFilters/InnerShadow.js +4 -26
- package/lib/module/renderer/components/imageFilters/InnerShadow.js.map +1 -1
- package/lib/module/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +16 -6
- package/lib/module/renderer/components/imageFilters/Shadow.js.map +1 -0
- package/lib/module/renderer/components/imageFilters/index.js +1 -2
- package/lib/module/renderer/components/imageFilters/index.js.map +1 -1
- package/lib/module/renderer/components/index.js +2 -1
- package/lib/module/renderer/components/index.js.map +1 -1
- package/lib/module/renderer/components/maskFilters/Blur.js +1 -1
- package/lib/module/renderer/components/maskFilters/Blur.js.map +1 -1
- package/lib/module/renderer/components/shapes/Box.js +102 -0
- package/lib/module/renderer/components/shapes/Box.js.map +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/renderer/index.js +1 -0
- package/lib/module/renderer/index.js.map +1 -1
- package/lib/module/renderer/nodes/Declaration.js +4 -0
- package/lib/module/renderer/nodes/Declaration.js.map +1 -1
- package/lib/module/renderer/nodes/Drawing.js +8 -21
- package/lib/module/renderer/nodes/Drawing.js.map +1 -1
- package/lib/module/renderer/nodes/Node.js +9 -15
- package/lib/module/renderer/nodes/Node.js.map +1 -1
- package/lib/module/renderer/processors/Paint.js +22 -21
- package/lib/module/renderer/processors/Paint.js.map +1 -1
- package/lib/module/renderer/processors/math/Math.js +15 -0
- package/lib/module/renderer/processors/math/Math.js.map +1 -1
- package/lib/module/renderer/processors/math/Matrix3.js +6 -2
- package/lib/module/renderer/processors/math/Matrix3.js.map +1 -1
- package/lib/module/renderer/typeddash.js +21 -0
- package/lib/module/renderer/typeddash.js.map +1 -1
- package/lib/module/renderer/useContextBridge.js +21 -0
- package/lib/module/renderer/useContextBridge.js.map +1 -0
- package/lib/module/skia/Canvas.js.map +1 -1
- package/lib/module/skia/Picture/Picture.js +2 -0
- package/lib/module/skia/Picture/Picture.js.map +1 -0
- package/lib/module/skia/Picture/PictureFactory.js +2 -0
- package/lib/module/skia/Picture/PictureFactory.js.map +1 -0
- package/lib/module/skia/Picture/PictureRecorder.js +2 -0
- package/lib/module/skia/Picture/PictureRecorder.js.map +1 -0
- package/lib/module/skia/Picture/index.js +5 -0
- package/lib/module/skia/Picture/index.js.map +1 -0
- package/lib/module/skia/Picture/usePicture.js +19 -0
- package/lib/module/skia/Picture/usePicture.js.map +1 -0
- package/lib/module/skia/Skia.js +2 -0
- package/lib/module/skia/Skia.js.map +1 -1
- package/lib/module/skia/index.js +1 -0
- package/lib/module/skia/index.js.map +1 -1
- package/lib/module/values/hooks/useDerivedValue.js +1 -1
- package/lib/module/values/hooks/useDerivedValue.js.map +1 -1
- package/lib/module/views/SkiaView.js +6 -5
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +5 -10
- package/lib/typescript/src/renderer/components/Drawing.d.ts +7 -0
- package/lib/typescript/src/renderer/components/Picture.d.ts +6 -0
- package/lib/typescript/src/renderer/components/imageFilters/InnerShadow.d.ts +3 -12
- package/lib/typescript/src/renderer/components/imageFilters/{DropShadow.d.ts → Shadow.d.ts} +3 -2
- package/lib/typescript/src/renderer/components/imageFilters/index.d.ts +1 -2
- package/lib/typescript/src/renderer/components/index.d.ts +2 -1
- package/lib/typescript/src/renderer/components/shapes/Box.d.ts +23 -0
- package/lib/typescript/src/renderer/components/shapes/index.d.ts +1 -0
- package/lib/typescript/src/renderer/index.d.ts +1 -0
- package/lib/typescript/src/renderer/nodes/Declaration.d.ts +3 -0
- package/lib/typescript/src/renderer/nodes/Drawing.d.ts +2 -2
- package/lib/typescript/src/renderer/nodes/Node.d.ts +2 -2
- package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -2
- package/lib/typescript/src/renderer/processors/math/Math.d.ts +14 -0
- package/lib/typescript/src/renderer/processors/math/Matrix3.d.ts +1 -0
- package/lib/typescript/src/renderer/typeddash.d.ts +1 -0
- package/lib/typescript/src/renderer/useContextBridge.d.ts +5 -0
- package/lib/typescript/src/skia/Canvas.d.ts +6 -0
- package/lib/typescript/src/skia/Picture/Picture.d.ts +26 -0
- package/lib/typescript/src/skia/Picture/PictureFactory.d.ts +8 -0
- package/lib/typescript/src/skia/Picture/PictureRecorder.d.ts +15 -0
- package/lib/typescript/src/skia/Picture/index.d.ts +4 -0
- package/lib/typescript/src/skia/Picture/usePicture.d.ts +11 -0
- package/lib/typescript/src/skia/Skia.d.ts +5 -0
- package/lib/typescript/src/skia/index.d.ts +1 -0
- package/lib/typescript/src/views/SkiaView.d.ts +25 -1
- package/lib/typescript/src/views/types.d.ts +0 -24
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +14 -30
- package/src/renderer/HostConfig.ts +2 -20
- package/src/renderer/components/Drawing.tsx +16 -0
- package/src/renderer/components/Group.tsx +25 -15
- package/src/renderer/components/Paint.tsx +5 -35
- package/src/renderer/components/Picture.tsx +17 -0
- package/src/renderer/components/imageFilters/InnerShadow.tsx +33 -47
- package/src/renderer/components/imageFilters/Shadow.tsx +39 -0
- package/src/renderer/components/imageFilters/index.ts +1 -2
- package/src/renderer/components/index.ts +2 -1
- package/src/renderer/components/maskFilters/Blur.tsx +1 -1
- package/src/renderer/components/shapes/Box.tsx +98 -0
- package/src/renderer/components/shapes/index.ts +1 -0
- package/src/renderer/index.ts +1 -0
- package/src/renderer/nodes/Declaration.tsx +14 -0
- package/src/renderer/nodes/Drawing.tsx +16 -26
- package/src/renderer/nodes/Node.ts +9 -12
- package/src/renderer/processors/Paint.ts +34 -31
- package/src/renderer/processors/math/Math.ts +16 -0
- package/src/renderer/processors/math/Matrix3.ts +35 -31
- package/src/renderer/typeddash.ts +18 -0
- package/src/renderer/useContextBridge.tsx +21 -0
- package/src/skia/Canvas.ts +7 -0
- package/src/skia/Picture/Picture.ts +34 -0
- package/src/skia/Picture/PictureFactory.ts +9 -0
- package/src/skia/Picture/PictureRecorder.ts +18 -0
- package/src/skia/Picture/index.ts +4 -0
- package/src/skia/Picture/usePicture.ts +28 -0
- package/src/skia/Skia.ts +5 -0
- package/src/skia/index.ts +1 -0
- package/src/values/hooks/useDerivedValue.ts +1 -1
- package/src/views/SkiaView.tsx +27 -3
- package/src/views/types.ts +0 -25
- package/lib/commonjs/renderer/components/Defs.js.map +0 -1
- package/lib/commonjs/renderer/components/imageFilters/DropShadow.js.map +0 -1
- package/lib/module/renderer/components/Defs.js +0 -16
- package/lib/module/renderer/components/Defs.js.map +0 -1
- package/lib/module/renderer/components/imageFilters/DropShadow.js.map +0 -1
- package/lib/typescript/src/renderer/components/Defs.d.ts +0 -5
- package/src/renderer/components/Defs.tsx +0 -19
- package/src/renderer/components/imageFilters/DropShadow.tsx +0 -31
@@ -1,8 +1,8 @@
|
|
1
|
-
import type { ReactNode } from "react";
|
2
|
-
import
|
1
|
+
import type { DependencyList, ReactNode } from "react";
|
2
|
+
import { useCallback } from "react";
|
3
3
|
|
4
4
|
import type { DrawingContext } from "../DrawingContext";
|
5
|
-
import { processPaint
|
5
|
+
import { processPaint } from "../processors";
|
6
6
|
import type { AnimatedProps } from "../processors/Animations/Animations";
|
7
7
|
import { materialize } from "../processors/Animations/Animations";
|
8
8
|
import { isPaint } from "../../skia";
|
@@ -21,16 +21,16 @@ type OnDrawCallback<P> = (ctx: DrawingContext, props: P, node: Node<P>) => void;
|
|
21
21
|
export const createDrawing = <P,>(cb: OnDrawCallback<P>): DrawingCallback<P> =>
|
22
22
|
cb;
|
23
23
|
|
24
|
+
export const useDrawing = <P,>(cb: OnDrawCallback<P>, deps?: DependencyList) =>
|
25
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
26
|
+
useCallback(cb, deps ?? []);
|
27
|
+
|
24
28
|
export type DrawingProps<T> = {
|
25
29
|
onDraw: DrawingCallback<T>;
|
26
30
|
skipProcessing?: boolean;
|
27
31
|
children?: ReactNode | ReactNode[];
|
28
32
|
};
|
29
33
|
|
30
|
-
export const Drawing = <P,>(props: DrawingProps<P>) => {
|
31
|
-
return <skDrawing {...props} />;
|
32
|
-
};
|
33
|
-
|
34
34
|
export class DrawingNode<P> extends Node<P> {
|
35
35
|
onDraw: DrawingCallback<P>;
|
36
36
|
skipProcessing: boolean;
|
@@ -51,25 +51,15 @@ export class DrawingNode<P> extends Node<P> {
|
|
51
51
|
if (this.skipProcessing) {
|
52
52
|
this.onDraw(ctx, drawingProps, this);
|
53
53
|
} else {
|
54
|
-
const
|
55
|
-
processPaint(
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
const ret = child.draw(ctx);
|
64
|
-
if (ret) {
|
65
|
-
return ret;
|
66
|
-
}
|
67
|
-
//}
|
68
|
-
return null;
|
69
|
-
})
|
70
|
-
.filter(isPaint),
|
71
|
-
].forEach((paint) => {
|
72
|
-
this.onDraw({ ...ctx, paint }, drawingProps, this);
|
54
|
+
const declarations = this.visit(ctx);
|
55
|
+
const paint = processPaint(
|
56
|
+
ctx.paint.copy(),
|
57
|
+
ctx.opacity,
|
58
|
+
drawingProps,
|
59
|
+
declarations
|
60
|
+
);
|
61
|
+
[paint, ...declarations.filter(isPaint)].forEach((currentPaint) => {
|
62
|
+
this.onDraw({ ...ctx, paint: currentPaint }, drawingProps, this);
|
73
63
|
});
|
74
64
|
}
|
75
65
|
}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { isPaint } from "../../skia";
|
2
1
|
import type { SkJSIInstance } from "../../skia/JsiInstance";
|
3
2
|
import type { DependencyManager } from "../DependencyManager";
|
4
3
|
import type { DrawingContext } from "../DrawingContext";
|
@@ -15,7 +14,7 @@ export abstract class Node<P = unknown> {
|
|
15
14
|
readonly children: Node[] = [];
|
16
15
|
_props: AnimatedProps<P>;
|
17
16
|
memoizable = false;
|
18
|
-
memoized =
|
17
|
+
memoized: DeclarationResult | null = null;
|
19
18
|
parent?: Node;
|
20
19
|
depMgr: DependencyManager;
|
21
20
|
|
@@ -38,21 +37,19 @@ export abstract class Node<P = unknown> {
|
|
38
37
|
return this._props;
|
39
38
|
}
|
40
39
|
|
41
|
-
visit(ctx: DrawingContext) {
|
40
|
+
visit(ctx: DrawingContext, children?: Node[]) {
|
42
41
|
const returnedValues: Exclude<DeclarationResult, null>[] = [];
|
43
|
-
|
44
|
-
this.children.forEach((child) => {
|
42
|
+
(children ?? this.children).forEach((child) => {
|
45
43
|
if (!child.memoized) {
|
46
|
-
const ret = child.draw(
|
44
|
+
const ret = child.draw(ctx);
|
47
45
|
if (ret) {
|
48
|
-
if (isPaint(ret)) {
|
49
|
-
currentCtx = { ...currentCtx, paint: ret };
|
50
|
-
}
|
51
46
|
returnedValues.push(ret);
|
47
|
+
if (child.memoizable) {
|
48
|
+
child.memoized = ret;
|
49
|
+
}
|
52
50
|
}
|
53
|
-
|
54
|
-
|
55
|
-
}
|
51
|
+
} else {
|
52
|
+
returnedValues.push(child.memoized);
|
56
53
|
}
|
57
54
|
});
|
58
55
|
return returnedValues;
|
@@ -6,14 +6,22 @@ import {
|
|
6
6
|
StrokeJoin,
|
7
7
|
StrokeCap,
|
8
8
|
processColor,
|
9
|
+
isShader,
|
10
|
+
isMaskFilter,
|
11
|
+
isColorFilter,
|
12
|
+
isPathEffect,
|
13
|
+
isImageFilter,
|
14
|
+
Skia,
|
9
15
|
} from "../../skia";
|
10
|
-
import type { SkPaint, Color } from "../../skia";
|
16
|
+
import type { SkPaint, Color, SkImageFilter } from "../../skia";
|
17
|
+
import type { DeclarationResult } from "../nodes";
|
11
18
|
export type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;
|
12
19
|
|
13
20
|
export interface ChildrenProps {
|
14
21
|
children?: ReactNode | ReactNode[];
|
15
22
|
}
|
16
23
|
|
24
|
+
// TODO: rename to paint props?
|
17
25
|
export interface CustomPaintProps extends ChildrenProps {
|
18
26
|
paint?: RefObject<SkPaint>;
|
19
27
|
color?: Color;
|
@@ -33,6 +41,7 @@ export const processPaint = (
|
|
33
41
|
paint: SkPaint,
|
34
42
|
currentOpacity: number,
|
35
43
|
{
|
44
|
+
paint: paintRef,
|
36
45
|
color,
|
37
46
|
blendMode,
|
38
47
|
style,
|
@@ -41,8 +50,12 @@ export const processPaint = (
|
|
41
50
|
strokeCap,
|
42
51
|
strokeMiter,
|
43
52
|
opacity,
|
44
|
-
}: CustomPaintProps
|
53
|
+
}: CustomPaintProps,
|
54
|
+
children: DeclarationResult[]
|
45
55
|
) => {
|
56
|
+
if (paintRef && paintRef.current) {
|
57
|
+
return paintRef.current;
|
58
|
+
}
|
46
59
|
if (color !== undefined) {
|
47
60
|
const c = processColor(color, currentOpacity);
|
48
61
|
paint.setShader(null);
|
@@ -72,34 +85,24 @@ export const processPaint = (
|
|
72
85
|
if (opacity !== undefined) {
|
73
86
|
paint.setAlphaf(opacity);
|
74
87
|
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
)
|
91
|
-
|
92
|
-
|
93
|
-
blendMode !== undefined ||
|
94
|
-
paintStyle !== undefined ||
|
95
|
-
strokeWidth !== undefined ||
|
96
|
-
strokeJoin !== undefined ||
|
97
|
-
opacity !== undefined ||
|
98
|
-
strokeCap !== undefined ||
|
99
|
-
strokeMiter !== undefined;
|
100
|
-
const parentPaint = paint?.current ?? currentPaint;
|
101
|
-
if (hasCustomPaint) {
|
102
|
-
return parentPaint.copy();
|
88
|
+
children.forEach((child) => {
|
89
|
+
if (isShader(child)) {
|
90
|
+
paint.setShader(child);
|
91
|
+
} else if (isMaskFilter(child)) {
|
92
|
+
paint.setMaskFilter(child);
|
93
|
+
} else if (isColorFilter(child)) {
|
94
|
+
paint.setColorFilter(child);
|
95
|
+
} else if (isPathEffect(child)) {
|
96
|
+
paint.setPathEffect(child);
|
97
|
+
}
|
98
|
+
});
|
99
|
+
const filters = children.filter(isImageFilter);
|
100
|
+
if (filters.length > 0) {
|
101
|
+
paint.setImageFilter(
|
102
|
+
filters
|
103
|
+
.reverse()
|
104
|
+
.reduce<SkImageFilter | null>(Skia.ImageFilter.MakeCompose, null)
|
105
|
+
);
|
103
106
|
}
|
104
|
-
return
|
107
|
+
return paint;
|
105
108
|
};
|
@@ -1,2 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* Linear interpolation
|
3
|
+
* @param value
|
4
|
+
* @param x
|
5
|
+
* @param y
|
6
|
+
*/
|
1
7
|
export const mix = (value: number, x: number, y: number) =>
|
2
8
|
x * (1 - value) + y * value;
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @summary Clamps a node with a lower and upper bound.
|
12
|
+
* @example
|
13
|
+
clamp(-1, 0, 100); // 0
|
14
|
+
clamp(1, 0, 100); // 1
|
15
|
+
clamp(101, 0, 100); // 100
|
16
|
+
*/
|
17
|
+
export const clamp = (value: number, lowerBound: number, upperBound: number) =>
|
18
|
+
Math.min(Math.max(lowerBound, value), upperBound);
|
@@ -102,6 +102,9 @@ const multiply3 = (m1: Matrix3, m2: Matrix3) => {
|
|
102
102
|
] as const;
|
103
103
|
};
|
104
104
|
|
105
|
+
export const matrixVecMul3 = (m: Matrix3, v: Vec3) =>
|
106
|
+
[dot3(m[0], v), dot3(m[1], v), dot3(m[2], v)] as const;
|
107
|
+
|
105
108
|
const skiaMatrix3 = (m: Matrix3): SkMatrix => {
|
106
109
|
return [
|
107
110
|
m[0][0],
|
@@ -117,34 +120,35 @@ const skiaMatrix3 = (m: Matrix3): SkMatrix => {
|
|
117
120
|
};
|
118
121
|
|
119
122
|
export const processTransform2d = (transforms: Transforms2d) =>
|
120
|
-
skiaMatrix3(
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
return
|
149
|
-
}
|
150
|
-
|
123
|
+
skiaMatrix3(processTransform(transforms));
|
124
|
+
|
125
|
+
const processTransform = (transforms: Transforms2d) =>
|
126
|
+
transforms.reduce((acc, transform) => {
|
127
|
+
const key = Object.keys(transform)[0] as Transform2dName;
|
128
|
+
const value = (transform as Pick<Transformations, typeof key>)[key];
|
129
|
+
if (key === "translateX") {
|
130
|
+
return multiply3(acc, translateXMatrix(value));
|
131
|
+
}
|
132
|
+
if (key === "translateY") {
|
133
|
+
return multiply3(acc, translateYMatrix(value));
|
134
|
+
}
|
135
|
+
if (key === "scale") {
|
136
|
+
return multiply3(acc, scaleMatrix(value));
|
137
|
+
}
|
138
|
+
if (key === "scaleX") {
|
139
|
+
return multiply3(acc, scaleXMatrix(value));
|
140
|
+
}
|
141
|
+
if (key === "scaleY") {
|
142
|
+
return multiply3(acc, scaleYMatrix(value));
|
143
|
+
}
|
144
|
+
if (key === "skewX") {
|
145
|
+
return multiply3(acc, skewXMatrix(value));
|
146
|
+
}
|
147
|
+
if (key === "skewY") {
|
148
|
+
return multiply3(acc, skewYMatrix(value));
|
149
|
+
}
|
150
|
+
if (key === "rotate" || key === "rotateZ") {
|
151
|
+
return multiply3(acc, rotateZMatrix(value));
|
152
|
+
}
|
153
|
+
return exhaustiveCheck(key);
|
154
|
+
}, identityMatrix);
|
@@ -3,3 +3,21 @@ export const mapKeys = <T>(obj: T) => Object.keys(obj) as (keyof T)[];
|
|
3
3
|
export const exhaustiveCheck = (a: never): never => {
|
4
4
|
throw new Error(`Unexhaustive handling for ${a}`);
|
5
5
|
};
|
6
|
+
|
7
|
+
// Shallow eq on props (without children)
|
8
|
+
export const shallowEq = <P>(p1: P, p2: P): boolean => {
|
9
|
+
const keys1 = mapKeys(p1);
|
10
|
+
const keys2 = mapKeys(p2);
|
11
|
+
if (keys1.length !== keys2.length) {
|
12
|
+
return false;
|
13
|
+
}
|
14
|
+
for (const key of keys1) {
|
15
|
+
if (key === "children") {
|
16
|
+
continue;
|
17
|
+
}
|
18
|
+
if (p1[key] !== p2[key]) {
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
return true;
|
23
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import React, { useMemo, useContext } from "react";
|
2
|
+
import type { ReactNode, Context, ReactElement } from "react";
|
3
|
+
|
4
|
+
// useContextBridge() is taken from https://github.com/pmndrs/drei#usecontextbridge
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
6
|
+
export const useContextBridge = (...contexts: Context<any>[]) => {
|
7
|
+
const values =
|
8
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
9
|
+
contexts.map((context) => useContext(context));
|
10
|
+
return useMemo(
|
11
|
+
() =>
|
12
|
+
({ children }: { children: ReactNode }) =>
|
13
|
+
contexts.reduceRight(
|
14
|
+
(acc, Context, i) => (
|
15
|
+
<Context.Provider value={values[i]} children={acc} />
|
16
|
+
),
|
17
|
+
children
|
18
|
+
) as ReactElement,
|
19
|
+
[contexts, values]
|
20
|
+
);
|
21
|
+
};
|
package/src/skia/Canvas.ts
CHANGED
@@ -12,6 +12,7 @@ import type { SkMatrix } from "./Matrix";
|
|
12
12
|
import type { SkImageFilter } from "./ImageFilter";
|
13
13
|
import type { SkVertices } from "./Vertices";
|
14
14
|
import type { SkTextBlob } from "./TextBlob";
|
15
|
+
import type { SkPicture } from "./Picture";
|
15
16
|
|
16
17
|
export enum ClipOp {
|
17
18
|
Difference,
|
@@ -485,4 +486,10 @@ export interface SkCanvas {
|
|
485
486
|
* @param m
|
486
487
|
*/
|
487
488
|
concat(m: SkMatrix): void;
|
489
|
+
|
490
|
+
/**
|
491
|
+
* Draws the given picture using the current clip, current matrix, and the provided paint.
|
492
|
+
* @param skp
|
493
|
+
*/
|
494
|
+
drawPicture(skp: SkPicture): void;
|
488
495
|
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { InputColorMatrix } from "../ColorFilter";
|
2
|
+
import type { FilterMode } from "../Image";
|
3
|
+
import type { TileMode } from "../ImageFilter";
|
4
|
+
import type { SkRect } from "../Rect";
|
5
|
+
import type { IShader } from "../Shader";
|
6
|
+
|
7
|
+
export interface SkPicture {
|
8
|
+
/**
|
9
|
+
* Returns a new shader that will draw with this picture.
|
10
|
+
*
|
11
|
+
* @param tmx The tiling mode to use when sampling in the x-direction.
|
12
|
+
* @param tmy The tiling mode to use when sampling in the y-direction.
|
13
|
+
* @param mode How to filter the tiles
|
14
|
+
* @param localMatrix Optional matrix used when sampling
|
15
|
+
* @param tileRect The tile rectangle in picture coordinates: this represents the subset
|
16
|
+
* (or superset) of the picture used when building a tile. It is not
|
17
|
+
* affected by localMatrix and does not imply scaling (only translation
|
18
|
+
* and cropping). If null, the tile rect is considered equal to the picture
|
19
|
+
* bounds.
|
20
|
+
*/
|
21
|
+
makeShader(
|
22
|
+
tmx: TileMode,
|
23
|
+
tmy: TileMode,
|
24
|
+
mode: FilterMode,
|
25
|
+
localMatrix?: InputColorMatrix,
|
26
|
+
tileRect?: SkRect
|
27
|
+
): IShader;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Returns the serialized format of this SkPicture. The format may change at anytime and
|
31
|
+
* no promises are made for backwards or forward compatibility.
|
32
|
+
*/
|
33
|
+
serialize(): Uint8Array | null;
|
34
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { SkCanvas } from "../Canvas";
|
2
|
+
import type { SkRect } from "../Rect";
|
3
|
+
|
4
|
+
import type { SkPicture } from "./Picture";
|
5
|
+
|
6
|
+
export interface SkPictureRecorder {
|
7
|
+
/**
|
8
|
+
* Returns a canvas on which to draw. When done drawing, call finishRecordingAsPicture()
|
9
|
+
*
|
10
|
+
* @param bounds - a rect to cull the results.
|
11
|
+
*/
|
12
|
+
beginRecording(bounds: SkRect): SkCanvas;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Returns the captured draw commands as a picture and invalidates the canvas returned earlier.
|
16
|
+
*/
|
17
|
+
finishRecordingAsPicture(): SkPicture;
|
18
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import type { DependencyList } from "react";
|
2
|
+
import { useMemo } from "react";
|
3
|
+
|
4
|
+
import type { SkCanvas } from "../Canvas";
|
5
|
+
import type { SkRect } from "../Rect";
|
6
|
+
import { Skia } from "../Skia";
|
7
|
+
|
8
|
+
import type { SkPicture } from "./Picture";
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Memoizes and returns an SkPicture that can be drawn to another canvas.
|
12
|
+
* @param rect Picture bounds
|
13
|
+
* @param cb Callback for drawing to the canvas
|
14
|
+
* @returns SkPicture
|
15
|
+
*/
|
16
|
+
export const usePicture = (
|
17
|
+
rect: SkRect,
|
18
|
+
cb: (canvas: SkCanvas) => void,
|
19
|
+
deps: DependencyList = []
|
20
|
+
): SkPicture => {
|
21
|
+
return useMemo(() => {
|
22
|
+
const recorder = Skia.PictureRecorder();
|
23
|
+
const canvas = recorder.beginRecording(rect);
|
24
|
+
cb(canvas);
|
25
|
+
return recorder.finishRecordingAsPicture();
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
27
|
+
}, [cb, rect, deps]);
|
28
|
+
};
|
package/src/skia/Skia.ts
CHANGED
@@ -26,6 +26,7 @@ import "./NativeSetup";
|
|
26
26
|
import type { SkRSXform } from "./RSXform";
|
27
27
|
import type { SkPath } from "./Path/Path";
|
28
28
|
import type { SkContourMeasureIter } from "./ContourMeasure";
|
29
|
+
import type { PictureFactory, SkPictureRecorder } from "./Picture";
|
29
30
|
|
30
31
|
/**
|
31
32
|
* Declares the interface for the native Skia API
|
@@ -41,6 +42,8 @@ export interface Skia {
|
|
41
42
|
resScale: number
|
42
43
|
) => SkContourMeasureIter;
|
43
44
|
Paint: () => SkPaint;
|
45
|
+
PictureRecorder: () => SkPictureRecorder;
|
46
|
+
Picture: PictureFactory;
|
44
47
|
Path: PathFactory;
|
45
48
|
Matrix: () => SkMatrix;
|
46
49
|
ColorFilter: ColorFilterFactory;
|
@@ -106,6 +109,8 @@ export const Skia = {
|
|
106
109
|
XYWHRect: SkiaApi.XYWHRect,
|
107
110
|
RRectXY: SkiaApi.RRectXY,
|
108
111
|
Paint: SkiaApi.Paint,
|
112
|
+
PictureRecorder: SkiaApi.PictureRecorder,
|
113
|
+
Picture: SkiaApi.Picture,
|
109
114
|
Path: SkiaApi.Path,
|
110
115
|
ColorFilter: SkiaApi.ColorFilter,
|
111
116
|
ContourMeasureIter: SkiaApi.ContourMeasureIter,
|
package/src/skia/index.ts
CHANGED
package/src/views/SkiaView.tsx
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import React from "react";
|
2
|
+
import type { ViewProps } from "react-native";
|
2
3
|
import { requireNativeComponent } from "react-native";
|
3
4
|
|
4
5
|
import type { SkImage, SkRect } from "../skia";
|
@@ -6,7 +7,6 @@ import type { SkiaReadonlyValue } from "../values";
|
|
6
7
|
|
7
8
|
import type {
|
8
9
|
DrawMode,
|
9
|
-
SkiaViewProps,
|
10
10
|
RNSkiaDrawCallback,
|
11
11
|
NativeSkiaViewProps,
|
12
12
|
} from "./types";
|
@@ -35,6 +35,30 @@ declare global {
|
|
35
35
|
|
36
36
|
const { SkiaViewApi } = global;
|
37
37
|
|
38
|
+
export interface SkiaViewProps extends ViewProps {
|
39
|
+
/**
|
40
|
+
* Sets the drawing mode for the skia view. There are two drawing
|
41
|
+
* modes, "continuous" and "default", where the continuous mode will
|
42
|
+
* continuously redraw the view, and the default mode will only
|
43
|
+
* redraw when any of the regular react properties are changed like
|
44
|
+
* sizes and margins.
|
45
|
+
*/
|
46
|
+
mode?: DrawMode;
|
47
|
+
/**
|
48
|
+
* When set to true the view will display information about the
|
49
|
+
* average time it takes to render.
|
50
|
+
*/
|
51
|
+
debug?: boolean;
|
52
|
+
/**
|
53
|
+
* Draw callback. Will be called whenever the view is invalidated and
|
54
|
+
* needs to redraw. This is either caused by a change in a react
|
55
|
+
* property, a touch event, or a call to redraw. If the view is in
|
56
|
+
* continuous mode the callback will be called 60 frames per second
|
57
|
+
* by the native view.
|
58
|
+
*/
|
59
|
+
onDraw?: RNSkiaDrawCallback;
|
60
|
+
}
|
61
|
+
|
38
62
|
export class SkiaView extends React.Component<SkiaViewProps> {
|
39
63
|
constructor(props: SkiaViewProps) {
|
40
64
|
super(props);
|
@@ -103,14 +127,14 @@ export class SkiaView extends React.Component<SkiaViewProps> {
|
|
103
127
|
}
|
104
128
|
|
105
129
|
render() {
|
106
|
-
const {
|
130
|
+
const { mode, debug = false, ...viewProps } = this.props;
|
107
131
|
return (
|
108
132
|
<NativeSkiaView
|
109
|
-
style={style}
|
110
133
|
collapsable={false}
|
111
134
|
nativeID={`${this._nativeId}`}
|
112
135
|
mode={mode}
|
113
136
|
debug={debug}
|
137
|
+
{...viewProps}
|
114
138
|
/>
|
115
139
|
);
|
116
140
|
}
|
package/src/views/types.ts
CHANGED
@@ -47,31 +47,6 @@ export type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;
|
|
47
47
|
|
48
48
|
export type RNSkiaDrawCallback = (canvas: SkCanvas, info: DrawingInfo) => void;
|
49
49
|
|
50
|
-
export type SkiaViewProps = {
|
51
|
-
style?: ViewProps["style"];
|
52
|
-
/**
|
53
|
-
* Sets the drawing mode for the skia view. There are two drawing
|
54
|
-
* modes, "continuous" and "default", where the continuous mode will
|
55
|
-
* continuously redraw the view, and the default mode will only
|
56
|
-
* redraw when any of the regular react properties are changed like
|
57
|
-
* sizes and margins.
|
58
|
-
*/
|
59
|
-
mode?: DrawMode;
|
60
|
-
/**
|
61
|
-
* When set to true the view will display information about the
|
62
|
-
* average time it takes to render.
|
63
|
-
*/
|
64
|
-
debug?: boolean;
|
65
|
-
/**
|
66
|
-
* Draw callback. Will be called whenever the view is invalidated and
|
67
|
-
* needs to redraw. This is either caused by a change in a react
|
68
|
-
* property, a touch event, or a call to redraw. If the view is in
|
69
|
-
* continuous mode the callback will be called 60 frames per second
|
70
|
-
* by the native view.
|
71
|
-
*/
|
72
|
-
onDraw?: RNSkiaDrawCallback;
|
73
|
-
};
|
74
|
-
|
75
50
|
/**
|
76
51
|
* Listener interface for value changes
|
77
52
|
*/
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["Defs.tsx"],"names":["onDeclare","Defs","props"],"mappings":";;;;;;;AAAA;;AAGA;;;;;;AAMA,MAAMA,SAAS,GAAG,8BAAkB,MAAM;AACxC;AACA;AACA;AACA,SAAO,IAAP;AACD,CALiB,CAAlB;;AAOO,MAAMC,IAAI,GAAIC,KAAD,IAAsB;AACxC,sBAAO;AAAe,IAAA,SAAS,EAAEF;AAA1B,KAAyCE,KAAzC,EAAP;AACD,CAFM","sourcesContent":["import React from \"react\";\nimport type { ReactNode } from \"react\";\n\nimport { createDeclaration } from \"../nodes\";\n\nexport interface DefsProps {\n children: ReactNode | ReactNode[];\n}\n\nconst onDeclare = createDeclaration(() => {\n // Do nothing.\n // The goal of this component is to avoid declared paint from\n // being used in the drawing context automatically\n return null;\n});\n\nexport const Defs = (props: DefsProps) => {\n return <skDeclaration onDeclare={onDeclare} {...props} />;\n};\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["DropShadow.tsx"],"names":["onDeclare","children","dx","dy","blur","color","shadowOnly","opacity","input","factory","Skia","ImageFilter","MakeDropShadowOnly","MakeDropShadow","DropShadow","props"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAGA;;AAEA;;;;;;AAUA,MAAMA,SAAS,GAAG,oCAChB,OAAsCC,QAAtC,YAAgE;AAAA,MAA/D;AAAEC,IAAAA,EAAF;AAAMC,IAAAA,EAAN;AAAUC,IAAAA,IAAV;AAAgBC,IAAAA,KAAhB;AAAuBC,IAAAA;AAAvB,GAA+D;AAAA,MAAhB;AAAEC,IAAAA;AAAF,GAAgB;AAC9D,QAAMC,KAAK,GAAG,wBAASP,QAAT,CAAd;AACA,QAAMQ,OAAO,GAAGH,UAAU,GACtBI,WAAKC,WAAL,CAAiBC,kBADK,GAEtBF,WAAKC,WAAL,CAAiBE,cAFrB;AAGA,SAAOJ,OAAO,CAACP,EAAD,EAAKC,EAAL,EAASC,IAAT,EAAeA,IAAf,EAAqB,yBAAaC,KAAb,EAAoBE,OAApB,CAArB,EAAmDC,KAAnD,CAAd;AACD,CAPe,CAAlB;;AAUO,MAAMM,UAAU,GAAIC,KAAD,IAA2C;AACnE,sBAAO;AAAe,IAAA,SAAS,EAAEf;AAA1B,KAAyCe,KAAzC,EAAP;AACD,CAFM","sourcesContent":["import React from \"react\";\n\nimport { Skia } from \"../../../skia\";\nimport { createDeclaration } from \"../../nodes/Declaration\";\nimport type { AnimatedProps } from \"../../processors/Animations/Animations\";\nimport type { Color } from \"../../../skia/Color\";\nimport { processColor } from \"../../../skia/Color\";\n\nimport { getInput } from \"./getInput\";\n\nexport interface DropShadowProps {\n dx: number;\n dy: number;\n blur: number;\n color: Color;\n shadowOnly?: boolean;\n}\n\nconst onDeclare = createDeclaration<DropShadowProps>(\n ({ dx, dy, blur, color, shadowOnly }, children, { opacity }) => {\n const input = getInput(children);\n const factory = shadowOnly\n ? Skia.ImageFilter.MakeDropShadowOnly\n : Skia.ImageFilter.MakeDropShadow;\n return factory(dx, dy, blur, blur, processColor(color, opacity), input);\n }\n);\n\nexport const DropShadow = (props: AnimatedProps<DropShadowProps>) => {\n return <skDeclaration onDeclare={onDeclare} {...props} />;\n};\n"]}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2
|
-
|
3
|
-
import React from "react";
|
4
|
-
import { createDeclaration } from "../nodes";
|
5
|
-
const onDeclare = createDeclaration(() => {
|
6
|
-
// Do nothing.
|
7
|
-
// The goal of this component is to avoid declared paint from
|
8
|
-
// being used in the drawing context automatically
|
9
|
-
return null;
|
10
|
-
});
|
11
|
-
export const Defs = props => {
|
12
|
-
return /*#__PURE__*/React.createElement("skDeclaration", _extends({
|
13
|
-
onDeclare: onDeclare
|
14
|
-
}, props));
|
15
|
-
};
|
16
|
-
//# sourceMappingURL=Defs.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["Defs.tsx"],"names":["React","createDeclaration","onDeclare","Defs","props"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,iBAAT,QAAkC,UAAlC;AAMA,MAAMC,SAAS,GAAGD,iBAAiB,CAAC,MAAM;AACxC;AACA;AACA;AACA,SAAO,IAAP;AACD,CALkC,CAAnC;AAOA,OAAO,MAAME,IAAI,GAAIC,KAAD,IAAsB;AACxC,sBAAO;AAAe,IAAA,SAAS,EAAEF;AAA1B,KAAyCE,KAAzC,EAAP;AACD,CAFM","sourcesContent":["import React from \"react\";\nimport type { ReactNode } from \"react\";\n\nimport { createDeclaration } from \"../nodes\";\n\nexport interface DefsProps {\n children: ReactNode | ReactNode[];\n}\n\nconst onDeclare = createDeclaration(() => {\n // Do nothing.\n // The goal of this component is to avoid declared paint from\n // being used in the drawing context automatically\n return null;\n});\n\nexport const Defs = (props: DefsProps) => {\n return <skDeclaration onDeclare={onDeclare} {...props} />;\n};\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["DropShadow.tsx"],"names":["React","Skia","createDeclaration","processColor","getInput","onDeclare","children","dx","dy","blur","color","shadowOnly","opacity","input","factory","ImageFilter","MakeDropShadowOnly","MakeDropShadow","DropShadow","props"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,IAAT,QAAqB,eAArB;AACA,SAASC,iBAAT,QAAkC,yBAAlC;AAGA,SAASC,YAAT,QAA6B,qBAA7B;AAEA,SAASC,QAAT,QAAyB,YAAzB;AAUA,MAAMC,SAAS,GAAGH,iBAAiB,CACjC,OAAsCI,QAAtC,YAAgE;AAAA,MAA/D;AAAEC,IAAAA,EAAF;AAAMC,IAAAA,EAAN;AAAUC,IAAAA,IAAV;AAAgBC,IAAAA,KAAhB;AAAuBC,IAAAA;AAAvB,GAA+D;AAAA,MAAhB;AAAEC,IAAAA;AAAF,GAAgB;AAC9D,QAAMC,KAAK,GAAGT,QAAQ,CAACE,QAAD,CAAtB;AACA,QAAMQ,OAAO,GAAGH,UAAU,GACtBV,IAAI,CAACc,WAAL,CAAiBC,kBADK,GAEtBf,IAAI,CAACc,WAAL,CAAiBE,cAFrB;AAGA,SAAOH,OAAO,CAACP,EAAD,EAAKC,EAAL,EAASC,IAAT,EAAeA,IAAf,EAAqBN,YAAY,CAACO,KAAD,EAAQE,OAAR,CAAjC,EAAmDC,KAAnD,CAAd;AACD,CAPgC,CAAnC;AAUA,OAAO,MAAMK,UAAU,GAAIC,KAAD,IAA2C;AACnE,sBAAO;AAAe,IAAA,SAAS,EAAEd;AAA1B,KAAyCc,KAAzC,EAAP;AACD,CAFM","sourcesContent":["import React from \"react\";\n\nimport { Skia } from \"../../../skia\";\nimport { createDeclaration } from \"../../nodes/Declaration\";\nimport type { AnimatedProps } from \"../../processors/Animations/Animations\";\nimport type { Color } from \"../../../skia/Color\";\nimport { processColor } from \"../../../skia/Color\";\n\nimport { getInput } from \"./getInput\";\n\nexport interface DropShadowProps {\n dx: number;\n dy: number;\n blur: number;\n color: Color;\n shadowOnly?: boolean;\n}\n\nconst onDeclare = createDeclaration<DropShadowProps>(\n ({ dx, dy, blur, color, shadowOnly }, children, { opacity }) => {\n const input = getInput(children);\n const factory = shadowOnly\n ? Skia.ImageFilter.MakeDropShadowOnly\n : Skia.ImageFilter.MakeDropShadow;\n return factory(dx, dy, blur, blur, processColor(color, opacity), input);\n }\n);\n\nexport const DropShadow = (props: AnimatedProps<DropShadowProps>) => {\n return <skDeclaration onDeclare={onDeclare} {...props} />;\n};\n"]}
|