@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 +1 @@
|
|
1
|
-
{"version":3,"sources":["Declaration.tsx"],"names":["isAnimated","materialize","Node","createDeclaration","cb","DeclarationNode","constructor","depMgr","onDeclare","props","memoizable","_props","draw","ctx","children","visit","obj"],"mappings":";;
|
1
|
+
{"version":3,"sources":["Declaration.tsx"],"names":["useCallback","isAnimated","materialize","Node","createDeclaration","cb","useDeclaration","deps","isDeclarationNode","node","DeclarationNode","constructor","depMgr","onDeclare","props","memoizable","_props","draw","ctx","children","visit","obj"],"mappings":";;AACA,SAASA,WAAT,QAA4B,OAA5B;AAKA,SAASC,UAAT,EAAqBC,WAArB,QAAwC,eAAxC;AAGA,SAASC,IAAT,QAAqB,QAArB;AAUA,OAAO,MAAMC,iBAAiB,GAC5BC,EAD+B,IAEJA,EAFtB;AAIP,OAAO,MAAMC,cAAc,GAAG,CAC5BD,EAD4B,EAE5BE,IAF4B,KAI5B;AACAP,WAAW,CAACK,EAAD,EAAKE,IAAL,aAAKA,IAAL,cAAKA,IAAL,GAAa,EAAb,CALN;AAOP,OAAO,MAAMC,iBAAiB,GAC5BC,IAD+B,IAEMA,IAAI,YAAYC,eAFhD;AAQP,OAAO,MAAMA,eAAN,SAAiCP,IAAjC,CAAyC;AAG9CQ,EAAAA,WAAW,CACTC,MADS,EAETC,SAFS,EAGTC,KAHS,EAIT;AACA,UAAMF,MAAN,EAAcE,KAAd;;AADA;;AAEA,UAAMC,UAAN,GAAmB,CAACd,UAAU,CAACa,KAAD,CAA9B;AACA,SAAKD,SAAL,GAAiBA,SAAjB;AACD;;AAEQ,MAALC,KAAK,CAACA,KAAD,EAA0B;AACjC,SAAKC,UAAL,GAAkB,CAACd,UAAU,CAACa,KAAD,CAA7B;AACA,UAAMA,KAAN,GAAcA,KAAd;AACD;;AAEQ,MAALA,KAAK,GAAG;AACV,WAAO,KAAKE,MAAZ;AACD;;AAEDC,EAAAA,IAAI,CAACC,GAAD,EAAsB;AACxB,UAAMC,QAAQ,GAAG,KAAKC,KAAL,CAAWF,GAAX,CAAjB;AACA,UAAMJ,KAAK,GAAGZ,WAAW,CAAC,KAAKY,KAAN,CAAzB;AACA,UAAMO,GAAG,GAAG,KAAKR,SAAL,CAAeC,KAAf,EAAsBK,QAAtB,EAAgCD,GAAhC,CAAZ;AACA,WAAOG,GAAP;AACD;;AA3B6C","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback } from \"react\";\n\nimport type { DrawingContext } from \"../DrawingContext\";\nimport type { SkJSIInstance } from \"../../skia/JsiInstance\";\nimport type { AnimatedProps } from \"../processors\";\nimport { isAnimated, materialize } from \"../processors\";\nimport type { DependencyManager } from \"../DependencyManager\";\n\nimport { Node } from \"./Node\";\n\nexport type DeclarationResult = SkJSIInstance<string> | null;\n\ntype DeclarationCallback<T> = (\n props: T,\n children: DeclarationResult[],\n ctx: DrawingContext\n) => DeclarationResult;\n\nexport const createDeclaration = <T,>(\n cb: DeclarationCallback<T>\n): DeclarationCallback<T> => cb;\n\nexport const useDeclaration = <P,>(\n cb: DeclarationCallback<P>,\n deps?: DependencyList\n) =>\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useCallback(cb, deps ?? []);\n\nexport const isDeclarationNode = (\n node: Node\n): node is DeclarationNode<unknown> => node instanceof DeclarationNode;\n\nexport interface DeclarationProps<P> {\n onDeclare: DeclarationCallback<P>;\n}\n\nexport class DeclarationNode<P> extends Node<P> {\n private onDeclare: DeclarationCallback<P>;\n\n constructor(\n depMgr: DependencyManager,\n onDeclare: DeclarationCallback<P>,\n props: AnimatedProps<P>\n ) {\n super(depMgr, props);\n super.memoizable = !isAnimated(props);\n this.onDeclare = onDeclare;\n }\n\n set props(props: AnimatedProps<P>) {\n this.memoizable = !isAnimated(props);\n super.props = props;\n }\n\n get props() {\n return this._props;\n }\n\n draw(ctx: DrawingContext) {\n const children = this.visit(ctx);\n const props = materialize(this.props);\n const obj = this.onDeclare(props, children, ctx);\n return obj;\n }\n}\n"]}
|
@@ -1,14 +1,13 @@
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
2
2
|
|
3
|
-
import
|
4
|
-
import { processPaint
|
3
|
+
import { useCallback } from "react";
|
4
|
+
import { processPaint } from "../processors";
|
5
5
|
import { materialize } from "../processors/Animations/Animations";
|
6
6
|
import { isPaint } from "../../skia";
|
7
7
|
import { Node } from "./Node";
|
8
8
|
export const createDrawing = cb => cb;
|
9
|
-
export const
|
10
|
-
|
11
|
-
};
|
9
|
+
export const useDrawing = (cb, deps) => // eslint-disable-next-line react-hooks/exhaustive-deps
|
10
|
+
useCallback(cb, deps !== null && deps !== void 0 ? deps : []);
|
12
11
|
export class DrawingNode extends Node {
|
13
12
|
constructor(depMgr, onDraw, skipProcessing, props) {
|
14
13
|
super(depMgr, props);
|
@@ -27,23 +26,11 @@ export class DrawingNode extends Node {
|
|
27
26
|
if (this.skipProcessing) {
|
28
27
|
this.onDraw(ctx, drawingProps, this);
|
29
28
|
} else {
|
30
|
-
const
|
31
|
-
processPaint(
|
32
|
-
|
33
|
-
|
34
|
-
[selectedPaint, ...this.children.map(child => {
|
35
|
-
//if (child.type === NodeType.Declaration) {
|
36
|
-
const ret = child.draw(ctx);
|
37
|
-
|
38
|
-
if (ret) {
|
39
|
-
return ret;
|
40
|
-
} //}
|
41
|
-
|
42
|
-
|
43
|
-
return null;
|
44
|
-
}).filter(isPaint)].forEach(paint => {
|
29
|
+
const declarations = this.visit(ctx);
|
30
|
+
const paint = processPaint(ctx.paint.copy(), ctx.opacity, drawingProps, declarations);
|
31
|
+
[paint, ...declarations.filter(isPaint)].forEach(currentPaint => {
|
45
32
|
this.onDraw({ ...ctx,
|
46
|
-
paint
|
33
|
+
paint: currentPaint
|
47
34
|
}, drawingProps, this);
|
48
35
|
});
|
49
36
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Drawing.tsx"],"names":["
|
1
|
+
{"version":3,"sources":["Drawing.tsx"],"names":["useCallback","processPaint","materialize","isPaint","Node","createDrawing","cb","useDrawing","deps","DrawingNode","constructor","depMgr","onDraw","skipProcessing","props","draw","ctx","drawingProps","declarations","visit","paint","copy","opacity","filter","forEach","currentPaint"],"mappings":";;AACA,SAASA,WAAT,QAA4B,OAA5B;AAGA,SAASC,YAAT,QAA6B,eAA7B;AAEA,SAASC,WAAT,QAA4B,qCAA5B;AACA,SAASC,OAAT,QAAwB,YAAxB;AAGA,SAASC,IAAT,QAAqB,QAArB;AAUA,OAAO,MAAMC,aAAa,GAAQC,EAAL,IAC3BA,EADK;AAGP,OAAO,MAAMC,UAAU,GAAG,CAAKD,EAAL,EAA4BE,IAA5B,KACxB;AACAR,WAAW,CAACM,EAAD,EAAKE,IAAL,aAAKA,IAAL,cAAKA,IAAL,GAAa,EAAb,CAFN;AAUP,OAAO,MAAMC,WAAN,SAA6BL,IAA7B,CAAqC;AAI1CM,EAAAA,WAAW,CACTC,MADS,EAETC,MAFS,EAGTC,cAHS,EAITC,KAJS,EAKT;AACA,UAAMH,MAAN,EAAcG,KAAd;;AADA;;AAAA;;AAEA,SAAKF,MAAL,GAAcA,MAAd;AACA,SAAKC,cAAL,GAAsBA,cAAtB;AACD;;AAEDE,EAAAA,IAAI,CAACC,GAAD,EAAsB;AACxB,UAAMC,YAAY,GAAGf,WAAW,CAAC,KAAKY,KAAN,CAAhC;;AACA,QAAI,KAAKD,cAAT,EAAyB;AACvB,WAAKD,MAAL,CAAYI,GAAZ,EAAiBC,YAAjB,EAA+B,IAA/B;AACD,KAFD,MAEO;AACL,YAAMC,YAAY,GAAG,KAAKC,KAAL,CAAWH,GAAX,CAArB;AACA,YAAMI,KAAK,GAAGnB,YAAY,CACxBe,GAAG,CAACI,KAAJ,CAAUC,IAAV,EADwB,EAExBL,GAAG,CAACM,OAFoB,EAGxBL,YAHwB,EAIxBC,YAJwB,CAA1B;AAMA,OAACE,KAAD,EAAQ,GAAGF,YAAY,CAACK,MAAb,CAAoBpB,OAApB,CAAX,EAAyCqB,OAAzC,CAAkDC,YAAD,IAAkB;AACjE,aAAKb,MAAL,CAAY,EAAE,GAAGI,GAAL;AAAUI,UAAAA,KAAK,EAAEK;AAAjB,SAAZ,EAA6CR,YAA7C,EAA2D,IAA3D;AACD,OAFD;AAGD;AACF;;AA/ByC","sourcesContent":["import type { DependencyList, ReactNode } from \"react\";\nimport { useCallback } from \"react\";\n\nimport type { DrawingContext } from \"../DrawingContext\";\nimport { processPaint } from \"../processors\";\nimport type { AnimatedProps } from \"../processors/Animations/Animations\";\nimport { materialize } from \"../processors/Animations/Animations\";\nimport { isPaint } from \"../../skia\";\nimport type { DependencyManager } from \"../DependencyManager\";\n\nimport { Node } from \"./Node\";\n\ntype DrawingCallback<P> = (\n ctx: DrawingContext,\n props: P,\n node: Node<P>\n) => void;\n\ntype OnDrawCallback<P> = (ctx: DrawingContext, props: P, node: Node<P>) => void;\n\nexport const createDrawing = <P,>(cb: OnDrawCallback<P>): DrawingCallback<P> =>\n cb;\n\nexport const useDrawing = <P,>(cb: OnDrawCallback<P>, deps?: DependencyList) =>\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useCallback(cb, deps ?? []);\n\nexport type DrawingProps<T> = {\n onDraw: DrawingCallback<T>;\n skipProcessing?: boolean;\n children?: ReactNode | ReactNode[];\n};\n\nexport class DrawingNode<P> extends Node<P> {\n onDraw: DrawingCallback<P>;\n skipProcessing: boolean;\n\n constructor(\n depMgr: DependencyManager,\n onDraw: DrawingCallback<P>,\n skipProcessing: boolean,\n props: AnimatedProps<P>\n ) {\n super(depMgr, props);\n this.onDraw = onDraw;\n this.skipProcessing = skipProcessing;\n }\n\n draw(ctx: DrawingContext) {\n const drawingProps = materialize(this.props);\n if (this.skipProcessing) {\n this.onDraw(ctx, drawingProps, this);\n } else {\n const declarations = this.visit(ctx);\n const paint = processPaint(\n ctx.paint.copy(),\n ctx.opacity,\n drawingProps,\n declarations\n );\n [paint, ...declarations.filter(isPaint)].forEach((currentPaint) => {\n this.onDraw({ ...ctx, paint: currentPaint }, drawingProps, this);\n });\n }\n }\n}\n"]}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
2
2
|
|
3
|
-
import { isPaint } from "../../skia";
|
4
3
|
export let NodeType;
|
5
4
|
|
6
5
|
(function (NodeType) {
|
@@ -16,7 +15,7 @@ export class Node {
|
|
16
15
|
|
17
16
|
_defineProperty(this, "memoizable", false);
|
18
17
|
|
19
|
-
_defineProperty(this, "memoized",
|
18
|
+
_defineProperty(this, "memoized", null);
|
20
19
|
|
21
20
|
_defineProperty(this, "parent", void 0);
|
22
21
|
|
@@ -38,26 +37,21 @@ export class Node {
|
|
38
37
|
return this._props;
|
39
38
|
}
|
40
39
|
|
41
|
-
visit(ctx) {
|
40
|
+
visit(ctx, children) {
|
42
41
|
const returnedValues = [];
|
43
|
-
|
44
|
-
this.children.forEach(child => {
|
42
|
+
(children !== null && children !== void 0 ? children : this.children).forEach(child => {
|
45
43
|
if (!child.memoized) {
|
46
|
-
const ret = child.draw(
|
44
|
+
const ret = child.draw(ctx);
|
47
45
|
|
48
46
|
if (ret) {
|
49
|
-
if (isPaint(ret)) {
|
50
|
-
currentCtx = { ...currentCtx,
|
51
|
-
paint: ret
|
52
|
-
};
|
53
|
-
}
|
54
|
-
|
55
47
|
returnedValues.push(ret);
|
56
|
-
}
|
57
48
|
|
58
|
-
|
59
|
-
|
49
|
+
if (child.memoizable) {
|
50
|
+
child.memoized = ret;
|
51
|
+
}
|
60
52
|
}
|
53
|
+
} else {
|
54
|
+
returnedValues.push(child.memoized);
|
61
55
|
}
|
62
56
|
});
|
63
57
|
return returnedValues;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Node.ts"],"names":["
|
1
|
+
{"version":3,"sources":["Node.ts"],"names":["NodeType","Node","constructor","depMgr","props","_props","unSubscribeNode","subscribeNode","visit","ctx","children","returnedValues","forEach","child","memoized","ret","draw","push","memoizable"],"mappings":";;AAKA,WAAYA,QAAZ;;WAAYA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;GAAAA,Q,KAAAA,Q;;AAOZ,OAAO,MAAeC,IAAf,CAAiC;AAQtCC,EAAAA,WAAW,CAACC,MAAD,EAA4BC,KAA5B,EAAqD;AAAA,sCAPpC,EAOoC;;AAAA;;AAAA,wCALnD,KAKmD;;AAAA,sCAJ3B,IAI2B;;AAAA;;AAAA;;AAC9D,SAAKC,MAAL,GAAcD,KAAd;AACA,SAAKD,MAAL,GAAcA,MAAd;AACA,SAAKA,MAAL,CAAYG,eAAZ,CAA4B,IAA5B;AACA,SAAKH,MAAL,CAAYI,aAAZ,CAA0B,IAA1B,EAAgCH,KAAhC;AACD;;AAIQ,MAALA,KAAK,CAACA,KAAD,EAA0B;AACjC,SAAKD,MAAL,CAAYG,eAAZ,CAA4B,IAA5B;AACA,SAAKH,MAAL,CAAYI,aAAZ,CAA0B,IAA1B,EAAgCH,KAAhC;AACA,SAAKC,MAAL,GAAcD,KAAd;AACD;;AAEQ,MAALA,KAAK,GAAG;AACV,WAAO,KAAKC,MAAZ;AACD;;AAEDG,EAAAA,KAAK,CAACC,GAAD,EAAsBC,QAAtB,EAAyC;AAC5C,UAAMC,cAAkD,GAAG,EAA3D;AACA,KAACD,QAAD,aAACA,QAAD,cAACA,QAAD,GAAa,KAAKA,QAAlB,EAA4BE,OAA5B,CAAqCC,KAAD,IAAW;AAC7C,UAAI,CAACA,KAAK,CAACC,QAAX,EAAqB;AACnB,cAAMC,GAAG,GAAGF,KAAK,CAACG,IAAN,CAAWP,GAAX,CAAZ;;AACA,YAAIM,GAAJ,EAAS;AACPJ,UAAAA,cAAc,CAACM,IAAf,CAAoBF,GAApB;;AACA,cAAIF,KAAK,CAACK,UAAV,EAAsB;AACpBL,YAAAA,KAAK,CAACC,QAAN,GAAiBC,GAAjB;AACD;AACF;AACF,OARD,MAQO;AACLJ,QAAAA,cAAc,CAACM,IAAf,CAAoBJ,KAAK,CAACC,QAA1B;AACD;AACF,KAZD;AAaA,WAAOH,cAAP;AACD;;AA3CqC","sourcesContent":["import type { SkJSIInstance } from \"../../skia/JsiInstance\";\nimport type { DependencyManager } from \"../DependencyManager\";\nimport type { DrawingContext } from \"../DrawingContext\";\nimport type { AnimatedProps } from \"../processors\";\n\nexport enum NodeType {\n Declaration = \"skDeclaration\",\n Drawing = \"skDrawing\",\n}\n\ntype DeclarationResult = SkJSIInstance<string> | null;\n\nexport abstract class Node<P = unknown> {\n readonly children: Node[] = [];\n _props: AnimatedProps<P>;\n memoizable = false;\n memoized: DeclarationResult | null = null;\n parent?: Node;\n depMgr: DependencyManager;\n\n constructor(depMgr: DependencyManager, props: AnimatedProps<P>) {\n this._props = props;\n this.depMgr = depMgr;\n this.depMgr.unSubscribeNode(this);\n this.depMgr.subscribeNode(this, props);\n }\n\n abstract draw(ctx: DrawingContext): void | DeclarationResult;\n\n set props(props: AnimatedProps<P>) {\n this.depMgr.unSubscribeNode(this);\n this.depMgr.subscribeNode(this, props);\n this._props = props;\n }\n\n get props() {\n return this._props;\n }\n\n visit(ctx: DrawingContext, children?: Node[]) {\n const returnedValues: Exclude<DeclarationResult, null>[] = [];\n (children ?? this.children).forEach((child) => {\n if (!child.memoized) {\n const ret = child.draw(ctx);\n if (ret) {\n returnedValues.push(ret);\n if (child.memoizable) {\n child.memoized = ret;\n }\n }\n } else {\n returnedValues.push(child.memoized);\n }\n });\n return returnedValues;\n }\n}\n"]}
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import { BlendMode, PaintStyle, StrokeJoin, StrokeCap, processColor } from "../../skia";
|
1
|
+
import { BlendMode, PaintStyle, StrokeJoin, StrokeCap, processColor, isShader, isMaskFilter, isColorFilter, isPathEffect, isImageFilter, Skia } from "../../skia";
|
2
2
|
export const enumKey = k => k.charAt(0).toUpperCase() + k.slice(1);
|
3
|
-
export const processPaint = (paint, currentOpacity, _ref) => {
|
3
|
+
export const processPaint = (paint, currentOpacity, _ref, children) => {
|
4
4
|
let {
|
5
|
+
paint: paintRef,
|
5
6
|
color,
|
6
7
|
blendMode,
|
7
8
|
style,
|
@@ -12,6 +13,10 @@ export const processPaint = (paint, currentOpacity, _ref) => {
|
|
12
13
|
opacity
|
13
14
|
} = _ref;
|
14
15
|
|
16
|
+
if (paintRef && paintRef.current) {
|
17
|
+
return paintRef.current;
|
18
|
+
}
|
19
|
+
|
15
20
|
if (color !== undefined) {
|
16
21
|
const c = processColor(color, currentOpacity);
|
17
22
|
paint.setShader(null);
|
@@ -48,28 +53,24 @@ export const processPaint = (paint, currentOpacity, _ref) => {
|
|
48
53
|
if (opacity !== undefined) {
|
49
54
|
paint.setAlphaf(opacity);
|
50
55
|
}
|
51
|
-
};
|
52
|
-
export const selectPaint = (currentPaint, _ref2) => {
|
53
|
-
var _paint$current;
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
}
|
66
|
-
const
|
67
|
-
const parentPaint = (_paint$current = paint === null || paint === void 0 ? void 0 : paint.current) !== null && _paint$current !== void 0 ? _paint$current : currentPaint;
|
57
|
+
children.forEach(child => {
|
58
|
+
if (isShader(child)) {
|
59
|
+
paint.setShader(child);
|
60
|
+
} else if (isMaskFilter(child)) {
|
61
|
+
paint.setMaskFilter(child);
|
62
|
+
} else if (isColorFilter(child)) {
|
63
|
+
paint.setColorFilter(child);
|
64
|
+
} else if (isPathEffect(child)) {
|
65
|
+
paint.setPathEffect(child);
|
66
|
+
}
|
67
|
+
});
|
68
|
+
const filters = children.filter(isImageFilter);
|
68
69
|
|
69
|
-
if (
|
70
|
-
|
70
|
+
if (filters.length > 0) {
|
71
|
+
paint.setImageFilter(filters.reverse().reduce(Skia.ImageFilter.MakeCompose, null));
|
71
72
|
}
|
72
73
|
|
73
|
-
return
|
74
|
+
return paint;
|
74
75
|
};
|
75
76
|
//# sourceMappingURL=Paint.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Paint.ts"],"names":["BlendMode","PaintStyle","StrokeJoin","StrokeCap","processColor","enumKey","k","charAt","toUpperCase","slice","processPaint","paint","currentOpacity","color","blendMode","style","strokeWidth","strokeJoin","strokeCap","strokeMiter","opacity","undefined","c","setShader","setColor","getColor","setBlendMode","setStyle","setStrokeJoin","setStrokeCap","setStrokeMiter","setStrokeWidth","setAlphaf","
|
1
|
+
{"version":3,"sources":["Paint.ts"],"names":["BlendMode","PaintStyle","StrokeJoin","StrokeCap","processColor","isShader","isMaskFilter","isColorFilter","isPathEffect","isImageFilter","Skia","enumKey","k","charAt","toUpperCase","slice","processPaint","paint","currentOpacity","children","paintRef","color","blendMode","style","strokeWidth","strokeJoin","strokeCap","strokeMiter","opacity","current","undefined","c","setShader","setColor","getColor","setBlendMode","setStyle","setStrokeJoin","setStrokeCap","setStrokeMiter","setStrokeWidth","setAlphaf","forEach","child","setMaskFilter","setColorFilter","setPathEffect","filters","filter","length","setImageFilter","reverse","reduce","ImageFilter","MakeCompose"],"mappings":"AAEA,SACEA,SADF,EAEEC,UAFF,EAGEC,UAHF,EAIEC,SAJF,EAKEC,YALF,EAMEC,QANF,EAOEC,YAPF,EAQEC,aARF,EASEC,YATF,EAUEC,aAVF,EAWEC,IAXF,QAYO,YAZP;AAkCA,OAAO,MAAMC,OAAO,GAAsBC,CAAnB,IACpBA,CAAC,CAACC,MAAF,CAAS,CAAT,EAAYC,WAAZ,KAA4BF,CAAC,CAACG,KAAF,CAAQ,CAAR,CADxB;AAGP,OA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AO,CAACe,SAAD,CAAR,CAA5B;AACD;;AACD,MAAIC,WAAW,KAAKG,SAApB,EAA+B;AAC7Bb,IAAAA,KAAK,CAACsB,cAAN,CAAqBZ,WAArB;AACD;;AACD,MAAIH,WAAW,KAAKM,SAApB,EAA+B;AAC7Bb,IAAAA,KAAK,CAACuB,cAAN,CAAqBhB,WAArB;AACD;;AACD,MAAII,OAAO,KAAKE,SAAhB,EAA2B;AACzBb,IAAAA,KAAK,CAACwB,SAAN,CAAgBb,OAAhB;AACD;;AACDT,EAAAA,QAAQ,CAACuB,OAAT,CAAkBC,KAAD,IAAW;AAC1B,QAAItC,QAAQ,CAACsC,KAAD,CAAZ,EAAqB;AACnB1B,MAAAA,KAAK,CAACe,SAAN,CAAgBW,KAAhB;AACD,KAFD,MAEO,IAAIrC,YAAY,CAACqC,KAAD,CAAhB,EAAyB;AAC9B1B,MAAAA,KAAK,CAAC2B,aAAN,CAAoBD,KAApB;AACD,KAFM,MAEA,IAAIpC,aAAa,CAACoC,KAAD,CAAjB,EAA0B;AAC/B1B,MAAAA,KAAK,CAAC4B,cAAN,CAAqBF,KAArB;AACD,KAFM,MAEA,IAAInC,YAAY,CAACmC,KAAD,CAAhB,EAAyB;AAC9B1B,MAAAA,KAAK,CAAC6B,aAAN,CAAoBH,KAApB;AACD;AACF,GAVD;AAWA,QAAMI,OAAO,GAAG5B,QAAQ,CAAC6B,MAAT,CAAgBvC,aAAhB,CAAhB;;AACA,MAAIsC,OAAO,CAACE,MAAR,GAAiB,CAArB,EAAwB;AACtBhC,IAAAA,KAAK,CAACiC,cAAN,CACEH,OAAO,CACJI,OADH,GAEGC,MAFH,CAEgC1C,IAAI,CAAC2C,WAAL,CAAiBC,WAFjD,EAE8D,IAF9D,CADF;AAKD;;AACD,SAAOrC,KAAP;AACD,CApEM","sourcesContent":["import type { ReactNode, RefObject } from \"react\";\n\nimport {\n BlendMode,\n PaintStyle,\n StrokeJoin,\n StrokeCap,\n processColor,\n isShader,\n isMaskFilter,\n isColorFilter,\n isPathEffect,\n isImageFilter,\n Skia,\n} from \"../../skia\";\nimport type { SkPaint, Color, SkImageFilter } from \"../../skia\";\nimport type { DeclarationResult } from \"../nodes\";\nexport type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;\n\nexport interface ChildrenProps {\n children?: ReactNode | ReactNode[];\n}\n\n// TODO: rename to paint props?\nexport interface CustomPaintProps extends ChildrenProps {\n paint?: RefObject<SkPaint>;\n color?: Color;\n strokeWidth?: number;\n blendMode?: SkEnum<typeof BlendMode>;\n style?: SkEnum<typeof PaintStyle>;\n strokeJoin?: SkEnum<typeof StrokeJoin>;\n strokeCap?: SkEnum<typeof StrokeCap>;\n strokeMiter?: number;\n opacity?: number;\n}\n\nexport const enumKey = <K extends string>(k: K) =>\n (k.charAt(0).toUpperCase() + k.slice(1)) as Capitalize<K>;\n\nexport const processPaint = (\n paint: SkPaint,\n currentOpacity: number,\n {\n paint: paintRef,\n color,\n blendMode,\n style,\n strokeWidth,\n strokeJoin,\n strokeCap,\n strokeMiter,\n opacity,\n }: CustomPaintProps,\n children: DeclarationResult[]\n) => {\n if (paintRef && paintRef.current) {\n return paintRef.current;\n }\n if (color !== undefined) {\n const c = processColor(color, currentOpacity);\n paint.setShader(null);\n paint.setColor(c);\n } else {\n const c = processColor(paint.getColor(), currentOpacity);\n paint.setColor(c);\n }\n if (blendMode !== undefined) {\n paint.setBlendMode(BlendMode[enumKey(blendMode)]);\n }\n if (style !== undefined) {\n paint.setStyle(PaintStyle[enumKey(style)]);\n }\n if (strokeJoin !== undefined) {\n paint.setStrokeJoin(StrokeJoin[enumKey(strokeJoin)]);\n }\n if (strokeCap !== undefined) {\n paint.setStrokeCap(StrokeCap[enumKey(strokeCap)]);\n }\n if (strokeMiter !== undefined) {\n paint.setStrokeMiter(strokeMiter);\n }\n if (strokeWidth !== undefined) {\n paint.setStrokeWidth(strokeWidth);\n }\n if (opacity !== undefined) {\n paint.setAlphaf(opacity);\n }\n children.forEach((child) => {\n if (isShader(child)) {\n paint.setShader(child);\n } else if (isMaskFilter(child)) {\n paint.setMaskFilter(child);\n } else if (isColorFilter(child)) {\n paint.setColorFilter(child);\n } else if (isPathEffect(child)) {\n paint.setPathEffect(child);\n }\n });\n const filters = children.filter(isImageFilter);\n if (filters.length > 0) {\n paint.setImageFilter(\n filters\n .reverse()\n .reduce<SkImageFilter | null>(Skia.ImageFilter.MakeCompose, null)\n );\n }\n return paint;\n};\n"]}
|
@@ -1,2 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* Linear interpolation
|
3
|
+
* @param value
|
4
|
+
* @param x
|
5
|
+
* @param y
|
6
|
+
*/
|
1
7
|
export const mix = (value, x, y) => x * (1 - value) + y * value;
|
8
|
+
/**
|
9
|
+
* @summary Clamps a node with a lower and upper bound.
|
10
|
+
* @example
|
11
|
+
clamp(-1, 0, 100); // 0
|
12
|
+
clamp(1, 0, 100); // 1
|
13
|
+
clamp(101, 0, 100); // 100
|
14
|
+
*/
|
15
|
+
|
16
|
+
export const clamp = (value, lowerBound, upperBound) => Math.min(Math.max(lowerBound, value), upperBound);
|
2
17
|
//# sourceMappingURL=Math.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Math.ts"],"names":["mix","value","x","y"],"mappings":"AAAA,OAAO,MAAMA,GAAG,GAAG,CAACC,KAAD,EAAgBC,CAAhB,EAA2BC,CAA3B,KACjBD,CAAC,IAAI,IAAID,KAAR,CAAD,GAAkBE,CAAC,GAAGF,KADjB","sourcesContent":["
|
1
|
+
{"version":3,"sources":["Math.ts"],"names":["mix","value","x","y","clamp","lowerBound","upperBound","Math","min","max"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,GAAG,GAAG,CAACC,KAAD,EAAgBC,CAAhB,EAA2BC,CAA3B,KACjBD,CAAC,IAAI,IAAID,KAAR,CAAD,GAAkBE,CAAC,GAAGF,KADjB;AAGP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,KAAK,GAAG,CAACH,KAAD,EAAgBI,UAAhB,EAAoCC,UAApC,KACnBC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,GAAL,CAASJ,UAAT,EAAqBJ,KAArB,CAAT,EAAsCK,UAAtC,CADK","sourcesContent":["/**\n * Linear interpolation\n * @param value\n * @param x\n * @param y\n */\nexport const mix = (value: number, x: number, y: number) =>\n x * (1 - value) + y * value;\n\n/**\n * @summary Clamps a node with a lower and upper bound.\n * @example\n clamp(-1, 0, 100); // 0\n clamp(1, 0, 100); // 1\n clamp(101, 0, 100); // 100\n */\nexport const clamp = (value: number, lowerBound: number, upperBound: number) =>\n Math.min(Math.max(lowerBound, value), upperBound);\n"]}
|
@@ -26,11 +26,15 @@ const multiply3 = (m1, m2) => {
|
|
26
26
|
return [[dot3(m1[0], col0), dot3(m1[0], col1), dot3(m1[0], col2)], [dot3(m1[1], col0), dot3(m1[1], col1), dot3(m1[1], col2)], [dot3(m1[2], col0), dot3(m1[2], col1), dot3(m1[2], col2)]];
|
27
27
|
};
|
28
28
|
|
29
|
+
export const matrixVecMul3 = (m, v) => [dot3(m[0], v), dot3(m[1], v), dot3(m[2], v)];
|
30
|
+
|
29
31
|
const skiaMatrix3 = m => {
|
30
32
|
return [m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2]];
|
31
33
|
};
|
32
34
|
|
33
|
-
export const processTransform2d = transforms => skiaMatrix3(transforms
|
35
|
+
export const processTransform2d = transforms => skiaMatrix3(processTransform(transforms));
|
36
|
+
|
37
|
+
const processTransform = transforms => transforms.reduce((acc, transform) => {
|
34
38
|
const key = Object.keys(transform)[0];
|
35
39
|
const value = transform[key];
|
36
40
|
|
@@ -67,5 +71,5 @@ export const processTransform2d = transforms => skiaMatrix3(transforms.reduce((a
|
|
67
71
|
}
|
68
72
|
|
69
73
|
return exhaustiveCheck(key);
|
70
|
-
}, identityMatrix)
|
74
|
+
}, identityMatrix);
|
71
75
|
//# sourceMappingURL=Matrix3.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Matrix3.ts"],"names":["exhaustiveCheck","identityMatrix","translateXMatrix","x","translateYMatrix","y","scaleMatrix","s","scaleXMatrix","scaleYMatrix","skewXMatrix","Math","tan","skewYMatrix","rotateZMatrix","r","cos","sin","dot3","row","col","multiply3","m1","m2","col0","col1","col2","
|
1
|
+
{"version":3,"sources":["Matrix3.ts"],"names":["exhaustiveCheck","identityMatrix","translateXMatrix","x","translateYMatrix","y","scaleMatrix","s","scaleXMatrix","scaleYMatrix","skewXMatrix","Math","tan","skewYMatrix","rotateZMatrix","r","cos","sin","dot3","row","col","multiply3","m1","m2","col0","col1","col2","matrixVecMul3","m","v","skiaMatrix3","processTransform2d","transforms","processTransform","reduce","acc","transform","key","Object","keys","value"],"mappings":"AAAA,SAASA,eAAT,QAAgC,iBAAhC;AAoCA,MAAMC,cAAuB,GAAG,CAC9B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAD8B,EAE9B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAF8B,EAG9B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAH8B,CAAhC;;AAMA,MAAMC,gBAAgB,GAAIC,CAAD,IAAwB,CAC/C,CAAC,CAAD,EAAI,CAAJ,EAAOA,CAAP,CAD+C,EAE/C,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAF+C,EAG/C,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAH+C,CAAjD;;AAMA,MAAMC,gBAAgB,GAAIC,CAAD,IAAwB,CAC/C,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAD+C,EAE/C,CAAC,CAAD,EAAI,CAAJ,EAAOA,CAAP,CAF+C,EAG/C,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAH+C,CAAjD;;AAMA,MAAMC,WAAW,GAAIC,CAAD,IAAwB,CAC1C,CAACA,CAAD,EAAI,CAA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C,eAAe,CAACqC,GAAD,CAAtB;AACD,CA5BD,EA4BGpC,cA5BH,CADF","sourcesContent":["import { exhaustiveCheck } from \"../../typeddash\";\nimport type { SkMatrix } from \"../../../skia/Matrix\";\n\nexport type Vec3 = readonly [number, number, number];\n\nexport type Matrix3 = readonly [Vec3, Vec3, Vec3];\n\ntype Transform2dName =\n | \"translateX\"\n | \"translateY\"\n | \"scale\"\n | \"skewX\"\n | \"skewY\"\n | \"scaleX\"\n | \"scaleY\"\n | \"rotateZ\"\n | \"rotate\";\n\nexport interface TransformProp {\n transform?: Transforms2d;\n}\n\ntype Transformations = {\n readonly [Name in Transform2dName]: number;\n};\nexport type Transforms2d = readonly (\n | Pick<Transformations, \"translateX\">\n | Pick<Transformations, \"translateY\">\n | Pick<Transformations, \"scale\">\n | Pick<Transformations, \"scaleX\">\n | Pick<Transformations, \"scaleY\">\n | Pick<Transformations, \"skewX\">\n | Pick<Transformations, \"skewY\">\n | Pick<Transformations, \"rotate\">\n)[];\n\nconst identityMatrix: Matrix3 = [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst translateXMatrix = (x: number): Matrix3 => [\n [1, 0, x],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst translateYMatrix = (y: number): Matrix3 => [\n [1, 0, 0],\n [0, 1, y],\n [0, 0, 1],\n];\n\nconst scaleMatrix = (s: number): Matrix3 => [\n [s, 0, 0],\n [0, s, 0],\n [0, 0, 1],\n];\n\nconst scaleXMatrix = (s: number): Matrix3 => [\n [s, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst scaleYMatrix = (s: number): Matrix3 => [\n [1, 0, 0],\n [0, s, 0],\n [0, 0, 1],\n];\n\nconst skewXMatrix = (s: number): Matrix3 => [\n [1, Math.tan(s), 0],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst skewYMatrix = (s: number): Matrix3 => [\n [1, 0, 0],\n [Math.tan(s), 1, 0],\n [0, 0, 1],\n];\n\nconst rotateZMatrix = (r: number): Matrix3 => [\n [Math.cos(r), -1 * Math.sin(r), 0],\n [Math.sin(r), Math.cos(r), 0],\n [0, 0, 1],\n];\n\nconst dot3 = (row: Vec3, col: Vec3) =>\n row[0] * col[0] + row[1] * col[1] + row[2] * col[2];\n\nconst multiply3 = (m1: Matrix3, m2: Matrix3) => {\n const col0 = [m2[0][0], m2[1][0], m2[2][0]] as const;\n const col1 = [m2[0][1], m2[1][1], m2[2][1]] as const;\n const col2 = [m2[0][2], m2[1][2], m2[2][2]] as const;\n return [\n [dot3(m1[0], col0), dot3(m1[0], col1), dot3(m1[0], col2)],\n [dot3(m1[1], col0), dot3(m1[1], col1), dot3(m1[1], col2)],\n [dot3(m1[2], col0), dot3(m1[2], col1), dot3(m1[2], col2)],\n ] as const;\n};\n\nexport const matrixVecMul3 = (m: Matrix3, v: Vec3) =>\n [dot3(m[0], v), dot3(m[1], v), dot3(m[2], v)] as const;\n\nconst skiaMatrix3 = (m: Matrix3): SkMatrix => {\n return [\n m[0][0],\n m[0][1],\n m[0][2],\n m[1][0],\n m[1][1],\n m[1][2],\n m[2][0],\n m[2][1],\n m[2][2],\n ];\n};\n\nexport const processTransform2d = (transforms: Transforms2d) =>\n skiaMatrix3(processTransform(transforms));\n\nconst processTransform = (transforms: Transforms2d) =>\n transforms.reduce((acc, transform) => {\n const key = Object.keys(transform)[0] as Transform2dName;\n const value = (transform as Pick<Transformations, typeof key>)[key];\n if (key === \"translateX\") {\n return multiply3(acc, translateXMatrix(value));\n }\n if (key === \"translateY\") {\n return multiply3(acc, translateYMatrix(value));\n }\n if (key === \"scale\") {\n return multiply3(acc, scaleMatrix(value));\n }\n if (key === \"scaleX\") {\n return multiply3(acc, scaleXMatrix(value));\n }\n if (key === \"scaleY\") {\n return multiply3(acc, scaleYMatrix(value));\n }\n if (key === \"skewX\") {\n return multiply3(acc, skewXMatrix(value));\n }\n if (key === \"skewY\") {\n return multiply3(acc, skewYMatrix(value));\n }\n if (key === \"rotate\" || key === \"rotateZ\") {\n return multiply3(acc, rotateZMatrix(value));\n }\n return exhaustiveCheck(key);\n }, identityMatrix);\n"]}
|
@@ -1,5 +1,26 @@
|
|
1
1
|
export const mapKeys = obj => Object.keys(obj);
|
2
2
|
export const exhaustiveCheck = a => {
|
3
3
|
throw new Error(`Unexhaustive handling for ${a}`);
|
4
|
+
}; // Shallow eq on props (without children)
|
5
|
+
|
6
|
+
export const shallowEq = (p1, p2) => {
|
7
|
+
const keys1 = mapKeys(p1);
|
8
|
+
const keys2 = mapKeys(p2);
|
9
|
+
|
10
|
+
if (keys1.length !== keys2.length) {
|
11
|
+
return false;
|
12
|
+
}
|
13
|
+
|
14
|
+
for (const key of keys1) {
|
15
|
+
if (key === "children") {
|
16
|
+
continue;
|
17
|
+
}
|
18
|
+
|
19
|
+
if (p1[key] !== p2[key]) {
|
20
|
+
return false;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
return true;
|
4
25
|
};
|
5
26
|
//# sourceMappingURL=typeddash.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["typeddash.ts"],"names":["mapKeys","obj","Object","keys","exhaustiveCheck","a","Error"],"mappings":"AAAA,OAAO,MAAMA,OAAO,GAAOC,GAAJ,IAAeC,MAAM,CAACC,IAAP,CAAYF,GAAZ,CAA/B;AAEP,OAAO,MAAMG,eAAe,GAAIC,CAAD,IAAqB;AAClD,QAAM,IAAIC,KAAJ,CAAW,6BAA4BD,CAAE,EAAzC,CAAN;AACD,CAFM","sourcesContent":["export const mapKeys = <T>(obj: T) => Object.keys(obj) as (keyof T)[];\n\nexport const exhaustiveCheck = (a: never): never => {\n throw new Error(`Unexhaustive handling for ${a}`);\n};\n"]}
|
1
|
+
{"version":3,"sources":["typeddash.ts"],"names":["mapKeys","obj","Object","keys","exhaustiveCheck","a","Error","shallowEq","p1","p2","keys1","keys2","length","key"],"mappings":"AAAA,OAAO,MAAMA,OAAO,GAAOC,GAAJ,IAAeC,MAAM,CAACC,IAAP,CAAYF,GAAZ,CAA/B;AAEP,OAAO,MAAMG,eAAe,GAAIC,CAAD,IAAqB;AAClD,QAAM,IAAIC,KAAJ,CAAW,6BAA4BD,CAAE,EAAzC,CAAN;AACD,CAFM,C,CAIP;;AACA,OAAO,MAAME,SAAS,GAAG,CAAIC,EAAJ,EAAWC,EAAX,KAA8B;AACrD,QAAMC,KAAK,GAAGV,OAAO,CAACQ,EAAD,CAArB;AACA,QAAMG,KAAK,GAAGX,OAAO,CAACS,EAAD,CAArB;;AACA,MAAIC,KAAK,CAACE,MAAN,KAAiBD,KAAK,CAACC,MAA3B,EAAmC;AACjC,WAAO,KAAP;AACD;;AACD,OAAK,MAAMC,GAAX,IAAkBH,KAAlB,EAAyB;AACvB,QAAIG,GAAG,KAAK,UAAZ,EAAwB;AACtB;AACD;;AACD,QAAIL,EAAE,CAACK,GAAD,CAAF,KAAYJ,EAAE,CAACI,GAAD,CAAlB,EAAyB;AACvB,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAAP;AACD,CAfM","sourcesContent":["export const mapKeys = <T>(obj: T) => Object.keys(obj) as (keyof T)[];\n\nexport const exhaustiveCheck = (a: never): never => {\n throw new Error(`Unexhaustive handling for ${a}`);\n};\n\n// Shallow eq on props (without children)\nexport const shallowEq = <P>(p1: P, p2: P): boolean => {\n const keys1 = mapKeys(p1);\n const keys2 = mapKeys(p2);\n if (keys1.length !== keys2.length) {\n return false;\n }\n for (const key of keys1) {\n if (key === \"children\") {\n continue;\n }\n if (p1[key] !== p2[key]) {\n return false;\n }\n }\n return true;\n};\n"]}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import React, { useMemo, useContext } from "react";
|
2
|
+
// useContextBridge() is taken from https://github.com/pmndrs/drei#usecontextbridge
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
4
|
+
export const useContextBridge = function () {
|
5
|
+
for (var _len = arguments.length, contexts = new Array(_len), _key = 0; _key < _len; _key++) {
|
6
|
+
contexts[_key] = arguments[_key];
|
7
|
+
}
|
8
|
+
|
9
|
+
const values = // eslint-disable-next-line react-hooks/rules-of-hooks
|
10
|
+
contexts.map(context => useContext(context));
|
11
|
+
return useMemo(() => _ref => {
|
12
|
+
let {
|
13
|
+
children
|
14
|
+
} = _ref;
|
15
|
+
return contexts.reduceRight((acc, Context, i) => /*#__PURE__*/React.createElement(Context.Provider, {
|
16
|
+
value: values[i],
|
17
|
+
children: acc
|
18
|
+
}), children);
|
19
|
+
}, [contexts, values]);
|
20
|
+
};
|
21
|
+
//# sourceMappingURL=useContextBridge.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["useContextBridge.tsx"],"names":["React","useMemo","useContext","useContextBridge","contexts","values","map","context","children","reduceRight","acc","Context","i"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,OAAhB,EAAyBC,UAAzB,QAA2C,OAA3C;AAGA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAG,YAAiC;AAAA,oCAA7BC,QAA6B;AAA7BA,IAAAA,QAA6B;AAAA;;AAC/D,QAAMC,MAAM,GACV;AACAD,EAAAA,QAAQ,CAACE,GAAT,CAAcC,OAAD,IAAaL,UAAU,CAACK,OAAD,CAApC,CAFF;AAGA,SAAON,OAAO,CACZ,MACE;AAAA,QAAC;AAAEO,MAAAA;AAAF,KAAD;AAAA,WACEJ,QAAQ,CAACK,WAAT,CACE,CAACC,GAAD,EAAMC,OAAN,EAAeC,CAAf,kBACE,oBAAC,OAAD,CAAS,QAAT;AAAkB,MAAA,KAAK,EAAEP,MAAM,CAACO,CAAD,CAA/B;AAAoC,MAAA,QAAQ,EAAEF;AAA9C,MAFJ,EAIEF,QAJF,CADF;AAAA,GAFU,EASZ,CAACJ,QAAD,EAAWC,MAAX,CATY,CAAd;AAWD,CAfM","sourcesContent":["import React, { useMemo, useContext } from \"react\";\nimport type { ReactNode, Context, ReactElement } from \"react\";\n\n// useContextBridge() is taken from https://github.com/pmndrs/drei#usecontextbridge\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useContextBridge = (...contexts: Context<any>[]) => {\n const values =\n // eslint-disable-next-line react-hooks/rules-of-hooks\n contexts.map((context) => useContext(context));\n return useMemo(\n () =>\n ({ children }: { children: ReactNode }) =>\n contexts.reduceRight(\n (acc, Context, i) => (\n <Context.Provider value={values[i]} children={acc} />\n ),\n children\n ) as ReactElement,\n [contexts, values]\n );\n};\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Canvas.ts"],"names":["ClipOp","SaveLayerFlag"],"mappings":"AAeA,WAAYA,MAAZ;;WAAYA,M;AAAAA,EAAAA,M,CAAAA,M;AAAAA,EAAAA,M,CAAAA,M;GAAAA,M,KAAAA,M;;AAKZ,WAAYC,aAAZ;;WAAYA,a;AAAAA,EAAAA,a,CAAAA,a;AAAAA,EAAAA,a,CAAAA,a;GAAAA,a,KAAAA,a","sourcesContent":["import type { SkPaint } from \"./Paint\";\nimport type { SkRect } from \"./Rect\";\nimport type { SkFont } from \"./Font\";\nimport type { SkPath } from \"./Path\";\nimport type { SkImage, MipmapMode, FilterMode } from \"./Image\";\nimport type { SkSVG } from \"./SVG\";\nimport type { SkColor } from \"./Color\";\nimport type { SkRRect } from \"./RRect\";\nimport type { BlendMode } from \"./Paint/BlendMode\";\nimport type { SkPoint, PointMode } from \"./Point\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { SkImageFilter } from \"./ImageFilter\";\nimport type { SkVertices } from \"./Vertices\";\nimport type { SkTextBlob } from \"./TextBlob\";\n\nexport enum ClipOp {\n Difference,\n Intersect,\n}\n\nexport enum SaveLayerFlag {\n SaveLayerInitWithPrevious = 1 << 2,\n SaveLayerF16ColorType = 1 << 4,\n}\n\nexport interface SkCanvas {\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix, and optionally-provided paint.\n * @param img\n * @param left\n * @param top\n * @param paint\n */\n drawImage: (image: SkImage, x: number, y: number, paint?: SkPaint) => void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * @param img\n * @param src\n * @param dest\n * @param paint\n * @param fastSample - if false, will filter strictly within src.\n */\n drawImageRect(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n paint: SkPaint,\n fastSample?: boolean\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param left\n * @param top\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageCubic(\n img: SkImage,\n left: number,\n top: number,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the provided sampling options if necessary.\n * @param img\n * @param left\n * @param top\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageOptions(\n img: SkImage,\n left: number,\n top: number,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the provided image stretched proportionally to fit into dst rectangle.\n * The center rectangle divides the image into nine sections: four sides, four corners, and\n * the center.\n * @param img\n * @param center\n * @param dest\n * @param filter - what technique to use when sampling the image\n * @param paint\n */\n drawImageNine(\n img: SkImage,\n center: SkRect,\n dest: SkRect,\n filter: FilterMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param src\n * @param dest\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageRectCubic(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the provided sampling options if necessary.\n * @param img\n * @param src\n * @param dest\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageRectOptions(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /** Fills clip with SkPaint paint. SkPaint components, SkShader,\n SkColorFilter, SkImageFilter, and SkBlendMode affect drawing;\n SkMaskFilter and SkPathEffect in paint are ignored.\n\n @param paint graphics state used to fill SkCanvas\n\n example: https://fiddle.skia.org/c/@Canvas_drawPaint\n */\n drawPaint: (paint: SkPaint) => void;\n\n /** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint stroke width describes the line thickness;\n SkPaint::Cap draws the end rounded or square;\n SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.\n\n @param x0 start of line segment on x-axis\n @param y0 start of line segment on y-axis\n @param x1 end of line segment on x-axis\n @param y1 end of line segment on y-axis\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawLine\n */\n drawLine: (\n x0: number,\n y0: number,\n x1: number,\n y1: number,\n paint: SkPaint\n ) => void;\n /** Draws SkRect rect using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint::Style determines if rectangle is stroked or filled;\n if stroked, SkPaint stroke width describes the line thickness, and\n SkPaint::Join draws the corners rounded or square.\n\n @param rect rectangle to draw\n @param paint stroke or fill, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawRect\n */\n drawRect: (rect: SkRect, paint: SkPaint) => void;\n\n /**\n * Draws a circle at (cx, cy) with the given radius.\n * @param cx\n * @param cy\n * @param radius\n * @param paint\n */\n drawCircle(cx: number, cy: number, radius: number, paint: SkPaint): void;\n\n /**\n * Draws the given vertices (a triangle mesh) using the current clip, current matrix, and the\n * provided paint.\n * If paint contains an Shader and vertices does not contain texCoords, the shader\n * is mapped using the vertices' positions.\n * If vertices colors are defined in vertices, and Paint paint contains Shader,\n * BlendMode mode combines vertices colors with Shader.\n * @param verts\n * @param mode\n * @param paint\n */\n drawVertices(verts: SkVertices, mode: BlendMode, paint: SkPaint): void;\n\n /**\n * Draws a cubic patch defined by 12 control points [top, right, bottom, left] with optional\n * colors and shader-coordinates [4] specifed for each corner [top-left, top-right, bottom-right, bottom-left]\n * @param cubics 12 points : 4 connected cubics specifying the boundary of the patch\n * @param colors optional colors interpolated across the patch\n * @param texs optional shader coordinates interpolated across the patch\n * @param mode Specifies how shader and colors blend (if both are specified)\n * @param paint\n */\n drawPatch(\n cubics: readonly SkPoint[],\n colors?: readonly SkColor[] | null,\n texs?: readonly SkPoint[] | null,\n mode?: BlendMode | null,\n paint?: SkPaint\n ): void;\n\n /**\n * Restores state to a previous stack value.\n * @param saveCount\n */\n restoreToCount(saveCount: number): void;\n\n /**\n * Draws the given points using the current clip, current matrix, and the provided paint.\n *\n * See Canvas.h for more on the mode and its interaction with paint.\n * @param mode\n * @param points\n * @param paint\n */\n drawPoints(mode: PointMode, points: SkPoint[], paint: SkPaint): void;\n\n /** Draws arc using clip, SkMatrix, and SkPaint paint.\n\n Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus\n sweepAngle. startAngle and sweepAngle are in degrees.\n\n startAngle of zero places start point at the right middle edge of oval.\n A positive sweepAngle places arc end point clockwise from start point;\n a negative sweepAngle places arc end point counterclockwise from start point.\n sweepAngle may exceed 360 degrees, a full circle.\n If useCenter is true, draw a wedge that includes lines from oval\n center to arc end points. If useCenter is false, draw arc between end points.\n\n If SkRect oval is empty or sweepAngle is zero, nothing is drawn.\n\n @param oval SkRect bounds of oval containing arc to draw\n @param startAngle angle in degrees where arc begins\n @param sweepAngle sweep angle in degrees; positive is clockwise\n @param useCenter if true, include the center of the oval\n @param paint SkPaint stroke or fill, blend, color, and so on, used to draw\n */\n drawArc: (\n oval: SkRect,\n startAngle: number,\n sweepAngle: number,\n useCenter: boolean,\n paint: SkPaint\n ) => void;\n\n /**\n * Draws the given rectangle with rounded corners using the current clip, current matrix,\n * and the provided paint.\n * @param rrect\n * @param paint\n */\n drawRRect(rrect: SkRRect, paint: SkPaint): void;\n\n /**\n * Draws RRect outer and inner using clip, Matrix, and Paint paint.\n * outer must contain inner or the drawing is undefined.\n * @param outer\n * @param inner\n * @param paint\n */\n drawDRRect(outer: SkRRect, inner: SkRRect, paint: SkPaint): void;\n\n /**\n * Draws an oval bounded by the given rectangle using the current clip, current matrix,\n * and the provided paint.\n * @param oval\n * @param paint\n */\n drawOval(oval: SkRect, paint: SkPaint): void;\n\n /** Draws SkPath path using clip, SkMatrix, and SkPaint paint.\n SkPath contains an array of path contour, each of which may be open or closed.\n\n In paint: SkPaint::Style determines if SkRRect is stroked or filled:\n if filled, SkPath::FillType determines whether path contour describes inside or\n outside of fill; if stroked, SkPaint stroke width describes the line thickness,\n SkPaint::Cap describes line ends, and SkPaint::Join describes how\n corners are drawn.\n\n @param path SkPath to draw\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawPath\n */\n drawPath: (path: SkPath, paint: SkPaint) => void;\n\n /**\n * Draw the given text at the location (x, y) using the provided paint and font. The text will\n * be drawn as is; no shaping, left-to-right, etc.\n * @param str\n * @param x\n * @param y\n * @param paint\n * @param font\n */\n drawText(\n str: string,\n x: number,\n y: number,\n paint: SkPaint,\n font: SkFont\n ): void;\n\n /**\n * Draws the given TextBlob at (x, y) using the current clip, current matrix, and the\n * provided paint. Reminder that the fonts used to draw TextBlob are part of the blob.\n * @param blob\n * @param x\n * @param y\n * @param paint\n */\n drawTextBlob(blob: SkTextBlob, x: number, y: number, paint: SkPaint): void;\n\n /**\n * Draws a run of glyphs, at corresponding positions, in a given font.\n * @param glyphs the array of glyph IDs (Uint16TypedArray)\n * @param positions the array of x,y floats to position each glyph\n * @param x x-coordinate of the origin of the entire run\n * @param y y-coordinate of the origin of the entire run\n * @param font the font that contains the glyphs\n * @param paint\n */\n drawGlyphs(\n glyphs: number[],\n positions: SkPoint[],\n x: number,\n y: number,\n font: SkFont,\n paint: SkPaint\n ): void;\n\n /**\n * Renders the SVG Dom object to the canvas. If width/height are omitted,\n * the SVG will be rendered to fit the canvas.\n */\n drawSvg: (svgDom: SkSVG, width?: number, height?: number) => void;\n /** Saves SkMatrix and clip.\n Calling restore() discards changes to SkMatrix and clip,\n restoring the SkMatrix and clip to their state when save() was called.\n\n SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(),\n and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().\n\n Saved SkCanvas state is put on a stack; multiple calls to save() should be balance\n by an equal number of calls to restore().\n\n Call restoreToCount() with result to restore this and subsequent saves.\n\n @return depth of saved stack\n\n example: https://fiddle.skia.org/c/@Canvas_save\n */\n save: () => number;\n\n /**\n * Saves Matrix and clip, and allocates a SkBitmap for subsequent drawing.\n * Calling restore() discards changes to Matrix and clip, and draws the SkBitmap.\n * It returns the height of the stack.\n * See Canvas.h for more.\n * @param paint\n * @param bounds\n * @param backdrop\n * @param flags\n */\n saveLayer(\n paint?: SkPaint,\n bounds?: SkRect | null,\n backdrop?: SkImageFilter | null,\n flags?: SaveLayerFlag\n ): number;\n\n /** Removes changes to SkMatrix and clip since SkCanvas state was\n last saved. The state is removed from the stack.\n\n Does nothing if the stack is empty.\n\n example: https://fiddle.skia.org/c/@AutoCanvasRestore_restore\n\n example: https://fiddle.skia.org/c/@Canvas_restore\n */\n restore: () => void;\n\n /**\n * Rotates the current matrix by the number of degrees.\n * @param rot - angle of rotation in degrees.\n * @param rx\n * @param ry\n */\n rotate(rotationInDegrees: number, rx: number, ry: number): void;\n\n /**\n * Scales the current matrix by sx on the x-axis and sy on the y-axis.\n * @param sx\n * @param sy\n */\n scale(sx: number, sy: number): void;\n\n /**\n * Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx\n * skews the drawing right as y-axis values increase; a positive value of sy skews\n * the drawing down as x-axis values increase.\n * @param sx\n * @param sy\n */\n skew(sx: number, sy: number): void;\n\n /**\n * Translates Matrix by dx along the x-axis and dy along the y-axis.\n * @param dx\n * @param dy\n */\n translate(dx: number, dy: number): void;\n\n /**\n * Fills clip with the given color.\n * @param color\n * @param blendMode - defaults to SrcOver.\n */\n drawColor(color: SkColor, blendMode?: BlendMode): void;\n\n /**\n * Fills the current clip with the given color using Src BlendMode.\n * This has the effect of replacing all pixels contained by clip with color.\n * @param color\n */\n clear(color: SkColor): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and path,\n * with an aliased or anti-aliased clip edge.\n * @param path\n * @param op\n * @param doAntiAlias\n */\n clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rect,\n * with an aliased or anti-aliased clip edge.\n * @param rect\n * @param op\n * @param doAntiAlias\n */\n clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rrect,\n * with an aliased or anti-aliased clip edge.\n * @param rrect\n * @param op\n * @param doAntiAlias\n */\n clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces current matrix with m premultiplied with the existing matrix.\n * @param m\n */\n concat(m: SkMatrix): void;\n}\n"]}
|
1
|
+
{"version":3,"sources":["Canvas.ts"],"names":["ClipOp","SaveLayerFlag"],"mappings":"AAgBA,WAAYA,MAAZ;;WAAYA,M;AAAAA,EAAAA,M,CAAAA,M;AAAAA,EAAAA,M,CAAAA,M;GAAAA,M,KAAAA,M;;AAKZ,WAAYC,aAAZ;;WAAYA,a;AAAAA,EAAAA,a,CAAAA,a;AAAAA,EAAAA,a,CAAAA,a;GAAAA,a,KAAAA,a","sourcesContent":["import type { SkPaint } from \"./Paint\";\nimport type { SkRect } from \"./Rect\";\nimport type { SkFont } from \"./Font\";\nimport type { SkPath } from \"./Path\";\nimport type { SkImage, MipmapMode, FilterMode } from \"./Image\";\nimport type { SkSVG } from \"./SVG\";\nimport type { SkColor } from \"./Color\";\nimport type { SkRRect } from \"./RRect\";\nimport type { BlendMode } from \"./Paint/BlendMode\";\nimport type { SkPoint, PointMode } from \"./Point\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { SkImageFilter } from \"./ImageFilter\";\nimport type { SkVertices } from \"./Vertices\";\nimport type { SkTextBlob } from \"./TextBlob\";\nimport type { SkPicture } from \"./Picture\";\n\nexport enum ClipOp {\n Difference,\n Intersect,\n}\n\nexport enum SaveLayerFlag {\n SaveLayerInitWithPrevious = 1 << 2,\n SaveLayerF16ColorType = 1 << 4,\n}\n\nexport interface SkCanvas {\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix, and optionally-provided paint.\n * @param img\n * @param left\n * @param top\n * @param paint\n */\n drawImage: (image: SkImage, x: number, y: number, paint?: SkPaint) => void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * @param img\n * @param src\n * @param dest\n * @param paint\n * @param fastSample - if false, will filter strictly within src.\n */\n drawImageRect(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n paint: SkPaint,\n fastSample?: boolean\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param left\n * @param top\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageCubic(\n img: SkImage,\n left: number,\n top: number,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the provided sampling options if necessary.\n * @param img\n * @param left\n * @param top\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageOptions(\n img: SkImage,\n left: number,\n top: number,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the provided image stretched proportionally to fit into dst rectangle.\n * The center rectangle divides the image into nine sections: four sides, four corners, and\n * the center.\n * @param img\n * @param center\n * @param dest\n * @param filter - what technique to use when sampling the image\n * @param paint\n */\n drawImageNine(\n img: SkImage,\n center: SkRect,\n dest: SkRect,\n filter: FilterMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param src\n * @param dest\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageRectCubic(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the provided sampling options if necessary.\n * @param img\n * @param src\n * @param dest\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageRectOptions(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /** Fills clip with SkPaint paint. SkPaint components, SkShader,\n SkColorFilter, SkImageFilter, and SkBlendMode affect drawing;\n SkMaskFilter and SkPathEffect in paint are ignored.\n\n @param paint graphics state used to fill SkCanvas\n\n example: https://fiddle.skia.org/c/@Canvas_drawPaint\n */\n drawPaint: (paint: SkPaint) => void;\n\n /** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint stroke width describes the line thickness;\n SkPaint::Cap draws the end rounded or square;\n SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.\n\n @param x0 start of line segment on x-axis\n @param y0 start of line segment on y-axis\n @param x1 end of line segment on x-axis\n @param y1 end of line segment on y-axis\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawLine\n */\n drawLine: (\n x0: number,\n y0: number,\n x1: number,\n y1: number,\n paint: SkPaint\n ) => void;\n /** Draws SkRect rect using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint::Style determines if rectangle is stroked or filled;\n if stroked, SkPaint stroke width describes the line thickness, and\n SkPaint::Join draws the corners rounded or square.\n\n @param rect rectangle to draw\n @param paint stroke or fill, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawRect\n */\n drawRect: (rect: SkRect, paint: SkPaint) => void;\n\n /**\n * Draws a circle at (cx, cy) with the given radius.\n * @param cx\n * @param cy\n * @param radius\n * @param paint\n */\n drawCircle(cx: number, cy: number, radius: number, paint: SkPaint): void;\n\n /**\n * Draws the given vertices (a triangle mesh) using the current clip, current matrix, and the\n * provided paint.\n * If paint contains an Shader and vertices does not contain texCoords, the shader\n * is mapped using the vertices' positions.\n * If vertices colors are defined in vertices, and Paint paint contains Shader,\n * BlendMode mode combines vertices colors with Shader.\n * @param verts\n * @param mode\n * @param paint\n */\n drawVertices(verts: SkVertices, mode: BlendMode, paint: SkPaint): void;\n\n /**\n * Draws a cubic patch defined by 12 control points [top, right, bottom, left] with optional\n * colors and shader-coordinates [4] specifed for each corner [top-left, top-right, bottom-right, bottom-left]\n * @param cubics 12 points : 4 connected cubics specifying the boundary of the patch\n * @param colors optional colors interpolated across the patch\n * @param texs optional shader coordinates interpolated across the patch\n * @param mode Specifies how shader and colors blend (if both are specified)\n * @param paint\n */\n drawPatch(\n cubics: readonly SkPoint[],\n colors?: readonly SkColor[] | null,\n texs?: readonly SkPoint[] | null,\n mode?: BlendMode | null,\n paint?: SkPaint\n ): void;\n\n /**\n * Restores state to a previous stack value.\n * @param saveCount\n */\n restoreToCount(saveCount: number): void;\n\n /**\n * Draws the given points using the current clip, current matrix, and the provided paint.\n *\n * See Canvas.h for more on the mode and its interaction with paint.\n * @param mode\n * @param points\n * @param paint\n */\n drawPoints(mode: PointMode, points: SkPoint[], paint: SkPaint): void;\n\n /** Draws arc using clip, SkMatrix, and SkPaint paint.\n\n Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus\n sweepAngle. startAngle and sweepAngle are in degrees.\n\n startAngle of zero places start point at the right middle edge of oval.\n A positive sweepAngle places arc end point clockwise from start point;\n a negative sweepAngle places arc end point counterclockwise from start point.\n sweepAngle may exceed 360 degrees, a full circle.\n If useCenter is true, draw a wedge that includes lines from oval\n center to arc end points. If useCenter is false, draw arc between end points.\n\n If SkRect oval is empty or sweepAngle is zero, nothing is drawn.\n\n @param oval SkRect bounds of oval containing arc to draw\n @param startAngle angle in degrees where arc begins\n @param sweepAngle sweep angle in degrees; positive is clockwise\n @param useCenter if true, include the center of the oval\n @param paint SkPaint stroke or fill, blend, color, and so on, used to draw\n */\n drawArc: (\n oval: SkRect,\n startAngle: number,\n sweepAngle: number,\n useCenter: boolean,\n paint: SkPaint\n ) => void;\n\n /**\n * Draws the given rectangle with rounded corners using the current clip, current matrix,\n * and the provided paint.\n * @param rrect\n * @param paint\n */\n drawRRect(rrect: SkRRect, paint: SkPaint): void;\n\n /**\n * Draws RRect outer and inner using clip, Matrix, and Paint paint.\n * outer must contain inner or the drawing is undefined.\n * @param outer\n * @param inner\n * @param paint\n */\n drawDRRect(outer: SkRRect, inner: SkRRect, paint: SkPaint): void;\n\n /**\n * Draws an oval bounded by the given rectangle using the current clip, current matrix,\n * and the provided paint.\n * @param oval\n * @param paint\n */\n drawOval(oval: SkRect, paint: SkPaint): void;\n\n /** Draws SkPath path using clip, SkMatrix, and SkPaint paint.\n SkPath contains an array of path contour, each of which may be open or closed.\n\n In paint: SkPaint::Style determines if SkRRect is stroked or filled:\n if filled, SkPath::FillType determines whether path contour describes inside or\n outside of fill; if stroked, SkPaint stroke width describes the line thickness,\n SkPaint::Cap describes line ends, and SkPaint::Join describes how\n corners are drawn.\n\n @param path SkPath to draw\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawPath\n */\n drawPath: (path: SkPath, paint: SkPaint) => void;\n\n /**\n * Draw the given text at the location (x, y) using the provided paint and font. The text will\n * be drawn as is; no shaping, left-to-right, etc.\n * @param str\n * @param x\n * @param y\n * @param paint\n * @param font\n */\n drawText(\n str: string,\n x: number,\n y: number,\n paint: SkPaint,\n font: SkFont\n ): void;\n\n /**\n * Draws the given TextBlob at (x, y) using the current clip, current matrix, and the\n * provided paint. Reminder that the fonts used to draw TextBlob are part of the blob.\n * @param blob\n * @param x\n * @param y\n * @param paint\n */\n drawTextBlob(blob: SkTextBlob, x: number, y: number, paint: SkPaint): void;\n\n /**\n * Draws a run of glyphs, at corresponding positions, in a given font.\n * @param glyphs the array of glyph IDs (Uint16TypedArray)\n * @param positions the array of x,y floats to position each glyph\n * @param x x-coordinate of the origin of the entire run\n * @param y y-coordinate of the origin of the entire run\n * @param font the font that contains the glyphs\n * @param paint\n */\n drawGlyphs(\n glyphs: number[],\n positions: SkPoint[],\n x: number,\n y: number,\n font: SkFont,\n paint: SkPaint\n ): void;\n\n /**\n * Renders the SVG Dom object to the canvas. If width/height are omitted,\n * the SVG will be rendered to fit the canvas.\n */\n drawSvg: (svgDom: SkSVG, width?: number, height?: number) => void;\n /** Saves SkMatrix and clip.\n Calling restore() discards changes to SkMatrix and clip,\n restoring the SkMatrix and clip to their state when save() was called.\n\n SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(),\n and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().\n\n Saved SkCanvas state is put on a stack; multiple calls to save() should be balance\n by an equal number of calls to restore().\n\n Call restoreToCount() with result to restore this and subsequent saves.\n\n @return depth of saved stack\n\n example: https://fiddle.skia.org/c/@Canvas_save\n */\n save: () => number;\n\n /**\n * Saves Matrix and clip, and allocates a SkBitmap for subsequent drawing.\n * Calling restore() discards changes to Matrix and clip, and draws the SkBitmap.\n * It returns the height of the stack.\n * See Canvas.h for more.\n * @param paint\n * @param bounds\n * @param backdrop\n * @param flags\n */\n saveLayer(\n paint?: SkPaint,\n bounds?: SkRect | null,\n backdrop?: SkImageFilter | null,\n flags?: SaveLayerFlag\n ): number;\n\n /** Removes changes to SkMatrix and clip since SkCanvas state was\n last saved. The state is removed from the stack.\n\n Does nothing if the stack is empty.\n\n example: https://fiddle.skia.org/c/@AutoCanvasRestore_restore\n\n example: https://fiddle.skia.org/c/@Canvas_restore\n */\n restore: () => void;\n\n /**\n * Rotates the current matrix by the number of degrees.\n * @param rot - angle of rotation in degrees.\n * @param rx\n * @param ry\n */\n rotate(rotationInDegrees: number, rx: number, ry: number): void;\n\n /**\n * Scales the current matrix by sx on the x-axis and sy on the y-axis.\n * @param sx\n * @param sy\n */\n scale(sx: number, sy: number): void;\n\n /**\n * Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx\n * skews the drawing right as y-axis values increase; a positive value of sy skews\n * the drawing down as x-axis values increase.\n * @param sx\n * @param sy\n */\n skew(sx: number, sy: number): void;\n\n /**\n * Translates Matrix by dx along the x-axis and dy along the y-axis.\n * @param dx\n * @param dy\n */\n translate(dx: number, dy: number): void;\n\n /**\n * Fills clip with the given color.\n * @param color\n * @param blendMode - defaults to SrcOver.\n */\n drawColor(color: SkColor, blendMode?: BlendMode): void;\n\n /**\n * Fills the current clip with the given color using Src BlendMode.\n * This has the effect of replacing all pixels contained by clip with color.\n * @param color\n */\n clear(color: SkColor): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and path,\n * with an aliased or anti-aliased clip edge.\n * @param path\n * @param op\n * @param doAntiAlias\n */\n clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rect,\n * with an aliased or anti-aliased clip edge.\n * @param rect\n * @param op\n * @param doAntiAlias\n */\n clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rrect,\n * with an aliased or anti-aliased clip edge.\n * @param rrect\n * @param op\n * @param doAntiAlias\n */\n clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces current matrix with m premultiplied with the existing matrix.\n * @param m\n */\n concat(m: SkMatrix): void;\n\n /**\n * Draws the given picture using the current clip, current matrix, and the provided paint.\n * @param skp\n */\n drawPicture(skp: SkPicture): void;\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAd;AACA,cAAc,mBAAd;AACA,cAAc,cAAd;AACA,cAAc,kBAAd","sourcesContent":["export * from \"./Picture\";\nexport * from \"./PictureRecorder\";\nexport * from \"./usePicture\";\nexport * from \"./PictureFactory\";\n"]}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { useMemo } from "react";
|
2
|
+
import { Skia } from "../Skia";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Memoizes and returns an SkPicture that can be drawn to another canvas.
|
6
|
+
* @param rect Picture bounds
|
7
|
+
* @param cb Callback for drawing to the canvas
|
8
|
+
* @returns SkPicture
|
9
|
+
*/
|
10
|
+
export const usePicture = function (rect, cb) {
|
11
|
+
let deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
12
|
+
return useMemo(() => {
|
13
|
+
const recorder = Skia.PictureRecorder();
|
14
|
+
const canvas = recorder.beginRecording(rect);
|
15
|
+
cb(canvas);
|
16
|
+
return recorder.finishRecordingAsPicture(); // eslint-disable-next-line react-hooks/exhaustive-deps
|
17
|
+
}, [cb, rect, deps]);
|
18
|
+
};
|
19
|
+
//# sourceMappingURL=usePicture.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["usePicture.ts"],"names":["useMemo","Skia","usePicture","rect","cb","deps","recorder","PictureRecorder","canvas","beginRecording","finishRecordingAsPicture"],"mappings":"AACA,SAASA,OAAT,QAAwB,OAAxB;AAIA,SAASC,IAAT,QAAqB,SAArB;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAG,UACxBC,IADwB,EAExBC,EAFwB,EAIV;AAAA,MADdC,IACc,uEADS,EACT;AACd,SAAOL,OAAO,CAAC,MAAM;AACnB,UAAMM,QAAQ,GAAGL,IAAI,CAACM,eAAL,EAAjB;AACA,UAAMC,MAAM,GAAGF,QAAQ,CAACG,cAAT,CAAwBN,IAAxB,CAAf;AACAC,IAAAA,EAAE,CAACI,MAAD,CAAF;AACA,WAAOF,QAAQ,CAACI,wBAAT,EAAP,CAJmB,CAKnB;AACD,GANa,EAMX,CAACN,EAAD,EAAKD,IAAL,EAAWE,IAAX,CANW,CAAd;AAOD,CAZM","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useMemo } from \"react\";\n\nimport type { SkCanvas } from \"../Canvas\";\nimport type { SkRect } from \"../Rect\";\nimport { Skia } from \"../Skia\";\n\nimport type { SkPicture } from \"./Picture\";\n\n/**\n * Memoizes and returns an SkPicture that can be drawn to another canvas.\n * @param rect Picture bounds\n * @param cb Callback for drawing to the canvas\n * @returns SkPicture\n */\nexport const usePicture = (\n rect: SkRect,\n cb: (canvas: SkCanvas) => void,\n deps: DependencyList = []\n): SkPicture => {\n return useMemo(() => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(rect);\n cb(canvas);\n return recorder.finishRecordingAsPicture();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [cb, rect, deps]);\n};\n"]}
|
package/lib/module/skia/Skia.js
CHANGED
@@ -24,6 +24,8 @@ export const Skia = {
|
|
24
24
|
XYWHRect: SkiaApi.XYWHRect,
|
25
25
|
RRectXY: SkiaApi.RRectXY,
|
26
26
|
Paint: SkiaApi.Paint,
|
27
|
+
PictureRecorder: SkiaApi.PictureRecorder,
|
28
|
+
Picture: SkiaApi.Picture,
|
27
29
|
Path: SkiaApi.Path,
|
28
30
|
ColorFilter: SkiaApi.ColorFilter,
|
29
31
|
ContourMeasureIter: SkiaApi.ContourMeasureIter,
|