@shopify/react-native-skia 0.1.136 → 0.1.137
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -47
- package/cpp/api/JsiSkMatrix.h +12 -0
- package/lib/commonjs/renderer/components/Group.js +1 -1
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/processors/Transform.js +8 -15
- package/lib/commonjs/renderer/processors/Transform.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.js +17 -2
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.js +4 -0
- package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.js +8 -8
- package/lib/commonjs/views/SkiaView.web.js.map +1 -1
- package/lib/commonjs/web/LoadSkiaWeb.js +25 -0
- package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -0
- package/lib/commonjs/web/WithSkiaWeb.js +38 -0
- package/lib/commonjs/web/WithSkiaWeb.js.map +1 -0
- package/lib/commonjs/web/index.js +22 -12
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/module/renderer/components/Group.js +1 -1
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/processors/Transform.js +8 -15
- package/lib/module/renderer/processors/Transform.js.map +1 -1
- package/lib/module/skia/types/Matrix.js +11 -1
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/web/JsiSkMatrix.js +4 -0
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/module/views/SkiaView.web.js +8 -8
- package/lib/module/views/SkiaView.web.js.map +1 -1
- package/lib/module/web/LoadSkiaWeb.js +12 -0
- package/lib/module/web/LoadSkiaWeb.js.map +1 -0
- package/lib/module/web/WithSkiaWeb.js +22 -0
- package/lib/module/web/WithSkiaWeb.js.map +1 -0
- package/lib/module/web/index.js +2 -9
- package/lib/module/web/index.js.map +1 -1
- package/lib/typescript/src/renderer/processors/Transform.d.ts +2 -2
- package/lib/typescript/src/skia/types/Matrix.d.ts +5 -1
- package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -0
- package/lib/typescript/src/views/SkiaView.web.d.ts +2 -2
- package/lib/typescript/src/web/LoadSkiaWeb.d.ts +6 -0
- package/lib/typescript/src/web/WithSkiaWeb.d.ts +10 -0
- package/lib/typescript/src/web/index.d.ts +2 -5
- package/package.json +5 -1
- package/scripts/setup-canvaskit.js +74 -0
- package/src/renderer/components/Group.tsx +1 -1
- package/src/renderer/processors/Transform.ts +7 -10
- package/src/skia/types/Matrix.ts +18 -2
- package/src/skia/web/JsiSkMatrix.ts +4 -0
- package/src/views/SkiaView.web.tsx +8 -8
- package/src/web/LoadSkiaWeb.tsx +18 -0
- package/src/web/WithSkiaWeb.tsx +32 -0
- package/src/web/index.ts +2 -15
package/README.md
CHANGED
@@ -1,52 +1,9 @@
|
|
1
1
|
# React Native Skia
|
2
2
|
|
3
|
-
|
4
|
-
Skia serves as the graphics engine for Google Chrome and Chrome OS, Android, Flutter, Mozilla Firefox, Firefox OS, and many other products.
|
3
|
+
High-performance 2d Graphics for React Native using Skia
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
```sh
|
9
|
-
yarn add @shopify/react-native-skia
|
10
|
-
```
|
11
|
-
|
12
|
-
Or using npm:
|
13
|
-
|
14
|
-
```sh
|
15
|
-
npm install @shopify/react-native-skia
|
16
|
-
```
|
17
|
-
|
18
|
-
## iOS
|
19
|
-
|
20
|
-
Run `pod install` on the `ios/` directory.
|
21
|
-
|
22
|
-
## Android
|
23
|
-
|
24
|
-
> **Version compatibility**: `react-native@>=0.66` is required.
|
25
|
-
|
26
|
-
Currently, you will need Android NDK to be installed.
|
27
|
-
If you have Android Studio installed, make sure `$ANDROID_NDK` is available.
|
28
|
-
`ANDROID_NDK=/Users/username/Library/Android/sdk/ndk-bundle` for instance.
|
5
|
+
<img width="400" alt="skia" src="https://user-images.githubusercontent.com/306134/146549218-b7959ad9-0107-4c1c-b439-b96c780f5230.png">
|
29
6
|
|
30
|
-
|
31
|
-
|
32
|
-
And then the _SDK Location_ section. It will show you the NDK path, or the option to download it if you don't have it installed.
|
33
|
-
|
34
|
-
### Proguard
|
35
|
-
|
36
|
-
If you're using Proguard, make sure to add the following rule:
|
37
|
-
|
38
|
-
```
|
39
|
-
-keep class com.shopify.reactnative.skia.** { *; }
|
40
|
-
```
|
41
|
-
|
42
|
-
## Playground
|
43
|
-
|
44
|
-
We have an example project you can play with [here](https://github.com/Shopify/react-native-skia/tree/main/example).
|
45
|
-
|
46
|
-
```sh
|
47
|
-
yarn
|
48
|
-
cd package && yarn && cd ..
|
49
|
-
cd example && yarn && yarn start
|
50
|
-
```
|
7
|
+
Checkout the full documentation [here](https://shopify.github.io/react-native-skia).
|
51
8
|
|
52
|
-
|
9
|
+
Documentation on the library development is available [here](https://github.com/Shopify/react-native-skia#library-development).
|
package/cpp/api/JsiSkMatrix.h
CHANGED
@@ -46,6 +46,10 @@ public:
|
|
46
46
|
);
|
47
47
|
}
|
48
48
|
|
49
|
+
JSI_PROPERTY_GET(__typename__) {
|
50
|
+
return jsi::String::createFromUtf8(runtime, "Matrix");
|
51
|
+
}
|
52
|
+
|
49
53
|
JSI_HOST_FUNCTION(concat) {
|
50
54
|
auto m3 = JsiSkMatrix::fromValue(runtime, arguments[0]);
|
51
55
|
getObject()->preConcat(*m3);
|
@@ -78,6 +82,13 @@ public:
|
|
78
82
|
getObject()->preRotate(SkRadiansToDegrees(a));
|
79
83
|
return jsi::Value::undefined();
|
80
84
|
}
|
85
|
+
|
86
|
+
JSI_HOST_FUNCTION(identity) {
|
87
|
+
getObject()->setIdentity();
|
88
|
+
return jsi::Value::undefined();
|
89
|
+
}
|
90
|
+
|
91
|
+
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkMatrix, __typename__))
|
81
92
|
|
82
93
|
JSI_EXPORT_FUNCTIONS(
|
83
94
|
JSI_EXPORT_FUNC(JsiSkMatrix, concat),
|
@@ -85,6 +96,7 @@ public:
|
|
85
96
|
JSI_EXPORT_FUNC(JsiSkMatrix, scale),
|
86
97
|
JSI_EXPORT_FUNC(JsiSkMatrix, skew),
|
87
98
|
JSI_EXPORT_FUNC(JsiSkMatrix, rotate),
|
99
|
+
JSI_EXPORT_FUNC(JsiSkMatrix, identity),
|
88
100
|
)
|
89
101
|
|
90
102
|
/**
|
@@ -55,7 +55,7 @@ const onDraw = (0, _nodes.createDrawing)((ctx, _ref, node) => {
|
|
55
55
|
canvas.save();
|
56
56
|
}
|
57
57
|
|
58
|
-
(0, _processors.processCanvasTransform)(
|
58
|
+
(0, _processors.processCanvasTransform)(canvas, groupProps);
|
59
59
|
|
60
60
|
if (clip) {
|
61
61
|
const op = invertClip ? _types.ClipOp.Difference : _types.ClipOp.Intersect;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Group.tsx"],"names":["isSkPaint","obj","__typename__","onDraw","ctx","node","layer","clip","invertClip","groupProps","canvas","opacity","Skia","declarations","children","filter","isDeclarationNode","map","child","draw","drawings","DrawingNode","paint","copy","hasTransform","transform","matrix","hasClip","shouldSave","saveLayer","current","undefined","save","op","ClipOp","Difference","Intersect","visit","restore","Group","props"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AAWA;;AACA;;;;;;AAEA,MAAMA,SAAS,GAAIC,GAAD,IAChB,kBAAkBA,GAAlB,IAAyBA,GAAG,CAACC,YAAJ,KAAqB,OADhD;;AASA,MAAMC,MAAM,GAAG,0BACb,CAACC,GAAD,QAAkDC,IAAlD,KAA2D;AAAA,MAArD;AAAEC,IAAAA,KAAF;AAASC,IAAAA,IAAT;AAAeC,IAAAA,UAAf;AAA2B,OAAGC;AAA9B,GAAqD;AACzD,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,OAAV;AAAmBC,IAAAA;AAAnB,MAA4BR,GAAlC;AACA,QAAMS,YAAY,GAAGR,IAAI,CAACS,QAAL,CAClBC,MADkB,CACXC,8BADW,EAElBC,GAFkB,CAEbC,KAAD,IAAWA,KAAK,CAACC,IAAN,CAAWf,GAAX,CAFG,CAArB;AAIA,QAAMgB,QAAQ,GAAGf,IAAI,CAACS,QAAL,CAAcC,MAAd,CACdG,KAAD,IAAWA,KAAK,YAAYG,kBADb,CAAjB;AAGA,QAAMC,KAAK,GAAG,8BACZlB,GAAG,CAACQ,IADQ,EAEZR,GAAG,CAACkB,KAAJ,CAAUC,IAAV,EAFY,EAGZZ,OAHY,EAIZF,UAJY,EAKZI,YALY,CAAd;AAOA,QAAMW,YAAY,GAAG,CAAC,CAACf,UAAU,CAACgB,SAAb,IAA0B,CAAC,CAAChB,UAAU,CAACiB,MAA5D;AACA,QAAMC,OAAO,GAAG,CAAC,CAACpB,IAAlB;AACA,QAAMqB,UAAU,GAAGJ,YAAY,IAAIG,OAAhB,IAA2B,CAAC,CAACrB,KAAhD;;AACA,MAAIsB,UAAJ,EAAgB;AACd,QAAItB,KAAJ,EAAW;AACT,UAAI,OAAOA,KAAP,KAAiB,SAArB,EAAgC;AAC9BI,QAAAA,MAAM,CAACmB,SAAP;AACD,OAFD,MAEO,IAAI7B,SAAS,CAACM,KAAD,CAAb,EAAsB;AAC3BI,QAAAA,MAAM,CAACmB,SAAP,CAAiBvB,KAAjB;AACD,OAFM,MAEA;AAAA;;AACLI,QAAAA,MAAM,CAACmB,SAAP,mBAAiBvB,KAAK,CAACwB,OAAvB,2DAAkCC,SAAlC;AACD;AACF,KARD,MAQO;AACLrB,MAAAA,MAAM,CAACsB,IAAP;AACD;;AACD,
|
1
|
+
{"version":3,"sources":["Group.tsx"],"names":["isSkPaint","obj","__typename__","onDraw","ctx","node","layer","clip","invertClip","groupProps","canvas","opacity","Skia","declarations","children","filter","isDeclarationNode","map","child","draw","drawings","DrawingNode","paint","copy","hasTransform","transform","matrix","hasClip","shouldSave","saveLayer","current","undefined","save","op","ClipOp","Difference","Intersect","visit","restore","Group","props"],"mappings":";;;;;;;AAAA;;AAIA;;AACA;;AAWA;;AACA;;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A;AAAA;;AACLI,QAAAA,MAAM,CAACmB,SAAP,mBAAiBvB,KAAK,CAACwB,OAAvB,2DAAkCC,SAAlC;AACD;AACF,KARD,MAQO;AACLrB,MAAAA,MAAM,CAACsB,IAAP;AACD;;AACD,4CAAuBtB,MAAvB,EAA+BD,UAA/B;;AACA,QAAIF,IAAJ,EAAU;AACR,YAAM0B,EAAE,GAAGzB,UAAU,GAAG0B,cAAOC,UAAV,GAAuBD,cAAOE,SAAnD;AACA,mCAAYxB,IAAZ,EAAkBF,MAAlB,EAA0BH,IAA1B,EAAgC0B,EAAhC;AACD;AACF;;AACD5B,EAAAA,IAAI,CAACgC,KAAL,CACE,EACE,GAAGjC,GADL;AAEEkB,IAAAA,KAFF;AAGEX,IAAAA,OAAO,EAAEF,UAAU,CAACE,OAAX,GAAqBF,UAAU,CAACE,OAAX,GAAqBA,OAA1C,GAAoDA;AAH/D,GADF,EAMES,QANF;;AAQA,MAAIQ,UAAJ,EAAgB;AACdlB,IAAAA,MAAM,CAAC4B,OAAP;AACD;AACF,CAjDY,CAAf;;AAoDO,MAAMC,KAAK,GAAIC,KAAD,IAAsC;AACzD,sBAAO;AAAW,IAAA,MAAM,EAAErC;AAAnB,KAA+BqC,KAA/B;AAAsC,IAAA,cAAc;AAApD,KAAP;AACD,CAFM","sourcesContent":["import React from \"react\";\nimport type { RefObject } from \"react\";\n\nimport type { SkPaint } from \"../../skia/types\";\nimport { ClipOp } from \"../../skia/types\";\nimport {\n processCanvasTransform,\n processPaint,\n processClip,\n} from \"../processors\";\nimport type {\n CustomPaintProps,\n TransformProps,\n AnimatedProps,\n ClipDef,\n} from \"../processors\";\nimport { createDrawing, DrawingNode } from \"../nodes\";\nimport { isDeclarationNode } from \"../nodes/Declaration\";\n\nconst isSkPaint = (obj: RefObject<SkPaint> | SkPaint): obj is SkPaint =>\n \"__typename__\" in obj && obj.__typename__ === \"Paint\";\n\nexport interface GroupProps extends CustomPaintProps, TransformProps {\n clip?: ClipDef;\n invertClip?: boolean;\n layer?: RefObject<SkPaint> | SkPaint | boolean;\n}\n\nconst onDraw = createDrawing<GroupProps>(\n (ctx, { layer, clip, invertClip, ...groupProps }, node) => {\n const { canvas, opacity, Skia } = ctx;\n const declarations = node.children\n .filter(isDeclarationNode)\n .map((child) => child.draw(ctx));\n\n const drawings = node.children.filter(\n (child) => child instanceof DrawingNode\n );\n const paint = processPaint(\n ctx.Skia,\n ctx.paint.copy(),\n opacity,\n groupProps,\n declarations\n );\n const hasTransform = !!groupProps.transform || !!groupProps.matrix;\n const hasClip = !!clip;\n const shouldSave = hasTransform || hasClip || !!layer;\n if (shouldSave) {\n if (layer) {\n if (typeof layer === \"boolean\") {\n canvas.saveLayer();\n } else if (isSkPaint(layer)) {\n canvas.saveLayer(layer);\n } else {\n canvas.saveLayer(layer.current ?? undefined);\n }\n } else {\n canvas.save();\n }\n processCanvasTransform(canvas, groupProps);\n if (clip) {\n const op = invertClip ? ClipOp.Difference : ClipOp.Intersect;\n processClip(Skia, canvas, clip, op);\n }\n }\n node.visit(\n {\n ...ctx,\n paint,\n opacity: groupProps.opacity ? groupProps.opacity * opacity : opacity,\n },\n drawings\n );\n if (shouldSave) {\n canvas.restore();\n }\n }\n);\n\nexport const Group = (props: AnimatedProps<GroupProps>) => {\n return <skDrawing onDraw={onDraw} {...props} skipProcessing />;\n};\n"]}
|
@@ -7,40 +7,33 @@ exports.transformOrigin = exports.processCanvasTransform = exports.localMatrix =
|
|
7
7
|
|
8
8
|
var _types = require("../../skia/types");
|
9
9
|
|
10
|
-
const processCanvasTransform = (
|
11
|
-
let {
|
12
|
-
canvas,
|
13
|
-
Skia
|
14
|
-
} = _ref;
|
10
|
+
const processCanvasTransform = (canvas, _ref) => {
|
15
11
|
let {
|
16
12
|
transform,
|
17
13
|
origin,
|
18
14
|
matrix
|
19
|
-
} =
|
15
|
+
} = _ref;
|
20
16
|
|
21
17
|
if (matrix) {
|
22
18
|
if (origin) {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
m3.translate(-origin.x, -origin.y);
|
27
|
-
canvas.concat(m3);
|
19
|
+
canvas.translate(origin.x, origin.y);
|
20
|
+
canvas.concat(matrix);
|
21
|
+
canvas.translate(-origin.x, -origin.y);
|
28
22
|
} else {
|
29
23
|
canvas.concat(matrix);
|
30
24
|
}
|
31
25
|
} else if (transform) {
|
32
|
-
|
33
|
-
canvas.concat(m3);
|
26
|
+
(0, _types.processTransform)(canvas, origin ? transformOrigin(origin, transform) : transform);
|
34
27
|
}
|
35
28
|
};
|
36
29
|
|
37
30
|
exports.processCanvasTransform = processCanvasTransform;
|
38
31
|
|
39
|
-
const localMatrix = (m,
|
32
|
+
const localMatrix = (m, _ref2) => {
|
40
33
|
let {
|
41
34
|
transform,
|
42
35
|
origin
|
43
|
-
} =
|
36
|
+
} = _ref2;
|
44
37
|
|
45
38
|
if (transform) {
|
46
39
|
return (0, _types.processTransform)(m, origin ? transformOrigin(origin, transform) : transform);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Transform.ts"],"names":["processCanvasTransform","canvas","
|
1
|
+
{"version":3,"sources":["Transform.ts"],"names":["processCanvasTransform","canvas","transform","origin","matrix","translate","x","y","concat","transformOrigin","localMatrix","m","undefined","translateX","translateY"],"mappings":";;;;;;;AACA;;AASO,MAAMA,sBAAsB,GAAG,CACpCC,MADoC,WAGjC;AAAA,MADH;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,MAAb;AAAqBC,IAAAA;AAArB,GACG;;AACH,MAAIA,MAAJ,EAAY;AACV,QAAID,MAAJ,EAAY;AACVF,MAAAA,MAAM,CAACI,SAAP,CAAiBF,MAAM,CAACG,CAAxB,EAA2BH,MAAM,CAACI,CAAlC;AACAN,MAAAA,MAAM,CAACO,MAAP,CAAcJ,MAAd;AACAH,MAAAA,MAAM,CAACI,SAAP,CAAiB,CAACF,MAAM,CAACG,CAAzB,EAA4B,CAACH,MAAM,CAACI,CAApC;AACD,KAJD,MAIO;AACLN,MAAAA,MAAM,CAACO,MAAP,CAAcJ,MAAd;AACD;AACF,GARD,MAQO,IAAIF,SAAJ,EAAe;AACpB,iCACED,MADF,EAEEE,MAAM,GAAGM,eAAe,CAACN,MAAD,EAASD,SAAT,CAAlB,GAAwCA,SAFhD;AAID;AACF,CAlBM;;;;AAoBA,MAAMQ,WAAW,GAAG,CACzBC,CADyB,YAGtB;AAAA,MADH;AAAET,IAAAA,SAAF;AAAaC,IAAAA;AAAb,GACG;;AACH,MAAID,SAAJ,EAAe;AACb,WAAO,6BACLS,CADK,EAELR,MAAM,GAAGM,eAAe,CAACN,MAAD,EAASD,SAAT,CAAlB,GAAwCA,SAFzC,CAAP;AAID;;AACD,SAAOU,SAAP;AACD,CAXM;;;;AAaA,MAAMH,eAAe,GAAG,CAACN,MAAD,EAAiBD,SAAjB,KAA6C,CAC1E;AAAEW,EAAAA,UAAU,EAAEV,MAAM,CAACG;AAArB,CAD0E,EAE1E;AAAEQ,EAAAA,UAAU,EAAEX,MAAM,CAACI;AAArB,CAF0E,EAG1E,GAAGL,SAHuE,EAI1E;AAAEW,EAAAA,UAAU,EAAE,CAACV,MAAM,CAACG;AAAtB,CAJ0E,EAK1E;AAAEQ,EAAAA,UAAU,EAAE,CAACX,MAAM,CAACI;AAAtB,CAL0E,CAArE","sourcesContent":["import type { SkMatrix, Vector, Transforms2d } from \"../../skia/types\";\nimport { processTransform } from \"../../skia/types\";\nimport type { SkCanvas } from \"../../skia/types/Canvas\";\n\nexport interface TransformProps {\n transform?: Transforms2d;\n origin?: Vector;\n matrix?: SkMatrix;\n}\n\nexport const processCanvasTransform = (\n canvas: SkCanvas,\n { transform, origin, matrix }: TransformProps\n) => {\n if (matrix) {\n if (origin) {\n canvas.translate(origin.x, origin.y);\n canvas.concat(matrix);\n canvas.translate(-origin.x, -origin.y);\n } else {\n canvas.concat(matrix);\n }\n } else if (transform) {\n processTransform(\n canvas,\n origin ? transformOrigin(origin, transform) : transform\n );\n }\n};\n\nexport const localMatrix = (\n m: SkMatrix,\n { transform, origin }: TransformProps\n) => {\n if (transform) {\n return processTransform(\n m,\n origin ? transformOrigin(origin, transform) : transform\n );\n }\n return undefined;\n};\n\nexport const transformOrigin = (origin: Vector, transform: Transforms2d) => [\n { translateX: origin.x },\n { translateY: origin.y },\n ...transform,\n { translateX: -origin.x },\n { translateY: -origin.y },\n];\n"]}
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.processTransform = exports.MatrixIndex = void 0;
|
6
|
+
exports.toDegrees = exports.processTransform = exports.isMatrix = exports.MatrixIndex = void 0;
|
7
7
|
let MatrixIndex;
|
8
8
|
exports.MatrixIndex = MatrixIndex;
|
9
9
|
|
@@ -19,6 +19,10 @@ exports.MatrixIndex = MatrixIndex;
|
|
19
19
|
MatrixIndex[MatrixIndex["persp2"] = 8] = "persp2";
|
20
20
|
})(MatrixIndex || (exports.MatrixIndex = MatrixIndex = {}));
|
21
21
|
|
22
|
+
const isMatrix = obj => obj !== null && obj.__typename__ === "Matrix";
|
23
|
+
|
24
|
+
exports.isMatrix = isMatrix;
|
25
|
+
|
22
26
|
const processTransform = (m, transforms) => {
|
23
27
|
for (const transform of transforms) {
|
24
28
|
const key = Object.keys(transform)[0];
|
@@ -60,7 +64,12 @@ const processTransform = (m, transforms) => {
|
|
60
64
|
}
|
61
65
|
|
62
66
|
if (key === "rotate" || key === "rotateZ") {
|
63
|
-
m
|
67
|
+
if (isMatrix(m)) {
|
68
|
+
m.rotate(value);
|
69
|
+
} else {
|
70
|
+
m.rotate(toDegrees(value), 0, 0);
|
71
|
+
}
|
72
|
+
|
64
73
|
continue;
|
65
74
|
}
|
66
75
|
|
@@ -75,4 +84,10 @@ exports.processTransform = processTransform;
|
|
75
84
|
const exhaustiveCheck = a => {
|
76
85
|
throw new Error(`Unknown transformation: ${a}`);
|
77
86
|
};
|
87
|
+
|
88
|
+
const toDegrees = rad => {
|
89
|
+
return rad * 180 / Math.PI;
|
90
|
+
};
|
91
|
+
|
92
|
+
exports.toDegrees = toDegrees;
|
78
93
|
//# sourceMappingURL=Matrix.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Matrix.ts"],"names":["MatrixIndex","processTransform","m","transforms","transform","key","Object","keys","value","translate","scale","skew","rotate","exhaustiveCheck","a","Error"],"mappings":";;;;;;
|
1
|
+
{"version":3,"sources":["Matrix.ts"],"names":["MatrixIndex","isMatrix","obj","__typename__","processTransform","m","transforms","transform","key","Object","keys","value","translate","scale","skew","rotate","toDegrees","exhaustiveCheck","a","Error","rad","Math","PI"],"mappings":";;;;;;IAEYA,W;;;WAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;AAAAA,EAAAA,W,CAAAA,W;GAAAA,W,2BAAAA,W;;AAYL,MAAMC,QAAQ,GAAIC,GAAD,IACtBA,GAAG,KAAK,IAAR,IAAiBA,GAAD,CAA+BC,YAA/B,KAAgD,QAD3D;;;;AA0CA,MAAMC,gBAAgB,GAAG,CAC9BC,CAD8B,EAE9BC,UAF8B,KAG3B;AACH,OAAK,MAAMC,SAAX,IAAwBD,UAAxB,EAAoC;AAClC,UAAME,GAAG,GAAGC,MAAM,CAACC,IAAP,CAAYH,SAAZ,EAAuB,CAAvB,CAAZ;AACA,UAAMI,KAAK,GAAIJ,SAAD,CAAiDC,GAAjD,CAAd;;AACA,QAAIA,GAAG,KAAK,YAAZ,EAA0B;AACxBH,MAAAA,CAAC,CAACO,SAAF,CAAYD,KAAZ,EAAmB,CAAnB;AACA;AACD;;AACD,QAAIH,GAAG,KAAK,YAAZ,EAA0B;AACxBH,MAAAA,CAAC,CAACO,SAAF,CAAY,CAAZ,EAAeD,KAAf;AACA;AACD;;AACD,QAAIH,GAAG,KAAK,OAAZ,EAAqB;AACnBH,MAAAA,CAAC,CAACQ,KAAF,CAAQF,KAAR,EAAeA,KAAf;AACA;AACD;;AACD,QAAIH,GAAG,KAAK,QAAZ,EAAsB;AACpBH,MAAAA,CAAC,CAACQ,KAAF,CAAQF,KAAR,EAAe,CAAf;AACA;AACD;;AACD,QAAIH,GAAG,KAAK,QAAZ,EAAsB;AACpBH,MAAAA,CAAC,CAACQ,KAAF,CAAQ,CAAR,EAAWF,KAAX;AACA;AACD;;AACD,QAAIH,GAAG,KAAK,OAAZ,EAAqB;AACnBH,MAAAA,CAAC,CAACS,IAAF,CAAOH,KAAP,EAAc,CAAd;AACA;AACD;;AACD,QAAIH,GAAG,KAAK,OAAZ,EAAqB;AACnBH,MAAAA,CAAC,CAACS,IAAF,CAAO,CAAP,EAAUH,KAAV;AACA;AACD;;AACD,QAAIH,GAAG,KAAK,QAAR,IAAoBA,GAAG,KAAK,SAAhC,EAA2C;AACzC,UAAIP,QAAQ,CAACI,CAAD,CAAZ,EAAiB;AACfA,QAAAA,CAAC,CAACU,MAAF,CAASJ,KAAT;AACD,OAFD,MAEO;AACLN,QAAAA,CAAC,CAACU,MAAF,CAASC,SAAS,CAACL,KAAD,CAAlB,EAA2B,CAA3B,EAA8B,CAA9B;AACD;;AACD;AACD;;AACDM,IAAAA,eAAe,CAACT,GAAD,CAAf;AACD;;AACD,SAAOH,CAAP;AACD,CA9CM;;;;AAgDP,MAAMY,eAAe,GAAIC,CAAD,IAAqB;AAC3C,QAAM,IAAIC,KAAJ,CAAW,2BAA0BD,CAAE,EAAvC,CAAN;AACD,CAFD;;AAIO,MAAMF,SAAS,GAAII,GAAD,IAAiB;AACxC,SAAQA,GAAG,GAAG,GAAP,GAAcC,IAAI,CAACC,EAA1B;AACD,CAFM","sourcesContent":["import type { SkJSIInstance } from \"./JsiInstance\";\nimport type { SkCanvas } from \"./Canvas\";\nexport enum MatrixIndex {\n ScaleX = 0,\n SkewX = 1,\n TransX = 2,\n SkewY = 3,\n ScaleY = 4,\n TransY = 5,\n Persp0 = 6,\n Persp1 = 7,\n persp2 = 8,\n}\n\nexport const isMatrix = (obj: unknown): obj is SkMatrix =>\n obj !== null && (obj as SkJSIInstance<string>).__typename__ === \"Matrix\";\n\nexport interface SkMatrix extends SkJSIInstance<\"Matrix\"> {\n concat: (matrix: SkMatrix) => void;\n translate: (x: number, y: number) => void;\n scale: (x: number, y?: number) => void;\n skew: (x: number, y: number) => void;\n rotate: (theta: number) => void;\n identity: () => void;\n}\n\ntype Transform2dName =\n | \"translateX\"\n | \"translateY\"\n | \"scale\"\n | \"skewX\"\n | \"skewY\"\n | \"scaleX\"\n | \"scaleY\"\n | \"rotateZ\"\n | \"rotate\";\n\ntype Transformations = {\n readonly [Name in Transform2dName]: number;\n};\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\nexport interface TransformProp {\n transform?: Transforms2d;\n}\n\nexport const processTransform = <T extends SkMatrix | SkCanvas>(\n m: T,\n transforms: Transforms2d\n) => {\n for (const transform of transforms) {\n const key = Object.keys(transform)[0] as Transform2dName;\n const value = (transform as Pick<Transformations, typeof key>)[key];\n if (key === \"translateX\") {\n m.translate(value, 0);\n continue;\n }\n if (key === \"translateY\") {\n m.translate(0, value);\n continue;\n }\n if (key === \"scale\") {\n m.scale(value, value);\n continue;\n }\n if (key === \"scaleX\") {\n m.scale(value, 1);\n continue;\n }\n if (key === \"scaleY\") {\n m.scale(1, value);\n continue;\n }\n if (key === \"skewX\") {\n m.skew(value, 0);\n continue;\n }\n if (key === \"skewY\") {\n m.skew(0, value);\n continue;\n }\n if (key === \"rotate\" || key === \"rotateZ\") {\n if (isMatrix(m)) {\n m.rotate(value);\n } else {\n m.rotate(toDegrees(value), 0, 0);\n }\n continue;\n }\n exhaustiveCheck(key);\n }\n return m;\n};\n\nconst exhaustiveCheck = (a: never): never => {\n throw new Error(`Unknown transformation: ${a}`);\n};\n\nexport const toDegrees = (rad: number) => {\n return (rad * 180) / Math.PI;\n};\n"]}
|
@@ -32,6 +32,10 @@ class JsiSkMatrix extends _Host.HostObject {
|
|
32
32
|
this.concat(new JsiSkMatrix(this.CanvasKit, Float32Array.of(...this.CanvasKit.Matrix.rotated(value))));
|
33
33
|
}
|
34
34
|
|
35
|
+
identity() {
|
36
|
+
this.ref.set(this.CanvasKit.Matrix.identity());
|
37
|
+
}
|
38
|
+
|
35
39
|
}
|
36
40
|
|
37
41
|
exports.JsiSkMatrix = JsiSkMatrix;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["JsiSkMatrix.ts"],"names":["JsiSkMatrix","HostObject","constructor","CanvasKit","ref","concat","matrix","set","Matrix","multiply","translate","x","y","Float32Array","of","translated","scale","scaled","skew","skewed","rotate","value","rotated"],"mappings":";;;;;;;AAIA;;AAEO,MAAMA,WAAN,SACGC,gBADH,CAGP;AACEC,EAAAA,WAAW,CAACC,SAAD,EAAuBC,GAAvB,EAAuC;AAChD,UAAMD,SAAN,EAAiBC,GAAjB,EAAsB,QAAtB;AACD;;AAEDC,EAAAA,MAAM,CAACC,MAAD,EAAmB;AACvB,SAAKF,GAAL,CAASG,GAAT,CAAa,KAAKJ,SAAL,CAAeK,MAAf,CAAsBC,QAAtB,CAA+B,KAAKL,GAApC,EAAyC,mBAAQE,MAAR,CAAzC,CAAb;AACD;;AAEDI,EAAAA,SAAS,CAACC,CAAD,EAAYC,CAAZ,EAAuB;AAC9B,SAAKP,MAAL,CACE,IAAIL,WAAJ,CACE,KAAKG,SADP,EAEEU,YAAY,CAACC,EAAb,CAAgB,GAAG,KAAKX,SAAL,CAAeK,MAAf,CAAsBO,UAAtB,CAAiCJ,CAAjC,EAAoCC,CAApC,CAAnB,CAFF,CADF;AAMD;;AAEDI,EAAAA,KAAK,CAACL,CAAD,EAAYC,CAAZ,EAAwB;AAC3B,SAAKP,MAAL,CACE,IAAIL,WAAJ,CACE,KAAKG,SADP,EAEEU,YAAY,CAACC,EAAb,CAAgB,GAAG,KAAKX,SAAL,CAAeK,MAAf,CAAsBS,MAAtB,CAA6BN,CAA7B,EAAgCC,CAAhC,aAAgCA,CAAhC,cAAgCA,CAAhC,GAAqCD,CAArC,CAAnB,CAFF,CADF;AAMD;;AAEDO,EAAAA,IAAI,CAACP,CAAD,EAAYC,CAAZ,EAAuB;AACzB,SAAKP,MAAL,CACE,IAAIL,WAAJ,CACE,KAAKG,SADP,EAEEU,YAAY,CAACC,EAAb,CAAgB,GAAG,KAAKX,SAAL,CAAeK,MAAf,CAAsBW,MAAtB,CAA6BR,CAA7B,EAAgCC,CAAhC,CAAnB,CAFF,CADF;AAMD;;AAEDQ,EAAAA,MAAM,CAACC,KAAD,EAAgB;AACpB,SAAKhB,MAAL,CACE,IAAIL,WAAJ,CACE,KAAKG,SADP,EAEEU,YAAY,CAACC,EAAb,CAAgB,GAAG,KAAKX,SAAL,CAAeK,MAAf,CAAsBc,OAAtB,CAA8BD,KAA9B,CAAnB,CAFF,CADF;AAMD;;
|
1
|
+
{"version":3,"sources":["JsiSkMatrix.ts"],"names":["JsiSkMatrix","HostObject","constructor","CanvasKit","ref","concat","matrix","set","Matrix","multiply","translate","x","y","Float32Array","of","translated","scale","scaled","skew","skewed","rotate","value","rotated","identity"],"mappings":";;;;;;;AAIA;;AAEO,MAAMA,WAAN,SACGC,gBADH,CAGP;AACEC,EAAAA,WAAW,CAACC,SAAD,EAAuBC,GAAvB,EAAuC;AAChD,UAAMD,SAAN,EAAiBC,GAAjB,EAAsB,QAAtB;AACD;;AAEDC,EAAAA,MAAM,CAACC,MAAD,EAAmB;AACvB,SAAKF,GAAL,CAASG,GAAT,CAAa,KAAKJ,SAAL,CAAeK,MAAf,C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Matrix3x3 } from \"canvaskit-wasm\";\n\nimport type { SkMatrix } from \"../types\";\n\nimport { HostObject, toValue } from \"./Host\";\n\nexport class JsiSkMatrix\n extends HostObject<Matrix3x3, \"Matrix\">\n implements SkMatrix\n{\n constructor(CanvasKit: CanvasKit, ref: Matrix3x3) {\n super(CanvasKit, ref, \"Matrix\");\n }\n\n concat(matrix: SkMatrix) {\n this.ref.set(this.CanvasKit.Matrix.multiply(this.ref, toValue(matrix)));\n }\n\n translate(x: number, y: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.translated(x, y))\n )\n );\n }\n\n scale(x: number, y?: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.scaled(x, y ?? x))\n )\n );\n }\n\n skew(x: number, y: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.skewed(x, y))\n )\n );\n }\n\n rotate(value: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.rotated(value))\n )\n );\n }\n\n identity() {\n this.ref.set(this.CanvasKit.Matrix.identity());\n }\n}\n"]}
|
@@ -66,7 +66,7 @@ class SkiaView extends _react.default.Component {
|
|
66
66
|
|
67
67
|
if (this._surface) {
|
68
68
|
this._canvas = this._surface.getCanvas();
|
69
|
-
this.
|
69
|
+
this.redraw();
|
70
70
|
}
|
71
71
|
}
|
72
72
|
});
|
@@ -74,7 +74,7 @@ class SkiaView extends _react.default.Component {
|
|
74
74
|
|
75
75
|
componentDidMount() {
|
76
76
|
// Start render loop
|
77
|
-
this.
|
77
|
+
this.tick();
|
78
78
|
}
|
79
79
|
|
80
80
|
componentWillUnmount() {
|
@@ -100,7 +100,7 @@ class SkiaView extends _react.default.Component {
|
|
100
100
|
*/
|
101
101
|
|
102
102
|
|
103
|
-
|
103
|
+
tick() {
|
104
104
|
if (this._mode === "continuous" || this._redrawRequests > 0) {
|
105
105
|
this._redrawRequests = 0;
|
106
106
|
|
@@ -122,11 +122,11 @@ class SkiaView extends _react.default.Component {
|
|
122
122
|
|
123
123
|
|
124
124
|
if (!this._unmounted) {
|
125
|
-
requestAnimationFrame(this.
|
125
|
+
requestAnimationFrame(this.tick.bind(this));
|
126
126
|
}
|
127
127
|
}
|
128
128
|
|
129
|
-
|
129
|
+
redraw() {
|
130
130
|
this._redrawRequests++;
|
131
131
|
}
|
132
132
|
/**
|
@@ -142,7 +142,7 @@ class SkiaView extends _react.default.Component {
|
|
142
142
|
|
143
143
|
setDrawMode(mode) {
|
144
144
|
this._mode = mode;
|
145
|
-
this.
|
145
|
+
this.tick();
|
146
146
|
}
|
147
147
|
/**
|
148
148
|
* Registers one or move values as a dependant value of the Skia View. The view will
|
@@ -157,7 +157,7 @@ class SkiaView extends _react.default.Component {
|
|
157
157
|
|
158
158
|
_values.forEach(v => {
|
159
159
|
this._unsubscriptions.push(v.addListener(() => {
|
160
|
-
this.
|
160
|
+
this.redraw();
|
161
161
|
}));
|
162
162
|
});
|
163
163
|
}
|
@@ -172,7 +172,7 @@ class SkiaView extends _react.default.Component {
|
|
172
172
|
timestamp: Date.now()
|
173
173
|
});
|
174
174
|
|
175
|
-
this.
|
175
|
+
this.redraw();
|
176
176
|
}
|
177
177
|
|
178
178
|
handleTouchStart(evt) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["SkiaView.web.tsx"],"names":["SkiaView","React","Component","constructor","props","createRef","state","width","height","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","setState","nativeEvent","layout","_canvasRef","current","_surface","JsiSkSurface","global","CanvasKit","MakeWebGLCanvasSurface","_canvas","getCanvas","requestRedraw","componentDidMount","redraw","componentWillUnmount","_unmounted","makeImageSnapshot","rect","_redrawRequests","onDraw","touches","_touches","info","timestamp","Date","now","ref","flush","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","handleTouchStart","TouchType","Start","handleTouchMove","Active","handleTouchEnd","Cancelled","handleTouchCancel","End","render","debug","viewProps"],"mappings":";;;;;;;AACA;;AAGA;;AAIA;;AAGA;;;;;;;;AAEO,MAAMA,QAAN,SAAuBC,eAAMC,SAA7B,CAGL;AACAC,EAAAA,WAAW,CAACC,KAAD,EAAuB;AAAA;;AAChC,UAAMA,KAAN;;AADgC,sCAMM,IANN;;AAAA,8CAOY,EAPZ;;AAAA,sCAQG,EARH;;AAAA,qCASC,IATD;;AAAA,qDAUuBH,eAAMI,SAAN,EAVvB;;AAAA;;AAAA,6CAYR,CAZQ;;AAAA,wCAab,KAba;;AAEhC,SAAKC,KAAL,GAAa;AAAEC,MAAAA,KAAK,EAAE,CAAC,CAAV;AAAaC,MAAAA,MAAM,EAAE,CAAC;AAAtB,KAAb;AACA,SAAKC,KAAL,kBAAaL,KAAK,CAACM,IAAnB,qDAA2B,SAA3B;AACD;;AAWOC,EAAAA,cAAc,GAAG;AACvB,SAAKC,gBAAL,CAAsBC,OAAtB,CAA+BC,CAAD,IAAOA,CAAC,EAAtC;;AACA,SAAKF,gBAAL,GAAwB,EAAxB;AACD;;AAEOG,EAAAA,QAAQ,CAACC,GAAD,EAAyB;AACvC,SAAKC,QAAL,CACE;AACEV,MAAAA,KAAK,EAAES,GAAG,CAACE,WAAJ,CAAgBC,MAAhB,CAAuBZ,KADhC;AAEEC,MAAAA,MAAM,EAAEQ,GAAG,CAACE,WAAJ,CAAgBC,MAAhB,CAAuBX;AAFjC,KADF,EAKE,MAAM;AACJ;AACA,UAAI,KAAKY,UAAL,CAAgBC,OAApB,EAA6B;AAC3B;AACA,aAAKC,QAAL,GAAgB,IAAIC,0BAAJ,CACdC,MAAM,CAACC,SADO,EAEdD,MAAM,CAACC,SAAP,CAAiBC,sBAAjB,CAAwC,KAAKN,UAAL,CAAgBC,OAAxD,CAFc,C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B;AAPnB,MADF,CADF;AAaD;;AA/KD","sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawingInfo, DrawMode, SkiaViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nexport class SkiaView extends React.Component<\n SkiaViewProps,\n { width: number; height: number }\n> {\n constructor(props: SkiaViewProps) {\n super(props);\n this.state = { width: -1, height: -1 };\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef: React.RefObject<HTMLCanvasElement> = React.createRef();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private _unmounted = false;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n this.setState(\n {\n width: evt.nativeEvent.layout.width,\n height: evt.nativeEvent.layout.height,\n },\n () => {\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n // Create surface\n this._surface = new JsiSkSurface(\n global.CanvasKit,\n global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)!\n );\n // Get canvas and repaint\n if (this._surface) {\n this._canvas = this._surface.getCanvas();\n this.requestRedraw();\n }\n }\n }\n );\n }\n\n componentDidMount() {\n // Start render loop\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n this._surface = null;\n this._canvas = null;\n this._unmounted = true;\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private redraw() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (\n this._canvas &&\n this.props.onDraw &&\n this.state.height !== -1 &&\n this.state.width !== -1\n ) {\n const touches = [...this._touches];\n this._touches = [];\n const info: DrawingInfo = {\n height: this.state.height,\n width: this.state.width,\n timestamp: Date.now(),\n touches: [touches],\n };\n this.props.onDraw && this.props.onDraw(this._canvas!, info);\n this._surface?.ref.flush();\n }\n }\n // Always request a new redraw as long as we're not unmounted\n if (!this._unmounted) {\n requestAnimationFrame(this.redraw.bind(this));\n }\n }\n\n public requestRedraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.redraw();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.requestRedraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.requestRedraw();\n }\n\n handleTouchStart(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Start);\n }\n\n handleTouchMove(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Active);\n }\n\n handleTouchEnd(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Cancelled);\n }\n\n handleTouchCancel(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.End);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n width={this.state.width}\n height={this.state.height}\n onPointerDown={this.handleTouchStart.bind(this)}\n onPointerMove={this.handleTouchMove.bind(this)}\n onPointerUp={this.handleTouchEnd.bind(this)}\n onPointerCancel={this.handleTouchCancel.bind(this)}\n />\n </View>\n );\n }\n}\n"]}
|
1
|
+
{"version":3,"sources":["SkiaView.web.tsx"],"names":["SkiaView","React","Component","constructor","props","createRef","state","width","height","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","setState","nativeEvent","layout","_canvasRef","current","_surface","JsiSkSurface","global","CanvasKit","MakeWebGLCanvasSurface","_canvas","getCanvas","redraw","componentDidMount","tick","componentWillUnmount","_unmounted","makeImageSnapshot","rect","_redrawRequests","onDraw","touches","_touches","info","timestamp","Date","now","ref","flush","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","handleTouchStart","TouchType","Start","handleTouchMove","Active","handleTouchEnd","Cancelled","handleTouchCancel","End","render","debug","viewProps"],"mappings":";;;;;;;AACA;;AAGA;;AAIA;;AAGA;;;;;;;;AAEO,MAAMA,QAAN,SAAuBC,eAAMC,SAA7B,CAGL;AACAC,EAAAA,WAAW,CAACC,KAAD,EAAuB;AAAA;;AAChC,UAAMA,KAAN;;AADgC,sCAMM,IANN;;AAAA,8CAOY,EAPZ;;AAAA,sCAQG,EARH;;AAAA,qCASC,IATD;;AAAA,qDAUuBH,eAAMI,SAAN,EAVvB;;AAAA;;AAAA,6CAYR,CAZQ;;AAAA,wCAab,KAba;;AAEhC,SAAKC,KAAL,GA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,GAAtB,EAA2BsD,iBAAUO,GAArC;AACD;;AAEDC,EAAAA,MAAM,GAAG;AACP,UAAM;AAAEpE,MAAAA,IAAF;AAAQqE,MAAAA,KAAK,GAAG,KAAhB;AAAuB,SAAGC;AAA1B,QAAwC,KAAK5E,KAAnD;AACA,wBACE,6BAAC,iBAAD,eAAU4E,SAAV;AAAqB,MAAA,QAAQ,EAAE,KAAKjE,QAAL,CAAcgC,IAAd,CAAmB,IAAnB;AAA/B,qBACE;AACE,MAAA,GAAG,EAAE,KAAK3B,UADZ;AAEE,MAAA,KAAK,EAAE,KAAKd,KAAL,CAAWC,KAFpB;AAGE,MAAA,MAAM,EAAE,KAAKD,KAAL,CAAWE,MAHrB;AAIE,MAAA,aAAa,EAAE,KAAK6D,gBAAL,CAAsBtB,IAAtB,CAA2B,IAA3B,CAJjB;AAKE,MAAA,aAAa,EAAE,KAAKyB,eAAL,CAAqBzB,IAArB,CAA0B,IAA1B,CALjB;AAME,MAAA,WAAW,EAAE,KAAK2B,cAAL,CAAoB3B,IAApB,CAAyB,IAAzB,CANf;AAOE,MAAA,eAAe,EAAE,KAAK6B,iBAAL,CAAuB7B,IAAvB,CAA4B,IAA5B;AAPnB,MADF,CADF;AAaD;;AA/KD","sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawingInfo, DrawMode, SkiaViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nexport class SkiaView extends React.Component<\n SkiaViewProps,\n { width: number; height: number }\n> {\n constructor(props: SkiaViewProps) {\n super(props);\n this.state = { width: -1, height: -1 };\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef: React.RefObject<HTMLCanvasElement> = React.createRef();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private _unmounted = false;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n this.setState(\n {\n width: evt.nativeEvent.layout.width,\n height: evt.nativeEvent.layout.height,\n },\n () => {\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n // Create surface\n this._surface = new JsiSkSurface(\n global.CanvasKit,\n global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)!\n );\n // Get canvas and repaint\n if (this._surface) {\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n }\n }\n );\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n this._surface = null;\n this._canvas = null;\n this._unmounted = true;\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (\n this._canvas &&\n this.props.onDraw &&\n this.state.height !== -1 &&\n this.state.width !== -1\n ) {\n const touches = [...this._touches];\n this._touches = [];\n const info: DrawingInfo = {\n height: this.state.height,\n width: this.state.width,\n timestamp: Date.now(),\n touches: [touches],\n };\n this.props.onDraw && this.props.onDraw(this._canvas!, info);\n this._surface?.ref.flush();\n }\n }\n // Always request a new redraw as long as we're not unmounted\n if (!this._unmounted) {\n requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.tick();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n handleTouchStart(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Start);\n }\n\n handleTouchMove(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Active);\n }\n\n handleTouchEnd(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Cancelled);\n }\n\n handleTouchCancel(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.End);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n width={this.state.width}\n height={this.state.height}\n onPointerDown={this.handleTouchStart.bind(this)}\n onPointerMove={this.handleTouchMove.bind(this)}\n onPointerUp={this.handleTouchEnd.bind(this)}\n onPointerCancel={this.handleTouchCancel.bind(this)}\n />\n </View>\n );\n }\n}\n"]}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.LoadSkiaWeb = exports.LoadSkia = void 0;
|
7
|
+
|
8
|
+
var _canvaskit = _interopRequireDefault(require("canvaskit-wasm/bin/full/canvaskit"));
|
9
|
+
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
|
12
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
13
|
+
// @ts-expect-error
|
14
|
+
const LoadSkiaWeb = async () => {
|
15
|
+
const CanvasKit = await (0, _canvaskit.default)(); // The CanvasKit API is stored on the global object and used
|
16
|
+
// to create the JsiSKApi in the Skia.web.ts file.
|
17
|
+
|
18
|
+
global.CanvasKit = CanvasKit;
|
19
|
+
}; // We keep this function for backward compatibility
|
20
|
+
|
21
|
+
|
22
|
+
exports.LoadSkiaWeb = LoadSkiaWeb;
|
23
|
+
const LoadSkia = LoadSkiaWeb;
|
24
|
+
exports.LoadSkia = LoadSkia;
|
25
|
+
//# sourceMappingURL=LoadSkiaWeb.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["LoadSkiaWeb.tsx"],"names":["LoadSkiaWeb","CanvasKit","global","LoadSkia"],"mappings":";;;;;;;AAEA;;;;AAFA;AACA;AAQO,MAAMA,WAAW,GAAG,YAAY;AACrC,QAAMC,SAAS,GAAG,MAAM,yBAAxB,CADqC,CAErC;AACA;;AACAC,EAAAA,MAAM,CAACD,SAAP,GAAmBA,SAAnB;AACD,CALM,C,CAOP;;;;AACO,MAAME,QAAQ,GAAGH,WAAjB","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type { CanvasKit as CanvasKitType } from \"canvaskit-wasm\";\n\ndeclare global {\n var CanvasKit: CanvasKitType;\n}\n\nexport const LoadSkiaWeb = async () => {\n const CanvasKit = await CanvasKitInit();\n // The CanvasKit API is stored on the global object and used\n // to create the JsiSKApi in the Skia.web.ts file.\n global.CanvasKit = CanvasKit;\n};\n\n// We keep this function for backward compatibility\nexport const LoadSkia = LoadSkiaWeb;\n"]}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.WithSkiaWeb = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
|
10
|
+
var _reactNative = require("react-native");
|
11
|
+
|
12
|
+
var _LoadSkiaWeb = require("./LoadSkiaWeb");
|
13
|
+
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
15
|
+
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17
|
+
|
18
|
+
const WithSkiaWeb = _ref => {
|
19
|
+
let {
|
20
|
+
getComponent,
|
21
|
+
fallback
|
22
|
+
} = _ref;
|
23
|
+
const Inner = (0, _react.useMemo)(() => /*#__PURE__*/(0, _react.lazy)(async () => {
|
24
|
+
if (_reactNative.Platform.OS === "web") {
|
25
|
+
await (0, _LoadSkiaWeb.LoadSkiaWeb)();
|
26
|
+
} else {
|
27
|
+
console.warn("<WithSkiaWeb /> is only necessary on web. Consider not using on native.");
|
28
|
+
}
|
29
|
+
|
30
|
+
return getComponent();
|
31
|
+
}), [getComponent]);
|
32
|
+
return /*#__PURE__*/_react.default.createElement(_react.Suspense, {
|
33
|
+
fallback: fallback
|
34
|
+
}, /*#__PURE__*/_react.default.createElement(Inner, null));
|
35
|
+
};
|
36
|
+
|
37
|
+
exports.WithSkiaWeb = WithSkiaWeb;
|
38
|
+
//# sourceMappingURL=WithSkiaWeb.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["WithSkiaWeb.tsx"],"names":["WithSkiaWeb","getComponent","fallback","Inner","Platform","OS","console","warn"],"mappings":";;;;;;;AACA;;AACA;;AAEA;;;;;;AAOO,MAAMA,WAAW,GAAG,QAA+C;AAAA,MAA9C;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,GAA8C;AACxE,QAAMC,KAAK,GAAG,oBACZ,mBACE,iBAAK,YAAY;AACf,QAAIC,sBAASC,EAAT,KAAgB,KAApB,EAA2B;AACzB,YAAM,+BAAN;AACD,KAFD,MAEO;AACLC,MAAAA,OAAO,CAACC,IAAR,CACE,yEADF;AAGD;;AACD,WAAON,YAAY,EAAnB;AACD,GATD,CAFU,EAYZ,CAACA,YAAD,CAZY,CAAd;AAcA,sBACE,6BAAC,eAAD;AAAU,IAAA,QAAQ,EAAEC;AAApB,kBACE,6BAAC,KAAD,OADF,CADF;AAKD,CApBM","sourcesContent":["import type { ComponentProps, ComponentType } from \"react\";\nimport React, { useMemo, lazy, Suspense } from \"react\";\nimport { Platform } from \"react-native\";\n\nimport { LoadSkiaWeb } from \"./LoadSkiaWeb\";\n\ninterface WithSkiaProps {\n fallback: ComponentProps<typeof Suspense>[\"fallback\"];\n getComponent: () => Promise<{ default: ComponentType }>;\n}\n\nexport const WithSkiaWeb = ({ getComponent, fallback }: WithSkiaProps) => {\n const Inner = useMemo(\n () =>\n lazy(async () => {\n if (Platform.OS === \"web\") {\n await LoadSkiaWeb();\n } else {\n console.warn(\n \"<WithSkiaWeb /> is only necessary on web. Consider not using on native.\"\n );\n }\n return getComponent();\n }),\n [getComponent]\n );\n return (\n <Suspense fallback={fallback}>\n <Inner />\n </Suspense>\n );\n};\n"]}
|
@@ -3,20 +3,30 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.LoadSkia = void 0;
|
7
6
|
|
8
|
-
var
|
7
|
+
var _LoadSkiaWeb = require("./LoadSkiaWeb");
|
9
8
|
|
10
|
-
function
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
Object.keys(_LoadSkiaWeb).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _LoadSkiaWeb[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _LoadSkiaWeb[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
17
19
|
|
18
|
-
|
19
|
-
};
|
20
|
+
var _WithSkiaWeb = require("./WithSkiaWeb");
|
20
21
|
|
21
|
-
|
22
|
+
Object.keys(_WithSkiaWeb).forEach(function (key) {
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
24
|
+
if (key in exports && exports[key] === _WithSkiaWeb[key]) return;
|
25
|
+
Object.defineProperty(exports, key, {
|
26
|
+
enumerable: true,
|
27
|
+
get: function () {
|
28
|
+
return _WithSkiaWeb[key];
|
29
|
+
}
|
30
|
+
});
|
31
|
+
});
|
22
32
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from \"./LoadSkiaWeb\";\nexport * from \"./WithSkiaWeb\";\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Group.tsx"],"names":["React","ClipOp","processCanvasTransform","processPaint","processClip","createDrawing","DrawingNode","isDeclarationNode","isSkPaint","obj","__typename__","onDraw","ctx","node","layer","clip","invertClip","groupProps","canvas","opacity","Skia","declarations","children","filter","map","child","draw","drawings","paint","copy","hasTransform","transform","matrix","hasClip","shouldSave","saveLayer","current","undefined","save","op","Difference","Intersect","visit","restore","Group","props"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAIA,SAASC,MAAT,QAAuB,kBAAvB;AACA,SACEC,sBADF,EAEEC,YAFF,EAGEC,WAHF,QAIO,eAJP;AAWA,SAASC,aAAT,EAAwBC,WAAxB,QAA2C,UAA3C;AACA,SAASC,iBAAT,QAAkC,sBAAlC;;AAEA,MAAMC,SAAS,GAAIC,GAAD,IAChB,kBAAkBA,GAAlB,IAAyBA,GAAG,CAACC,YAAJ,KAAqB,OADhD;;AASA,MAAMC,MAAM,GAAGN,aAAa,CAC1B,CAACO,GAAD,QAAkDC,IAAlD,KAA2D;AAAA,MAArD;AAAEC,IAAAA,KAAF;AAASC,IAAAA,IAAT;AAAeC,IAAAA,UAAf;AAA2B,OAAGC;AAA9B,GAAqD;AACzD,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,OAAV;AAAmBC,IAAAA;AAAnB,MAA4BR,GAAlC;AACA,QAAMS,YAAY,GAAGR,IAAI,CAACS,QAAL,CAClBC,MADkB,CACXhB,iBADW,EAElBiB,GAFkB,CAEbC,KAAD,IAAWA,KAAK,CAACC,IAAN,CAAWd,GAAX,CAFG,CAArB;AAIA,QAAMe,QAAQ,GAAGd,IAAI,CAACS,QAAL,CAAcC,MAAd,CACdE,KAAD,IAAWA,KAAK,YAAYnB,WADb,CAAjB;AAGA,QAAMsB,KAAK,GAAGzB,YAAY,CACxBS,GAAG,CAACQ,IADoB,EAExBR,GAAG,CAACgB,KAAJ,CAAUC,IAAV,EAFwB,EAGxBV,OAHwB,EAIxBF,UAJwB,EAKxBI,YALwB,CAA1B;AAOA,QAAMS,YAAY,GAAG,CAAC,CAACb,UAAU,CAACc,SAAb,IAA0B,CAAC,CAACd,UAAU,CAACe,MAA5D;AACA,QAAMC,OAAO,GAAG,CAAC,CAAClB,IAAlB;AACA,QAAMmB,UAAU,GAAGJ,YAAY,IAAIG,OAAhB,IAA2B,CAAC,CAACnB,KAAhD;;AACA,MAAIoB,UAAJ,EAAgB;AACd,QAAIpB,KAAJ,EAAW;AACT,UAAI,OAAOA,KAAP,KAAiB,SAArB,EAAgC;AAC9BI,QAAAA,MAAM,CAACiB,SAAP;AACD,OAFD,MAEO,IAAI3B,SAAS,CAACM,KAAD,CAAb,EAAsB;AAC3BI,QAAAA,MAAM,CAACiB,SAAP,CAAiBrB,KAAjB;AACD,OAFM,MAEA;AAAA;;AACLI,QAAAA,MAAM,CAACiB,SAAP,mBAAiBrB,KAAK,CAACsB,OAAvB,2DAAkCC,SAAlC;AACD;AACF,KARD,MAQO;AACLnB,MAAAA,MAAM,CAACoB,IAAP;AACD;;AACDpC,IAAAA,sBAAsB,
|
1
|
+
{"version":3,"sources":["Group.tsx"],"names":["React","ClipOp","processCanvasTransform","processPaint","processClip","createDrawing","DrawingNode","isDeclarationNode","isSkPaint","obj","__typename__","onDraw","ctx","node","layer","clip","invertClip","groupProps","canvas","opacity","Skia","declarations","children","filter","map","child","draw","drawings","paint","copy","hasTransform","transform","matrix","hasClip","shouldSave","saveLayer","current","undefined","save","op","Difference","Intersect","visit","restore","Group","props"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAIA,SAASC,MAAT,QAAuB,kBAAvB;AACA,SACEC,sBADF,EAEEC,YAFF,EAGEC,WAHF,QAIO,eAJP;AAWA,SAASC,a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ACM,KAAD,CAAb,EAAsB;AAC3BI,QAAAA,MAAM,CAACiB,SAAP,CAAiBrB,KAAjB;AACD,OAFM,MAEA;AAAA;;AACLI,QAAAA,MAAM,CAACiB,SAAP,mBAAiBrB,KAAK,CAACsB,OAAvB,2DAAkCC,SAAlC;AACD;AACF,KARD,MAQO;AACLnB,MAAAA,MAAM,CAACoB,IAAP;AACD;;AACDpC,IAAAA,sBAAsB,CAACgB,MAAD,EAASD,UAAT,CAAtB;;AACA,QAAIF,IAAJ,EAAU;AACR,YAAMwB,EAAE,GAAGvB,UAAU,GAAGf,MAAM,CAACuC,UAAV,GAAuBvC,MAAM,CAACwC,SAAnD;AACArC,MAAAA,WAAW,CAACgB,IAAD,EAAOF,MAAP,EAAeH,IAAf,EAAqBwB,EAArB,CAAX;AACD;AACF;;AACD1B,EAAAA,IAAI,CAAC6B,KAAL,CACE,EACE,GAAG9B,GADL;AAEEgB,IAAAA,KAFF;AAGET,IAAAA,OAAO,EAAEF,UAAU,CAACE,OAAX,GAAqBF,UAAU,CAACE,OAAX,GAAqBA,OAA1C,GAAoDA;AAH/D,GADF,EAMEQ,QANF;;AAQA,MAAIO,UAAJ,EAAgB;AACdhB,IAAAA,MAAM,CAACyB,OAAP;AACD;AACF,CAjDyB,CAA5B;AAoDA,OAAO,MAAMC,KAAK,GAAIC,KAAD,IAAsC;AACzD,sBAAO;AAAW,IAAA,MAAM,EAAElC;AAAnB,KAA+BkC,KAA/B;AAAsC,IAAA,cAAc;AAApD,KAAP;AACD,CAFM","sourcesContent":["import React from \"react\";\nimport type { RefObject } from \"react\";\n\nimport type { SkPaint } from \"../../skia/types\";\nimport { ClipOp } from \"../../skia/types\";\nimport {\n processCanvasTransform,\n processPaint,\n processClip,\n} from \"../processors\";\nimport type {\n CustomPaintProps,\n TransformProps,\n AnimatedProps,\n ClipDef,\n} from \"../processors\";\nimport { createDrawing, DrawingNode } from \"../nodes\";\nimport { isDeclarationNode } from \"../nodes/Declaration\";\n\nconst isSkPaint = (obj: RefObject<SkPaint> | SkPaint): obj is SkPaint =>\n \"__typename__\" in obj && obj.__typename__ === \"Paint\";\n\nexport interface GroupProps extends CustomPaintProps, TransformProps {\n clip?: ClipDef;\n invertClip?: boolean;\n layer?: RefObject<SkPaint> | SkPaint | boolean;\n}\n\nconst onDraw = createDrawing<GroupProps>(\n (ctx, { layer, clip, invertClip, ...groupProps }, node) => {\n const { canvas, opacity, Skia } = ctx;\n const declarations = node.children\n .filter(isDeclarationNode)\n .map((child) => child.draw(ctx));\n\n const drawings = node.children.filter(\n (child) => child instanceof DrawingNode\n );\n const paint = processPaint(\n ctx.Skia,\n ctx.paint.copy(),\n opacity,\n groupProps,\n declarations\n );\n const hasTransform = !!groupProps.transform || !!groupProps.matrix;\n const hasClip = !!clip;\n const shouldSave = hasTransform || hasClip || !!layer;\n if (shouldSave) {\n if (layer) {\n if (typeof layer === \"boolean\") {\n canvas.saveLayer();\n } else if (isSkPaint(layer)) {\n canvas.saveLayer(layer);\n } else {\n canvas.saveLayer(layer.current ?? undefined);\n }\n } else {\n canvas.save();\n }\n processCanvasTransform(canvas, groupProps);\n if (clip) {\n const op = invertClip ? ClipOp.Difference : ClipOp.Intersect;\n processClip(Skia, canvas, clip, op);\n }\n }\n node.visit(\n {\n ...ctx,\n paint,\n opacity: groupProps.opacity ? groupProps.opacity * opacity : opacity,\n },\n drawings\n );\n if (shouldSave) {\n canvas.restore();\n }\n }\n);\n\nexport const Group = (props: AnimatedProps<GroupProps>) => {\n return <skDrawing onDraw={onDraw} {...props} skipProcessing />;\n};\n"]}
|
@@ -1,35 +1,28 @@
|
|
1
1
|
import { processTransform } from "../../skia/types";
|
2
|
-
export const processCanvasTransform = (
|
3
|
-
let {
|
4
|
-
canvas,
|
5
|
-
Skia
|
6
|
-
} = _ref;
|
2
|
+
export const processCanvasTransform = (canvas, _ref) => {
|
7
3
|
let {
|
8
4
|
transform,
|
9
5
|
origin,
|
10
6
|
matrix
|
11
|
-
} =
|
7
|
+
} = _ref;
|
12
8
|
|
13
9
|
if (matrix) {
|
14
10
|
if (origin) {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
m3.translate(-origin.x, -origin.y);
|
19
|
-
canvas.concat(m3);
|
11
|
+
canvas.translate(origin.x, origin.y);
|
12
|
+
canvas.concat(matrix);
|
13
|
+
canvas.translate(-origin.x, -origin.y);
|
20
14
|
} else {
|
21
15
|
canvas.concat(matrix);
|
22
16
|
}
|
23
17
|
} else if (transform) {
|
24
|
-
|
25
|
-
canvas.concat(m3);
|
18
|
+
processTransform(canvas, origin ? transformOrigin(origin, transform) : transform);
|
26
19
|
}
|
27
20
|
};
|
28
|
-
export const localMatrix = (m,
|
21
|
+
export const localMatrix = (m, _ref2) => {
|
29
22
|
let {
|
30
23
|
transform,
|
31
24
|
origin
|
32
|
-
} =
|
25
|
+
} = _ref2;
|
33
26
|
|
34
27
|
if (transform) {
|
35
28
|
return processTransform(m, origin ? transformOrigin(origin, transform) : transform);
|