@shopify/react-native-skia 2.2.19 → 2.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +2 -0
- package/apple/SkiaCVPixelBufferUtils.mm +8 -4
- package/cpp/api/JsiSkCanvas.h +22 -0
- package/cpp/api/JsiSkDispatcher.cpp +9 -0
- package/cpp/api/JsiSkDispatcher.h +149 -0
- package/cpp/api/JsiSkImage.h +27 -9
- package/cpp/api/JsiSkPicture.h +22 -1
- package/cpp/api/JsiSkSurface.h +15 -10
- package/cpp/api/recorder/Drawings.h +43 -9
- package/cpp/api/recorder/JsiRecorder.h +3 -1
- package/cpp/api/recorder/RNRecorder.h +10 -4
- package/lib/commonjs/external/reanimated/textures.js +31 -28
- package/lib/commonjs/external/reanimated/textures.js.map +1 -1
- package/lib/commonjs/renderer/Offscreen.js +1 -7
- package/lib/commonjs/renderer/Offscreen.js.map +1 -1
- package/lib/commonjs/skia/core/SVG.web.js +9 -2
- package/lib/commonjs/skia/core/SVG.web.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +4 -0
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js +4 -0
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js.map +1 -1
- package/lib/module/external/reanimated/textures.js +33 -30
- package/lib/module/external/reanimated/textures.js.map +1 -1
- package/lib/module/renderer/Offscreen.js +1 -8
- package/lib/module/renderer/Offscreen.js.map +1 -1
- package/lib/module/skia/core/SVG.web.js +9 -2
- package/lib/module/skia/core/SVG.web.js.map +1 -1
- package/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +4 -0
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js +5 -0
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js.map +1 -1
- package/lib/typescript/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +4 -0
- package/lib/typescript/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +4 -0
- package/lib/typescript/src/sksg/Recorder/ReanimatedRecorder.d.ts +4 -0
- package/package.json +6 -1
- package/src/external/reanimated/textures.tsx +36 -27
- package/src/renderer/Offscreen.tsx +1 -7
- package/src/skia/core/SVG.web.ts +12 -8
- package/src/sksg/Recorder/ReanimatedRecorder.ts +4 -0
- package/cpp/api/JsiSkThreadSafeDeletion.h +0 -105
@@ -7,12 +7,36 @@ exports.useTexture = exports.usePictureAsTexture = exports.useImageAsTexture = v
|
|
7
7
|
var _react = require("react");
|
8
8
|
var _Offscreen = require("../../renderer/Offscreen");
|
9
9
|
var _skia = require("../../skia");
|
10
|
+
var _Platform = require("../../Platform");
|
10
11
|
var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
13
|
+
const createTextureFromImage = (texture, image) => {
|
14
|
+
"worklet";
|
15
|
+
|
16
|
+
const surface = _skia.Skia.Surface.MakeOffscreen(image.width(), image.height());
|
17
|
+
if (!surface) {
|
18
|
+
texture.value = null;
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
const canvas = surface.getCanvas();
|
22
|
+
canvas.drawImage(image, 0, 0);
|
23
|
+
surface.flush();
|
24
|
+
texture.value = surface.makeImageSnapshot();
|
25
|
+
if (_Platform.Platform.OS === "web") {
|
26
|
+
texture.value = texture.value.makeNonTextureImage();
|
27
|
+
}
|
28
|
+
};
|
12
29
|
const createTexture = (texture, picture, size) => {
|
13
30
|
"worklet";
|
14
31
|
|
15
|
-
|
32
|
+
const surface = _skia.Skia.Surface.MakeOffscreen(size.width, size.height);
|
33
|
+
const canvas = surface.getCanvas();
|
34
|
+
canvas.drawPicture(picture);
|
35
|
+
surface.flush();
|
36
|
+
texture.value = surface.makeImageSnapshot();
|
37
|
+
if (_Platform.Platform.OS === "web") {
|
38
|
+
texture.value = texture.value.makeNonTextureImage();
|
39
|
+
}
|
16
40
|
};
|
17
41
|
const useTexture = (element, size, deps) => {
|
18
42
|
const {
|
@@ -46,34 +70,13 @@ const usePictureAsTexture = (picture, size) => {
|
|
46
70
|
exports.usePictureAsTexture = usePictureAsTexture;
|
47
71
|
const useImageAsTexture = source => {
|
48
72
|
const image = (0, _skia.useImage)(source);
|
49
|
-
const
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
height: image.height()
|
54
|
-
};
|
55
|
-
}
|
56
|
-
return {
|
57
|
-
width: 0,
|
58
|
-
height: 0
|
59
|
-
};
|
60
|
-
}, [image]);
|
61
|
-
const picture = (0, _react.useMemo)(() => {
|
62
|
-
if (image) {
|
63
|
-
const recorder = _skia.Skia.PictureRecorder();
|
64
|
-
const canvas = recorder.beginRecording({
|
65
|
-
x: 0,
|
66
|
-
y: 0,
|
67
|
-
width: size.width,
|
68
|
-
height: size.height
|
69
|
-
});
|
70
|
-
canvas.drawImage(image, 0, 0);
|
71
|
-
return recorder.finishRecordingAsPicture();
|
72
|
-
} else {
|
73
|
-
return null;
|
73
|
+
const texture = _ReanimatedProxy.default.useSharedValue(null);
|
74
|
+
(0, _react.useEffect)(() => {
|
75
|
+
if (image !== null) {
|
76
|
+
_ReanimatedProxy.default.runOnUI(createTextureFromImage)(texture, image);
|
74
77
|
}
|
75
|
-
}, [
|
76
|
-
return
|
78
|
+
}, [image, texture]);
|
79
|
+
return texture;
|
77
80
|
};
|
78
81
|
exports.useImageAsTexture = useImageAsTexture;
|
79
82
|
//# sourceMappingURL=textures.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_Offscreen","_skia","_ReanimatedProxy","_interopRequireDefault","e","__esModule","default","
|
1
|
+
{"version":3,"names":["_react","require","_Offscreen","_skia","_Platform","_ReanimatedProxy","_interopRequireDefault","e","__esModule","default","createTextureFromImage","texture","image","surface","Skia","Surface","MakeOffscreen","width","height","value","canvas","getCanvas","drawImage","flush","makeImageSnapshot","Platform","OS","makeNonTextureImage","createTexture","picture","size","drawPicture","useTexture","element","deps","setPicture","useState","useEffect","drawAsPicture","x","y","then","pic","usePictureAsTexture","exports","Rea","useSharedValue","runOnUI","useImageAsTexture","source","useImage"],"sources":["textures.tsx"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport type { DependencyList, ReactElement } from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type {\n DataSourceParam,\n SkImage,\n SkPicture,\n SkSize,\n} from \"../../skia/types\";\nimport { drawAsPicture } from \"../../renderer/Offscreen\";\nimport { Skia, useImage } from \"../../skia\";\nimport { Platform } from \"../../Platform\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst createTextureFromImage = (\n texture: SharedValue<SkImage | null>,\n image: SkImage\n) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(image.width(), image.height());\n if (!surface) {\n texture.value = null;\n return;\n }\n const canvas = surface.getCanvas();\n canvas.drawImage(image, 0, 0);\n surface.flush();\n texture.value = surface.makeImageSnapshot();\n if (Platform.OS === \"web\") {\n texture.value = texture.value.makeNonTextureImage();\n }\n};\n\nconst createTexture = (\n texture: SharedValue<SkImage | null>,\n picture: SkPicture,\n size: SkSize\n) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(size.width, size.height)!;\n const canvas = surface.getCanvas();\n canvas.drawPicture(picture);\n surface.flush();\n texture.value = surface.makeImageSnapshot();\n if (Platform.OS === \"web\") {\n texture.value = texture.value.makeNonTextureImage();\n }\n};\n\nexport const useTexture = (\n element: ReactElement,\n size: SkSize,\n deps?: DependencyList\n) => {\n const { width, height } = size;\n const [picture, setPicture] = useState<SkPicture | null>(null);\n useEffect(() => {\n drawAsPicture(element, {\n x: 0,\n y: 0,\n width,\n height,\n }).then((pic) => {\n setPicture(pic);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps ?? []);\n return usePictureAsTexture(picture, size);\n};\n\nexport const usePictureAsTexture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n const texture = Rea.useSharedValue<SkImage | null>(null);\n useEffect(() => {\n if (picture !== null) {\n Rea.runOnUI(createTexture)(texture, picture, size);\n }\n }, [picture, size, texture]);\n return texture;\n};\n\nexport const useImageAsTexture = (source: DataSourceParam) => {\n const image = useImage(source);\n const texture = Rea.useSharedValue<SkImage | null>(null);\n useEffect(() => {\n if (image !== null) {\n Rea.runOnUI(createTextureFromImage)(texture, image);\n }\n }, [image, texture]);\n return texture;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAUA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEA,IAAAI,gBAAA,GAAAC,sBAAA,CAAAL,OAAA;AAAoC,SAAAK,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEpC,MAAMG,sBAAsB,GAAGA,CAC7BC,OAAoC,EACpCC,KAAc,KACX;EACH,SAAS;;EACT,MAAMC,OAAO,GAAGC,UAAI,CAACC,OAAO,CAACC,aAAa,CAACJ,KAAK,CAACK,KAAK,CAAC,CAAC,EAAEL,KAAK,CAACM,MAAM,CAAC,CAAC,CAAC;EACzE,IAAI,CAACL,OAAO,EAAE;IACZF,OAAO,CAACQ,KAAK,GAAG,IAAI;IACpB;EACF;EACA,MAAMC,MAAM,GAAGP,OAAO,CAACQ,SAAS,CAAC,CAAC;EAClCD,MAAM,CAACE,SAAS,CAACV,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;EAC7BC,OAAO,CAACU,KAAK,CAAC,CAAC;EACfZ,OAAO,CAACQ,KAAK,GAAGN,OAAO,CAACW,iBAAiB,CAAC,CAAC;EAC3C,IAAIC,kBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;IACzBf,OAAO,CAACQ,KAAK,GAAGR,OAAO,CAACQ,KAAK,CAACQ,mBAAmB,CAAC,CAAC;EACrD;AACF,CAAC;AAED,MAAMC,aAAa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H,MAAMnB,OAAO,GAAGkC,wBAAG,CAACC,cAAc,CAAiB,IAAI,CAAC;EACxD,IAAAT,gBAAS,EAAC,MAAM;IACd,IAAIR,OAAO,KAAK,IAAI,EAAE;MACpBgB,wBAAG,CAACE,OAAO,CAACnB,aAAa,CAAC,CAACjB,OAAO,EAAEkB,OAAO,EAAEC,IAAI,CAAC;IACpD;EACF,CAAC,EAAE,CAACD,OAAO,EAAEC,IAAI,EAAEnB,OAAO,CAAC,CAAC;EAC5B,OAAOA,OAAO;AAChB,CAAC;AAACiC,OAAA,CAAAD,mBAAA,GAAAA,mBAAA;AAEK,MAAMK,iBAAiB,GAAIC,MAAuB,IAAK;EAC5D,MAAMrC,KAAK,GAAG,IAAAsC,cAAQ,EAACD,MAAM,CAAC;EAC9B,MAAMtC,OAAO,GAAGkC,wBAAG,CAACC,cAAc,CAAiB,IAAI,CAAC;EACxD,IAAAT,gBAAS,EAAC,MAAM;IACd,IAAIzB,KAAK,KAAK,IAAI,EAAE;MAClBiC,wBAAG,CAACE,OAAO,CAACrC,sBAAsB,CAAC,CAACC,OAAO,EAAEC,KAAK,CAAC;IACrD;EACF,CAAC,EAAE,CAACA,KAAK,EAAED,OAAO,CAAC,CAAC;EACpB,OAAOA,OAAO;AAChB,CAAC;AAACiC,OAAA,CAAAI,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
@@ -7,7 +7,6 @@ exports.isOnMainThread = exports.drawAsPicture = exports.drawAsImageFromPicture
|
|
7
7
|
var _skia = require("../skia");
|
8
8
|
var _Platform = require("../Platform");
|
9
9
|
var _Reconciler = require("../sksg/Reconciler");
|
10
|
-
// We call it main thread because on web main is JS thread
|
11
10
|
const isOnMainThread = () => {
|
12
11
|
"worklet";
|
13
12
|
|
@@ -37,12 +36,7 @@ const drawAsImageFromPicture = (picture, size) => {
|
|
37
36
|
canvas.drawPicture(picture);
|
38
37
|
surface.flush();
|
39
38
|
const image = surface.makeImageSnapshot();
|
40
|
-
|
41
|
-
if (!isOnMainThread() || _Platform.Platform.OS === "web") {
|
42
|
-
return image.makeNonTextureImage();
|
43
|
-
} else {
|
44
|
-
return image;
|
45
|
-
}
|
39
|
+
return image.makeNonTextureImage();
|
46
40
|
};
|
47
41
|
exports.drawAsImageFromPicture = drawAsImageFromPicture;
|
48
42
|
//# sourceMappingURL=Offscreen.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_skia","require","_Platform","_Reconciler","isOnMainThread","_WORKLET","Platform","OS","exports","drawAsPicture","element","bounds","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaSGRoot","render","drawOnCanvas","picture","finishRecordingAsPicture","unmount","drawAsImage","size","drawAsImageFromPicture","surface","Surface","MakeOffscreen","width","height","getCanvas","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\n\
|
1
|
+
{"version":3,"names":["_skia","require","_Platform","_Reconciler","isOnMainThread","_WORKLET","Platform","OS","exports","drawAsPicture","element","bounds","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaSGRoot","render","drawOnCanvas","picture","finishRecordingAsPicture","unmount","drawAsImage","size","drawAsImageFromPicture","surface","Surface","MakeOffscreen","width","height","getCanvas","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\n\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = async (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaSGRoot(Skia);\n await root.render(element);\n root.drawOnCanvas(canvas);\n const picture = recorder.finishRecordingAsPicture();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = async (element: ReactElement, size: SkSize) => {\n return drawAsImageFromPicture(await drawAsPicture(element), size);\n};\n\nexport const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(size.width, size.height)!;\n const canvas = surface.getCanvas();\n canvas.drawPicture(picture);\n surface.flush();\n const image = surface.makeImageSnapshot();\n return image.makeNonTextureImage();\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAEO,MAAMG,cAAc,GAAGA,CAAA,KAAM;EAClC,SAAS;;EACT,OACG,OAAOC,QAAQ,KAAK,WAAW,IAAIA,QAAQ,KAAK,IAAI,IACrDC,kBAAQ,CAACC,EAAE,KAAK,KAAK;AAEzB,CAAC;AAACC,OAAA,CAAAJ,cAAA,GAAAA,cAAA;AAEK,MAAMK,aAAa,GAAG,MAAAA,CAAOC,OAAqB,EAAEC,MAAe,KAAK;EAC7E,MAAMC,QAAQ,GAAGC,UAAI,CAACC,eAAe,CAAC,CAAC;EACvC,MAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAc,CAACL,MAAM,CAAC;EAC9C,MAAMM,IAAI,GAAG,IAAIC,sBAAU,CAACL,UAAI,CAAC;EACjC,MAAMI,IAAI,CAACE,MAAM,CAACT,OAAO,CAAC;EAC1BO,IAAI,CAACG,YAAY,CAACL,MAAM,CAAC;EACzB,MAAMM,OAAO,GAAGT,QAAQ,CAACU,wBAAwB,CAAC,CAAC;EACnDL,IAAI,CAACM,OAAO,CAAC,CAAC;EACd,OAAOF,OAAO;AAChB,CAAC;AAACb,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEK,MAAMe,WAAW,GAAG,MAAAA,CAAOd,OAAqB,EAAEe,IAAY,KAAK;EACxE,OAAOC,sBAAsB,CAAC,MAAMjB,aAAa,CAACC,OAAO,CAAC,EAAEe,IAAI,CAAC;AACnE,CAAC;AAACjB,OAAA,CAAAgB,WAAA,GAAAA,WAAA;AAEK,MAAME,sBAAsB,GAAGA,CAACL,OAAkB,EAAEI,IAAY,KAAK;EAC1E,SAAS;;EACT,MAAME,OAAO,GAAGd,UAAI,CAACe,OAAO,CAACC,aAAa,CAACJ,IAAI,CAACK,KAAK,EAAEL,IAAI,CAACM,MAAM,CAAE;EACpE,MAAMhB,MAAM,GAAGY,OAAO,CAACK,SAAS,CAAC,CAAC;EAClCjB,MAAM,CAACkB,WAAW,CAACZ,OAAO,CAAC;EAC3BM,OAAO,CAACO,KAAK,CAAC,CAAC;EACf,MAAMC,KAAK,GAAGR,OAAO,CAACS,iBAAiB,CAAC,CAAC;EACzC,OAAOD,KAAK,CAACE,mBAAmB,CAAC,CAAC;AACpC,CAAC;AAAC7B,OAAA,CAAAkB,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
@@ -9,10 +9,17 @@ const useSVG = (source, onError) => {
|
|
9
9
|
if (source === null || source === undefined) {
|
10
10
|
throw new Error(`Invalid svg data source. Got: ${source}`);
|
11
11
|
}
|
12
|
-
|
12
|
+
let src;
|
13
|
+
if (typeof source === "string") {
|
14
|
+
src = source;
|
15
|
+
} else if (typeof source === "object" && "default" in source && typeof source.default === "string") {
|
16
|
+
src = source.default;
|
17
|
+
} else if (typeof source === "object" && "uri" in source) {
|
18
|
+
src = source.uri;
|
19
|
+
} else {
|
13
20
|
throw new Error(`Invalid svg data source. Make sure that the source resolves to a string. Got: ${JSON.stringify(source, null, 2)}`);
|
14
21
|
}
|
15
|
-
const svg = _Skia.Skia.SVG.MakeFromString(
|
22
|
+
const svg = _Skia.Skia.SVG.MakeFromString(src);
|
16
23
|
if (svg === null && onError !== undefined) {
|
17
24
|
onError(new Error("Failed to create SVG from source."));
|
18
25
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_Skia","require","useSVG","source","onError","undefined","Error","
|
1
|
+
{"version":3,"names":["_Skia","require","useSVG","source","onError","undefined","Error","src","default","uri","JSON","stringify","svg","Skia","SVG","MakeFromString","exports"],"sources":["SVG.web.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { DataSourceParam } from \"../types\";\n\nexport const useSVG = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => {\n if (source === null || source === undefined) {\n throw new Error(`Invalid svg data source. Got: ${source}`);\n }\n let src: string;\n if (typeof source === \"string\") {\n src = source;\n } else if (\n typeof source === \"object\" &&\n \"default\" in source &&\n typeof source.default === \"string\"\n ) {\n src = source.default;\n } else if (typeof source === \"object\" && \"uri\" in source) {\n src = source.uri;\n } else {\n throw new Error(\n `Invalid svg data source. Make sure that the source resolves to a string. Got: ${JSON.stringify(\n source,\n null,\n 2\n )}`\n );\n }\n const svg = Skia.SVG.MakeFromString(src);\n if (svg === null && onError !== undefined) {\n onError(new Error(\"Failed to create SVG from source.\"));\n }\n return svg;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAGO,MAAMC,MAAM,GAAGA,CACpBC,MAAuB,EACvBC,OAA8B,KAC3B;EACH,IAAID,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAKE,SAAS,EAAE;IAC3C,MAAM,IAAIC,KAAK,CAAC,iCAAiCH,MAAM,EAAE,CAAC;EAC5D;EACA,IAAII,GAAW;EACf,IAAI,OAAOJ,MAAM,KAAK,QAAQ,EAAE;IAC9BI,GAAG,GAAGJ,MAAM;EACd,CAAC,MAAM,IACL,OAAOA,MAAM,KAAK,QAAQ,IAC1B,SAAS,IAAIA,MAAM,IACnB,OAAOA,MAAM,CAACK,OAAO,KAAK,QAAQ,EAClC;IACAD,GAAG,GAAGJ,MAAM,CAACK,OAAO;EACtB,CAAC,MAAM,IAAI,OAAOL,MAAM,KAAK,QAAQ,IAAI,KAAK,IAAIA,MAAM,EAAE;IACxDI,GAAG,GAAGJ,MAAM,CAACM,GAAG;EAClB,CAAC,MAAM;IACL,MAAM,IAAIH,KAAK,CACb,iFAAiFI,IAAI,CAACC,SAAS,CAC7FR,MAAM,EACN,IAAI,EACJ,CACF,CAAC,EACH,CAAC;EACH;EACA,MAAMS,GAAG,GAAGC,UAAI,CAACC,GAAG,CAACC,cAAc,CAACR,GAAG,CAAC;EACxC,IAAIK,GAAG,KAAK,IAAI,IAAIR,OAAO,KAAKC,SAAS,EAAE;IACzCD,OAAO,CAAC,IAAIE,KAAK,CAAC,mCAAmC,CAAC,CAAC;EACzD;EACA,OAAOM,GAAG;AACZ,CAAC;AAACI,OAAA,CAAAd,MAAA,GAAAA,MAAA","ignoreList":[]}
|
@@ -2,6 +2,10 @@ import type { SharedValue } from "react-native-reanimated";
|
|
2
2
|
import type { BaseRecorder, JsiRecorder, Skia } from "../../skia/types";
|
3
3
|
import type { PaintProps, NodeType, BlurMaskFilterProps, CTMProps, BoxProps, BoxShadowProps, ImageProps, CircleProps, PointsProps, PathProps, RectProps, RoundedRectProps, OvalProps, LineProps, PatchProps, VerticesProps, DiffRectProps, TextProps, TextPathProps, TextBlobProps, GlyphsProps, PictureProps, ImageSVGProps, ParagraphProps, AtlasProps, SkottieProps } from "../../dom/types";
|
4
4
|
import type { AnimatedProps } from "../../renderer";
|
5
|
+
/**
|
6
|
+
* Currently the recorder only work if the GPU resources (e.g Images) are owned by the main thread.
|
7
|
+
* It will crash otherwise on Ganesh (iOS/Android).
|
8
|
+
*/
|
5
9
|
export declare class ReanimatedRecorder implements BaseRecorder {
|
6
10
|
private values;
|
7
11
|
private recorder;
|
@@ -8,6 +8,10 @@ var _utils = require("../utils");
|
|
8
8
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
9
9
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
10
10
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
11
|
+
/**
|
12
|
+
* Currently the recorder only work if the GPU resources (e.g Images) are owned by the main thread.
|
13
|
+
* It will crash otherwise on Ganesh (iOS/Android).
|
14
|
+
*/
|
11
15
|
class ReanimatedRecorder {
|
12
16
|
constructor(Skia) {
|
13
17
|
_defineProperty(this, "values", new Set());
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_utils","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ReanimatedRecorder","constructor","Skia","Set","recorder","Recorder","processAnimationValues","props","values","forEach","isSharedValue","has","name","size","add","getRecorder","getSharedValues","Array","from","saveGroup","restoreGroup","savePaint","standalone","restorePaint","restorePaintDeclaration","materializePaint","pushPathEffect","pathEffectType","pushImageFilter","imageFilterType","pushColorFilter","colorFilterType","pushShader","shaderType","children","pushBlurMaskFilter","composePathEffect","composeColorFilter","composeImageFilter","saveCTM","restoreCTM","drawPaint","saveLayer","saveBackdropFilter","drawBox","boxProps","shadows","shadow","map","s","drawImage","drawCircle","drawPoints","drawPath","drawRect","drawRRect","drawOval","drawLine","drawPatch","drawVertices","drawDiffRect","drawText","drawTextPath","drawTextBlob","drawGlyphs","drawPicture","drawImageSVG","drawParagraph","drawAtlas","drawSkottie","exports"],"sources":["ReanimatedRecorder.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type { BaseRecorder, JsiRecorder, Skia } from \"../../skia/types\";\nimport type {\n PaintProps,\n NodeType,\n BlurMaskFilterProps,\n CTMProps,\n BoxProps,\n BoxShadowProps,\n ImageProps,\n CircleProps,\n PointsProps,\n PathProps,\n RectProps,\n RoundedRectProps,\n OvalProps,\n LineProps,\n PatchProps,\n VerticesProps,\n DiffRectProps,\n TextProps,\n TextPathProps,\n TextBlobProps,\n GlyphsProps,\n PictureProps,\n ImageSVGProps,\n ParagraphProps,\n AtlasProps,\n SkottieProps,\n} from \"../../dom/types\";\nimport type { AnimatedProps } from \"../../renderer\";\nimport { isSharedValue } from \"../utils\";\n\nexport class ReanimatedRecorder implements BaseRecorder {\n private values = new Set<SharedValue<unknown>>();\n private recorder: JsiRecorder;\n\n constructor(Skia: Skia) {\n this.recorder = Skia.Recorder();\n }\n\n private processAnimationValues(props?: Record<string, unknown>) {\n if (!props) {\n return;\n }\n Object.values(props).forEach((value) => {\n if (isSharedValue(value) && !this.values.has(value)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n value.name = `variable${this.values.size}`;\n this.values.add(value as SharedValue<unknown>);\n }\n });\n }\n\n getRecorder() {\n return this.recorder;\n }\n\n getSharedValues() {\n return Array.from(this.values);\n }\n\n saveGroup(): void {\n this.recorder.saveGroup();\n }\n\n restoreGroup(): void {\n this.recorder.restoreGroup();\n }\n\n savePaint(props: AnimatedProps<PaintProps>, standalone: boolean): void {\n this.processAnimationValues(props);\n this.recorder.savePaint(props, standalone);\n }\n\n restorePaint(): void {\n this.recorder.restorePaint();\n }\n\n restorePaintDeclaration(): void {\n this.recorder.restorePaintDeclaration();\n }\n\n materializePaint(): void {\n this.recorder.materializePaint();\n }\n\n pushPathEffect(\n pathEffectType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushPathEffect(pathEffectType, props);\n }\n\n pushImageFilter(\n imageFilterType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushImageFilter(imageFilterType, props);\n }\n\n pushColorFilter(\n colorFilterType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushColorFilter(colorFilterType, props);\n }\n\n pushShader(\n shaderType: NodeType,\n props: AnimatedProps<unknown>,\n children: number\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushShader(shaderType, props, children);\n }\n\n pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>): void {\n this.processAnimationValues(props);\n this.recorder.pushBlurMaskFilter(props);\n }\n\n composePathEffect(): void {\n this.recorder.composePathEffect();\n }\n\n composeColorFilter(): void {\n this.recorder.composeColorFilter();\n }\n\n composeImageFilter(): void {\n this.recorder.composeImageFilter();\n }\n\n saveCTM(props: AnimatedProps<CTMProps>): void {\n this.processAnimationValues(props);\n this.recorder.saveCTM(props);\n }\n\n restoreCTM(): void {\n this.recorder.restoreCTM();\n }\n\n drawPaint(): void {\n this.recorder.drawPaint();\n }\n\n saveLayer(): void {\n this.recorder.saveLayer();\n }\n\n saveBackdropFilter(): void {\n this.recorder.saveBackdropFilter();\n }\n\n drawBox(\n boxProps: AnimatedProps<BoxProps>,\n shadows: {\n props: BoxShadowProps;\n }[]\n ): void {\n this.processAnimationValues(boxProps);\n shadows.forEach((shadow) => {\n this.processAnimationValues(\n shadow.props as AnimatedProps<BoxShadowProps>\n );\n });\n this.recorder.drawBox(\n boxProps,\n // TODO: Fix this type BaseRecorder.drawBox()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n shadows.map((s) => s.props)\n );\n }\n\n drawImage(props: AnimatedProps<ImageProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawImage(props);\n }\n\n drawCircle(props: AnimatedProps<CircleProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawCircle(props);\n }\n\n drawPoints(props: AnimatedProps<PointsProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPoints(props);\n }\n\n drawPath(props: AnimatedProps<PathProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPath(props);\n }\n\n drawRect(props: AnimatedProps<RectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawRect(props);\n }\n\n drawRRect(props: AnimatedProps<RoundedRectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawRRect(props);\n }\n\n drawOval(props: AnimatedProps<OvalProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawOval(props);\n }\n\n drawLine(props: AnimatedProps<LineProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawLine(props);\n }\n\n drawPatch(props: AnimatedProps<PatchProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPatch(props);\n }\n\n drawVertices(props: AnimatedProps<VerticesProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawVertices(props);\n }\n\n drawDiffRect(props: AnimatedProps<DiffRectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawDiffRect(props);\n }\n\n drawText(props: AnimatedProps<TextProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawText(props);\n }\n\n drawTextPath(props: AnimatedProps<TextPathProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawTextPath(props);\n }\n\n drawTextBlob(props: AnimatedProps<TextBlobProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawTextBlob(props);\n }\n\n drawGlyphs(props: AnimatedProps<GlyphsProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawGlyphs(props);\n }\n\n drawPicture(props: AnimatedProps<PictureProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPicture(props);\n }\n\n drawImageSVG(props: AnimatedProps<ImageSVGProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawImageSVG(props);\n }\n\n drawParagraph(props: AnimatedProps<ParagraphProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawParagraph(props);\n }\n\n drawAtlas(props: AnimatedProps<AtlasProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawAtlas(props);\n }\n\n drawSkottie(props: AnimatedProps<SkottieProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawSkottie(props);\n }\n}\n"],"mappings":";;;;;;AA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C2D,YAAY,CAACxD,KAAK,CAAC;EACnC;EAEAyD,UAAUA,CAACzD,KAAiC,EAAQ;IAClD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAAC4D,UAAU,CAACzD,KAAK,CAAC;EACjC;EAEA0D,WAAWA,CAAC1D,KAAkC,EAAQ;IACpD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAAC6D,WAAW,CAAC1D,KAAK,CAAC;EAClC;EAEA2D,YAAYA,CAAC3D,KAAmC,EAAQ;IACtD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAAC8D,YAAY,CAAC3D,KAAK,CAAC;EACnC;EAEA4D,aAAaA,CAAC5D,KAAoC,EAAQ;IACxD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAAC+D,aAAa,CAAC5D,KAAK,CAAC;EACpC;EAEA6D,SAASA,CAAC7D,KAAgC,EAAQ;IAChD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACgE,SAAS,CAAC7D,KAAK,CAAC;EAChC;EAEA8D,WAAWA,CAAC9D,KAAkC,EAAQ;IACpD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACiE,WAAW,CAAC9D,KAAK,CAAC;EAClC;AACF;AAAC+D,OAAA,CAAAtE,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
1
|
+
{"version":3,"names":["_utils","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ReanimatedRecorder","constructor","Skia","Set","recorder","Recorder","processAnimationValues","props","values","forEach","isSharedValue","has","name","size","add","getRecorder","getSharedValues","Array","from","saveGroup","restoreGroup","savePaint","standalone","restorePaint","restorePaintDeclaration","materializePaint","pushPathEffect","pathEffectType","pushImageFilter","imageFilterType","pushColorFilter","colorFilterType","pushShader","shaderType","children","pushBlurMaskFilter","composePathEffect","composeColorFilter","composeImageFilter","saveCTM","restoreCTM","drawPaint","saveLayer","saveBackdropFilter","drawBox","boxProps","shadows","shadow","map","s","drawImage","drawCircle","drawPoints","drawPath","drawRect","drawRRect","drawOval","drawLine","drawPatch","drawVertices","drawDiffRect","drawText","drawTextPath","drawTextBlob","drawGlyphs","drawPicture","drawImageSVG","drawParagraph","drawAtlas","drawSkottie","exports"],"sources":["ReanimatedRecorder.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type { BaseRecorder, JsiRecorder, Skia } from \"../../skia/types\";\nimport type {\n PaintProps,\n NodeType,\n BlurMaskFilterProps,\n CTMProps,\n BoxProps,\n BoxShadowProps,\n ImageProps,\n CircleProps,\n PointsProps,\n PathProps,\n RectProps,\n RoundedRectProps,\n OvalProps,\n LineProps,\n PatchProps,\n VerticesProps,\n DiffRectProps,\n TextProps,\n TextPathProps,\n TextBlobProps,\n GlyphsProps,\n PictureProps,\n ImageSVGProps,\n ParagraphProps,\n AtlasProps,\n SkottieProps,\n} from \"../../dom/types\";\nimport type { AnimatedProps } from \"../../renderer\";\nimport { isSharedValue } from \"../utils\";\n\n/**\n * Currently the recorder only work if the GPU resources (e.g Images) are owned by the main thread.\n * It will crash otherwise on Ganesh (iOS/Android).\n */\nexport class ReanimatedRecorder implements BaseRecorder {\n private values = new Set<SharedValue<unknown>>();\n private recorder: JsiRecorder;\n\n constructor(Skia: Skia) {\n this.recorder = Skia.Recorder();\n }\n\n private processAnimationValues(props?: Record<string, unknown>) {\n if (!props) {\n return;\n }\n Object.values(props).forEach((value) => {\n if (isSharedValue(value) && !this.values.has(value)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n value.name = `variable${this.values.size}`;\n this.values.add(value as SharedValue<unknown>);\n }\n });\n }\n\n getRecorder() {\n return this.recorder;\n }\n\n getSharedValues() {\n return Array.from(this.values);\n }\n\n saveGroup(): void {\n this.recorder.saveGroup();\n }\n\n restoreGroup(): void {\n this.recorder.restoreGroup();\n }\n\n savePaint(props: AnimatedProps<PaintProps>, standalone: boolean): void {\n this.processAnimationValues(props);\n this.recorder.savePaint(props, standalone);\n }\n\n restorePaint(): void {\n this.recorder.restorePaint();\n }\n\n restorePaintDeclaration(): void {\n this.recorder.restorePaintDeclaration();\n }\n\n materializePaint(): void {\n this.recorder.materializePaint();\n }\n\n pushPathEffect(\n pathEffectType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushPathEffect(pathEffectType, props);\n }\n\n pushImageFilter(\n imageFilterType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushImageFilter(imageFilterType, props);\n }\n\n pushColorFilter(\n colorFilterType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushColorFilter(colorFilterType, props);\n }\n\n pushShader(\n shaderType: NodeType,\n props: AnimatedProps<unknown>,\n children: number\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushShader(shaderType, props, children);\n }\n\n pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>): void {\n this.processAnimationValues(props);\n this.recorder.pushBlurMaskFilter(props);\n }\n\n composePathEffect(): void {\n this.recorder.composePathEffect();\n }\n\n composeColorFilter(): void {\n this.recorder.composeColorFilter();\n }\n\n composeImageFilter(): void {\n this.recorder.composeImageFilter();\n }\n\n saveCTM(props: AnimatedProps<CTMProps>): void {\n this.processAnimationValues(props);\n this.recorder.saveCTM(props);\n }\n\n restoreCTM(): void {\n this.recorder.restoreCTM();\n }\n\n drawPaint(): void {\n this.recorder.drawPaint();\n }\n\n saveLayer(): void {\n this.recorder.saveLayer();\n }\n\n saveBackdropFilter(): void {\n this.recorder.saveBackdropFilter();\n }\n\n drawBox(\n boxProps: AnimatedProps<BoxProps>,\n shadows: {\n props: BoxShadowProps;\n }[]\n ): void {\n this.processAnimationValues(boxProps);\n shadows.forEach((shadow) => {\n this.processAnimationValues(\n shadow.props as AnimatedProps<BoxShadowProps>\n );\n });\n this.recorder.drawBox(\n boxProps,\n // TODO: Fix this type BaseRecorder.drawBox()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n shadows.map((s) => s.props)\n );\n }\n\n drawImage(props: AnimatedProps<ImageProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawImage(props);\n }\n\n drawCircle(props: AnimatedProps<CircleProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawCircle(props);\n }\n\n drawPoints(props: AnimatedProps<PointsProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPoints(props);\n }\n\n drawPath(props: AnimatedProps<PathProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPath(props);\n }\n\n drawRect(props: AnimatedProps<RectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawRect(props);\n }\n\n drawRRect(props: AnimatedProps<RoundedRectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawRRect(props);\n }\n\n drawOval(props: AnimatedProps<OvalProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawOval(props);\n }\n\n drawLine(props: AnimatedProps<LineProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawLine(props);\n }\n\n drawPatch(props: AnimatedProps<PatchProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPatch(props);\n }\n\n drawVertices(props: AnimatedProps<VerticesProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawVertices(props);\n }\n\n drawDiffRect(props: AnimatedProps<DiffRectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawDiffRect(props);\n }\n\n drawText(props: AnimatedProps<TextProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawText(props);\n }\n\n drawTextPath(props: AnimatedProps<TextPathProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawTextPath(props);\n }\n\n drawTextBlob(props: AnimatedProps<TextBlobProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawTextBlob(props);\n }\n\n drawGlyphs(props: AnimatedProps<GlyphsProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawGlyphs(props);\n }\n\n drawPicture(props: AnimatedProps<PictureProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPicture(props);\n }\n\n drawImageSVG(props: AnimatedProps<ImageSVGProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawImageSVG(props);\n }\n\n drawParagraph(props: AnimatedProps<ParagraphProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawParagraph(props);\n }\n\n drawAtlas(props: AnimatedProps<AtlasProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawAtlas(props);\n }\n\n drawSkottie(props: AnimatedProps<SkottieProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawSkottie(props);\n }\n}\n"],"mappings":";;;;;;AAgCA,IAAAA,MAAA,GAAAC,OAAA;AAAyC,SAAAC,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAF,CAAA,GAAAE,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAb,CAAA,QAAAU,CAAA,GAAAV,CAAA,CAAAc,IAAA,CAAAZ,CAAA,EAAAD,CA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AAK,CAAC;EACpC;EAEA6D,SAASA,CAAC7D,KAAgC,EAAQ;IAChD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACgE,SAAS,CAAC7D,KAAK,CAAC;EAChC;EAEA8D,WAAWA,CAAC9D,KAAkC,EAAQ;IACpD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACiE,WAAW,CAAC9D,KAAK,CAAC;EAClC;AACF;AAAC+D,OAAA,CAAAtE,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
@@ -1,11 +1,35 @@
|
|
1
|
-
import { useEffect,
|
2
|
-
import {
|
1
|
+
import { useEffect, useState } from "react";
|
2
|
+
import { drawAsPicture } from "../../renderer/Offscreen";
|
3
3
|
import { Skia, useImage } from "../../skia";
|
4
|
+
import { Platform } from "../../Platform";
|
4
5
|
import Rea from "./ReanimatedProxy";
|
6
|
+
const createTextureFromImage = (texture, image) => {
|
7
|
+
"worklet";
|
8
|
+
|
9
|
+
const surface = Skia.Surface.MakeOffscreen(image.width(), image.height());
|
10
|
+
if (!surface) {
|
11
|
+
texture.value = null;
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
const canvas = surface.getCanvas();
|
15
|
+
canvas.drawImage(image, 0, 0);
|
16
|
+
surface.flush();
|
17
|
+
texture.value = surface.makeImageSnapshot();
|
18
|
+
if (Platform.OS === "web") {
|
19
|
+
texture.value = texture.value.makeNonTextureImage();
|
20
|
+
}
|
21
|
+
};
|
5
22
|
const createTexture = (texture, picture, size) => {
|
6
23
|
"worklet";
|
7
24
|
|
8
|
-
|
25
|
+
const surface = Skia.Surface.MakeOffscreen(size.width, size.height);
|
26
|
+
const canvas = surface.getCanvas();
|
27
|
+
canvas.drawPicture(picture);
|
28
|
+
surface.flush();
|
29
|
+
texture.value = surface.makeImageSnapshot();
|
30
|
+
if (Platform.OS === "web") {
|
31
|
+
texture.value = texture.value.makeNonTextureImage();
|
32
|
+
}
|
9
33
|
};
|
10
34
|
export const useTexture = (element, size, deps) => {
|
11
35
|
const {
|
@@ -37,33 +61,12 @@ export const usePictureAsTexture = (picture, size) => {
|
|
37
61
|
};
|
38
62
|
export const useImageAsTexture = source => {
|
39
63
|
const image = useImage(source);
|
40
|
-
const
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
height: image.height()
|
45
|
-
};
|
46
|
-
}
|
47
|
-
return {
|
48
|
-
width: 0,
|
49
|
-
height: 0
|
50
|
-
};
|
51
|
-
}, [image]);
|
52
|
-
const picture = useMemo(() => {
|
53
|
-
if (image) {
|
54
|
-
const recorder = Skia.PictureRecorder();
|
55
|
-
const canvas = recorder.beginRecording({
|
56
|
-
x: 0,
|
57
|
-
y: 0,
|
58
|
-
width: size.width,
|
59
|
-
height: size.height
|
60
|
-
});
|
61
|
-
canvas.drawImage(image, 0, 0);
|
62
|
-
return recorder.finishRecordingAsPicture();
|
63
|
-
} else {
|
64
|
-
return null;
|
64
|
+
const texture = Rea.useSharedValue(null);
|
65
|
+
useEffect(() => {
|
66
|
+
if (image !== null) {
|
67
|
+
Rea.runOnUI(createTextureFromImage)(texture, image);
|
65
68
|
}
|
66
|
-
}, [
|
67
|
-
return
|
69
|
+
}, [image, texture]);
|
70
|
+
return texture;
|
68
71
|
};
|
69
72
|
//# sourceMappingURL=textures.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useEffect","
|
1
|
+
{"version":3,"names":["useEffect","useState","drawAsPicture","Skia","useImage","Platform","Rea","createTextureFromImage","texture","image","surface","Surface","MakeOffscreen","width","height","value","canvas","getCanvas","drawImage","flush","makeImageSnapshot","OS","makeNonTextureImage","createTexture","picture","size","drawPicture","useTexture","element","deps","setPicture","x","y","then","pic","usePictureAsTexture","useSharedValue","runOnUI","useImageAsTexture","source"],"sources":["textures.tsx"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport type { DependencyList, ReactElement } from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type {\n DataSourceParam,\n SkImage,\n SkPicture,\n SkSize,\n} from \"../../skia/types\";\nimport { drawAsPicture } from \"../../renderer/Offscreen\";\nimport { Skia, useImage } from \"../../skia\";\nimport { Platform } from \"../../Platform\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst createTextureFromImage = (\n texture: SharedValue<SkImage | null>,\n image: SkImage\n) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(image.width(), image.height());\n if (!surface) {\n texture.value = null;\n return;\n }\n const canvas = surface.getCanvas();\n canvas.drawImage(image, 0, 0);\n surface.flush();\n texture.value = surface.makeImageSnapshot();\n if (Platform.OS === \"web\") {\n texture.value = texture.value.makeNonTextureImage();\n }\n};\n\nconst createTexture = (\n texture: SharedValue<SkImage | null>,\n picture: SkPicture,\n size: SkSize\n) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(size.width, size.height)!;\n const canvas = surface.getCanvas();\n canvas.drawPicture(picture);\n surface.flush();\n texture.value = surface.makeImageSnapshot();\n if (Platform.OS === \"web\") {\n texture.value = texture.value.makeNonTextureImage();\n }\n};\n\nexport const useTexture = (\n element: ReactElement,\n size: SkSize,\n deps?: DependencyList\n) => {\n const { width, height } = size;\n const [picture, setPicture] = useState<SkPicture | null>(null);\n useEffect(() => {\n drawAsPicture(element, {\n x: 0,\n y: 0,\n width,\n height,\n }).then((pic) => {\n setPicture(pic);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps ?? []);\n return usePictureAsTexture(picture, size);\n};\n\nexport const usePictureAsTexture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n const texture = Rea.useSharedValue<SkImage | null>(null);\n useEffect(() => {\n if (picture !== null) {\n Rea.runOnUI(createTexture)(texture, picture, size);\n }\n }, [picture, size, texture]);\n return texture;\n};\n\nexport const useImageAsTexture = (source: DataSourceParam) => {\n const image = useImage(source);\n const texture = Rea.useSharedValue<SkImage | null>(null);\n useEffect(() => {\n if (image !== null) {\n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MAAM8B,iBAAiB,GAAIC,MAAuB,IAAK;EAC5D,MAAM9B,KAAK,GAAGL,QAAQ,CAACmC,MAAM,CAAC;EAC9B,MAAM/B,OAAO,GAAGF,GAAG,CAAC8B,cAAc,CAAiB,IAAI,CAAC;EACxDpC,SAAS,CAAC,MAAM;IACd,IAAIS,KAAK,KAAK,IAAI,EAAE;MAClBH,GAAG,CAAC+B,OAAO,CAAC9B,sBAAsB,CAAC,CAACC,OAAO,EAAEC,KAAK,CAAC;IACrD;EACF,CAAC,EAAE,CAACA,KAAK,EAAED,OAAO,CAAC,CAAC;EACpB,OAAOA,OAAO;AAChB,CAAC","ignoreList":[]}
|
@@ -1,8 +1,6 @@
|
|
1
1
|
import { Skia } from "../skia";
|
2
2
|
import { Platform } from "../Platform";
|
3
3
|
import { SkiaSGRoot } from "../sksg/Reconciler";
|
4
|
-
|
5
|
-
// We call it main thread because on web main is JS thread
|
6
4
|
export const isOnMainThread = () => {
|
7
5
|
"worklet";
|
8
6
|
|
@@ -29,11 +27,6 @@ export const drawAsImageFromPicture = (picture, size) => {
|
|
29
27
|
canvas.drawPicture(picture);
|
30
28
|
surface.flush();
|
31
29
|
const image = surface.makeImageSnapshot();
|
32
|
-
|
33
|
-
if (!isOnMainThread() || Platform.OS === "web") {
|
34
|
-
return image.makeNonTextureImage();
|
35
|
-
} else {
|
36
|
-
return image;
|
37
|
-
}
|
30
|
+
return image.makeNonTextureImage();
|
38
31
|
};
|
39
32
|
//# sourceMappingURL=Offscreen.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Skia","Platform","SkiaSGRoot","isOnMainThread","_WORKLET","OS","drawAsPicture","element","bounds","recorder","PictureRecorder","canvas","beginRecording","root","render","drawOnCanvas","picture","finishRecordingAsPicture","unmount","drawAsImage","size","drawAsImageFromPicture","surface","Surface","MakeOffscreen","width","height","getCanvas","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\n\
|
1
|
+
{"version":3,"names":["Skia","Platform","SkiaSGRoot","isOnMainThread","_WORKLET","OS","drawAsPicture","element","bounds","recorder","PictureRecorder","canvas","beginRecording","root","render","drawOnCanvas","picture","finishRecordingAsPicture","unmount","drawAsImage","size","drawAsImageFromPicture","surface","Surface","MakeOffscreen","width","height","getCanvas","drawPicture","flush","image","makeImageSnapshot","makeNonTextureImage"],"sources":["Offscreen.tsx"],"sourcesContent":["import type { ReactElement } from \"react\";\n\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\n\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = async (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaSGRoot(Skia);\n await root.render(element);\n root.drawOnCanvas(canvas);\n const picture = recorder.finishRecordingAsPicture();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = async (element: ReactElement, size: SkSize) => {\n return drawAsImageFromPicture(await drawAsPicture(element), size);\n};\n\nexport const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {\n \"worklet\";\n const surface = Skia.Surface.MakeOffscreen(size.width, size.height)!;\n const canvas = surface.getCanvas();\n canvas.drawPicture(picture);\n surface.flush();\n const image = surface.makeImageSnapshot();\n return image.makeNonTextureImage();\n};\n"],"mappings":"AAGA,SAASA,IAAI,QAAQ,SAAS;AAC9B,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,UAAU,QAAQ,oBAAoB;AAE/C,OAAO,MAAMC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AACpC,CAAC","ignoreList":[]}
|
@@ -3,10 +3,17 @@ export const useSVG = (source, onError) => {
|
|
3
3
|
if (source === null || source === undefined) {
|
4
4
|
throw new Error(`Invalid svg data source. Got: ${source}`);
|
5
5
|
}
|
6
|
-
|
6
|
+
let src;
|
7
|
+
if (typeof source === "string") {
|
8
|
+
src = source;
|
9
|
+
} else if (typeof source === "object" && "default" in source && typeof source.default === "string") {
|
10
|
+
src = source.default;
|
11
|
+
} else if (typeof source === "object" && "uri" in source) {
|
12
|
+
src = source.uri;
|
13
|
+
} else {
|
7
14
|
throw new Error(`Invalid svg data source. Make sure that the source resolves to a string. Got: ${JSON.stringify(source, null, 2)}`);
|
8
15
|
}
|
9
|
-
const svg = Skia.SVG.MakeFromString(
|
16
|
+
const svg = Skia.SVG.MakeFromString(src);
|
10
17
|
if (svg === null && onError !== undefined) {
|
11
18
|
onError(new Error("Failed to create SVG from source."));
|
12
19
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Skia","useSVG","source","onError","undefined","Error","
|
1
|
+
{"version":3,"names":["Skia","useSVG","source","onError","undefined","Error","src","default","uri","JSON","stringify","svg","SVG","MakeFromString"],"sources":["SVG.web.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { DataSourceParam } from \"../types\";\n\nexport const useSVG = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => {\n if (source === null || source === undefined) {\n throw new Error(`Invalid svg data source. Got: ${source}`);\n }\n let src: string;\n if (typeof source === \"string\") {\n src = source;\n } else if (\n typeof source === \"object\" &&\n \"default\" in source &&\n typeof source.default === \"string\"\n ) {\n src = source.default;\n } else if (typeof source === \"object\" && \"uri\" in source) {\n src = source.uri;\n } else {\n throw new Error(\n `Invalid svg data source. Make sure that the source resolves to a string. Got: ${JSON.stringify(\n source,\n null,\n 2\n )}`\n );\n }\n const svg = Skia.SVG.MakeFromString(src);\n if (svg === null && onError !== undefined) {\n onError(new Error(\"Failed to create SVG from source.\"));\n }\n return svg;\n};\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,SAAS;AAG9B,OAAO,MAAMC,MAAM,GAAGA,CACpBC,MAAuB,EACvBC,OAA8B,KAC3B;EACH,IAAID,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAKE,SAAS,EAAE;IAC3C,MAAM,IAAIC,KAAK,CAAC,iCAAiCH,MAAM,EAAE,CAAC;EAC5D;EACA,IAAII,GAAW;EACf,IAAI,OAAOJ,MAAM,KAAK,QAAQ,EAAE;IAC9BI,GAAG,GAAGJ,MAAM;EACd,CAAC,MAAM,IACL,OAAOA,MAAM,KAAK,QAAQ,IAC1B,SAAS,IAAIA,MAAM,IACnB,OAAOA,MAAM,CAACK,OAAO,KAAK,QAAQ,EAClC;IACAD,GAAG,GAAGJ,MAAM,CAACK,OAAO;EACtB,CAAC,MAAM,IAAI,OAAOL,MAAM,KAAK,QAAQ,IAAI,KAAK,IAAIA,MAAM,EAAE;IACxDI,GAAG,GAAGJ,MAAM,CAACM,GAAG;EAClB,CAAC,MAAM;IACL,MAAM,IAAIH,KAAK,CACb,iFAAiFI,IAAI,CAACC,SAAS,CAC7FR,MAAM,EACN,IAAI,EACJ,CACF,CAAC,EACH,CAAC;EACH;EACA,MAAMS,GAAG,GAAGX,IAAI,CAACY,GAAG,CAACC,cAAc,CAACP,GAAG,CAAC;EACxC,IAAIK,GAAG,KAAK,IAAI,IAAIR,OAAO,KAAKC,SAAS,EAAE;IACzCD,OAAO,CAAC,IAAIE,KAAK,CAAC,mCAAmC,CAAC,CAAC;EACzD;EACA,OAAOM,GAAG;AACZ,CAAC","ignoreList":[]}
|
@@ -2,6 +2,10 @@ import type { SharedValue } from "react-native-reanimated";
|
|
2
2
|
import type { BaseRecorder, JsiRecorder, Skia } from "../../skia/types";
|
3
3
|
import type { PaintProps, NodeType, BlurMaskFilterProps, CTMProps, BoxProps, BoxShadowProps, ImageProps, CircleProps, PointsProps, PathProps, RectProps, RoundedRectProps, OvalProps, LineProps, PatchProps, VerticesProps, DiffRectProps, TextProps, TextPathProps, TextBlobProps, GlyphsProps, PictureProps, ImageSVGProps, ParagraphProps, AtlasProps, SkottieProps } from "../../dom/types";
|
4
4
|
import type { AnimatedProps } from "../../renderer";
|
5
|
+
/**
|
6
|
+
* Currently the recorder only work if the GPU resources (e.g Images) are owned by the main thread.
|
7
|
+
* It will crash otherwise on Ganesh (iOS/Android).
|
8
|
+
*/
|
5
9
|
export declare class ReanimatedRecorder implements BaseRecorder {
|
6
10
|
private values;
|
7
11
|
private recorder;
|
@@ -2,6 +2,11 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
|
|
2
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
4
4
|
import { isSharedValue } from "../utils";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Currently the recorder only work if the GPU resources (e.g Images) are owned by the main thread.
|
8
|
+
* It will crash otherwise on Ganesh (iOS/Android).
|
9
|
+
*/
|
5
10
|
export class ReanimatedRecorder {
|
6
11
|
constructor(Skia) {
|
7
12
|
_defineProperty(this, "values", new Set());
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["isSharedValue","ReanimatedRecorder","constructor","Skia","_defineProperty","Set","recorder","Recorder","processAnimationValues","props","Object","values","forEach","value","has","name","size","add","getRecorder","getSharedValues","Array","from","saveGroup","restoreGroup","savePaint","standalone","restorePaint","restorePaintDeclaration","materializePaint","pushPathEffect","pathEffectType","pushImageFilter","imageFilterType","pushColorFilter","colorFilterType","pushShader","shaderType","children","pushBlurMaskFilter","composePathEffect","composeColorFilter","composeImageFilter","saveCTM","restoreCTM","drawPaint","saveLayer","saveBackdropFilter","drawBox","boxProps","shadows","shadow","map","s","drawImage","drawCircle","drawPoints","drawPath","drawRect","drawRRect","drawOval","drawLine","drawPatch","drawVertices","drawDiffRect","drawText","drawTextPath","drawTextBlob","drawGlyphs","drawPicture","drawImageSVG","drawParagraph","drawAtlas","drawSkottie"],"sources":["ReanimatedRecorder.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type { BaseRecorder, JsiRecorder, Skia } from \"../../skia/types\";\nimport type {\n PaintProps,\n NodeType,\n BlurMaskFilterProps,\n CTMProps,\n BoxProps,\n BoxShadowProps,\n ImageProps,\n CircleProps,\n PointsProps,\n PathProps,\n RectProps,\n RoundedRectProps,\n OvalProps,\n LineProps,\n PatchProps,\n VerticesProps,\n DiffRectProps,\n TextProps,\n TextPathProps,\n TextBlobProps,\n GlyphsProps,\n PictureProps,\n ImageSVGProps,\n ParagraphProps,\n AtlasProps,\n SkottieProps,\n} from \"../../dom/types\";\nimport type { AnimatedProps } from \"../../renderer\";\nimport { isSharedValue } from \"../utils\";\n\nexport class ReanimatedRecorder implements BaseRecorder {\n private values = new Set<SharedValue<unknown>>();\n private recorder: JsiRecorder;\n\n constructor(Skia: Skia) {\n this.recorder = Skia.Recorder();\n }\n\n private processAnimationValues(props?: Record<string, unknown>) {\n if (!props) {\n return;\n }\n Object.values(props).forEach((value) => {\n if (isSharedValue(value) && !this.values.has(value)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n value.name = `variable${this.values.size}`;\n this.values.add(value as SharedValue<unknown>);\n }\n });\n }\n\n getRecorder() {\n return this.recorder;\n }\n\n getSharedValues() {\n return Array.from(this.values);\n }\n\n saveGroup(): void {\n this.recorder.saveGroup();\n }\n\n restoreGroup(): void {\n this.recorder.restoreGroup();\n }\n\n savePaint(props: AnimatedProps<PaintProps>, standalone: boolean): void {\n this.processAnimationValues(props);\n this.recorder.savePaint(props, standalone);\n }\n\n restorePaint(): void {\n this.recorder.restorePaint();\n }\n\n restorePaintDeclaration(): void {\n this.recorder.restorePaintDeclaration();\n }\n\n materializePaint(): void {\n this.recorder.materializePaint();\n }\n\n pushPathEffect(\n pathEffectType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushPathEffect(pathEffectType, props);\n }\n\n pushImageFilter(\n imageFilterType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushImageFilter(imageFilterType, props);\n }\n\n pushColorFilter(\n colorFilterType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushColorFilter(colorFilterType, props);\n }\n\n pushShader(\n shaderType: NodeType,\n props: AnimatedProps<unknown>,\n children: number\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushShader(shaderType, props, children);\n }\n\n pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>): void {\n this.processAnimationValues(props);\n this.recorder.pushBlurMaskFilter(props);\n }\n\n composePathEffect(): void {\n this.recorder.composePathEffect();\n }\n\n composeColorFilter(): void {\n this.recorder.composeColorFilter();\n }\n\n composeImageFilter(): void {\n this.recorder.composeImageFilter();\n }\n\n saveCTM(props: AnimatedProps<CTMProps>): void {\n this.processAnimationValues(props);\n this.recorder.saveCTM(props);\n }\n\n restoreCTM(): void {\n this.recorder.restoreCTM();\n }\n\n drawPaint(): void {\n this.recorder.drawPaint();\n }\n\n saveLayer(): void {\n this.recorder.saveLayer();\n }\n\n saveBackdropFilter(): void {\n this.recorder.saveBackdropFilter();\n }\n\n drawBox(\n boxProps: AnimatedProps<BoxProps>,\n shadows: {\n props: BoxShadowProps;\n }[]\n ): void {\n this.processAnimationValues(boxProps);\n shadows.forEach((shadow) => {\n this.processAnimationValues(\n shadow.props as AnimatedProps<BoxShadowProps>\n );\n });\n this.recorder.drawBox(\n boxProps,\n // TODO: Fix this type BaseRecorder.drawBox()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n shadows.map((s) => s.props)\n );\n }\n\n drawImage(props: AnimatedProps<ImageProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawImage(props);\n }\n\n drawCircle(props: AnimatedProps<CircleProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawCircle(props);\n }\n\n drawPoints(props: AnimatedProps<PointsProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPoints(props);\n }\n\n drawPath(props: AnimatedProps<PathProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPath(props);\n }\n\n drawRect(props: AnimatedProps<RectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawRect(props);\n }\n\n drawRRect(props: AnimatedProps<RoundedRectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawRRect(props);\n }\n\n drawOval(props: AnimatedProps<OvalProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawOval(props);\n }\n\n drawLine(props: AnimatedProps<LineProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawLine(props);\n }\n\n drawPatch(props: AnimatedProps<PatchProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPatch(props);\n }\n\n drawVertices(props: AnimatedProps<VerticesProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawVertices(props);\n }\n\n drawDiffRect(props: AnimatedProps<DiffRectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawDiffRect(props);\n }\n\n drawText(props: AnimatedProps<TextProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawText(props);\n }\n\n drawTextPath(props: AnimatedProps<TextPathProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawTextPath(props);\n }\n\n drawTextBlob(props: AnimatedProps<TextBlobProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawTextBlob(props);\n }\n\n drawGlyphs(props: AnimatedProps<GlyphsProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawGlyphs(props);\n }\n\n drawPicture(props: AnimatedProps<PictureProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPicture(props);\n }\n\n drawImageSVG(props: AnimatedProps<ImageSVGProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawImageSVG(props);\n }\n\n drawParagraph(props: AnimatedProps<ParagraphProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawParagraph(props);\n }\n\n drawAtlas(props: AnimatedProps<AtlasProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawAtlas(props);\n }\n\n drawSkottie(props: AnimatedProps<SkottieProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawSkottie(props);\n }\n}\n"],"mappings":";;;AAgCA,SAASA,aAAa,QAAQ,UAAU;AAExC,OAAO,MAAMC,kBAAkB,CAAyB;EAItDC,WAAWA,CAACC,IAAU,EAAE;IAAAC,eAAA,iBAHP,IAAIC,GAAG,CAAuB,CAAC;IAAAD,eAAA;IAI9C,IAAI,CAACE,QAAQ,GAAGH,IAAI,CAACI,QAAQ,CAAC,CAAC;EACjC;EAEQC,sBAAsBA,CAACC,KAA+B,EAAE;IAC9D,IAAI,CAACA,KAAK,EAAE;MACV;IACF;IACAC,MAAM,CAACC,MAAM,CAACF,KAAK,CAAC,CAACG,OAAO,CAAEC,KAAK,IAAK;MACtC,IAAIb,aAAa,CAACa,KAAK,CAAC,IAAI,CAAC,IAAI,CAACF,MAAM,CAACG,GAAG,CAACD,KAAK,CAAC,EAAE;QACnD;QACA;QACAA,KAAK,CAACE,IAAI,GAAG,WAAW,IAAI,CAACJ,MAAM,CAACK,IAAI,EAAE;QAC1C,IAAI,CAACL,MAAM,CAACM,GAAG,CAACJ,KAA6B,CAAC;MAChD;IACF,CAAC,CAAC;EACJ;EAEAK,WAAWA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACZ,QAAQ;EACtB;EAEAa,eAAeA,CAAA,EAAG;IAChB,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACV,MAAM,CAAC;EAChC;EAEAW,SAASA,CAAA,EAAS;IAChB,IAAI,CAAChB,QAAQ,CAACgB,SAAS,CAAC,CAAC;EAC3B;EAEAC,YA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ACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAAC+D,YAAY,CAAC5D,KAAK,CAAC;EACnC;EAEA6D,aAAaA,CAAC7D,KAAoC,EAAQ;IACxD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACgE,aAAa,CAAC7D,KAAK,CAAC;EACpC;EAEA8D,SAASA,CAAC9D,KAAgC,EAAQ;IAChD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACiE,SAAS,CAAC9D,KAAK,CAAC;EAChC;EAEA+D,WAAWA,CAAC/D,KAAkC,EAAQ;IACpD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACkE,WAAW,CAAC/D,KAAK,CAAC;EAClC;AACF","ignoreList":[]}
|
1
|
+
{"version":3,"names":["isSharedValue","ReanimatedRecorder","constructor","Skia","_defineProperty","Set","recorder","Recorder","processAnimationValues","props","Object","values","forEach","value","has","name","size","add","getRecorder","getSharedValues","Array","from","saveGroup","restoreGroup","savePaint","standalone","restorePaint","restorePaintDeclaration","materializePaint","pushPathEffect","pathEffectType","pushImageFilter","imageFilterType","pushColorFilter","colorFilterType","pushShader","shaderType","children","pushBlurMaskFilter","composePathEffect","composeColorFilter","composeImageFilter","saveCTM","restoreCTM","drawPaint","saveLayer","saveBackdropFilter","drawBox","boxProps","shadows","shadow","map","s","drawImage","drawCircle","drawPoints","drawPath","drawRect","drawRRect","drawOval","drawLine","drawPatch","drawVertices","drawDiffRect","drawText","drawTextPath","drawTextBlob","drawGlyphs","drawPicture","drawImageSVG","drawParagraph","drawAtlas","drawSkottie"],"sources":["ReanimatedRecorder.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type { BaseRecorder, JsiRecorder, Skia } from \"../../skia/types\";\nimport type {\n PaintProps,\n NodeType,\n BlurMaskFilterProps,\n CTMProps,\n BoxProps,\n BoxShadowProps,\n ImageProps,\n CircleProps,\n PointsProps,\n PathProps,\n RectProps,\n RoundedRectProps,\n OvalProps,\n LineProps,\n PatchProps,\n VerticesProps,\n DiffRectProps,\n TextProps,\n TextPathProps,\n TextBlobProps,\n GlyphsProps,\n PictureProps,\n ImageSVGProps,\n ParagraphProps,\n AtlasProps,\n SkottieProps,\n} from \"../../dom/types\";\nimport type { AnimatedProps } from \"../../renderer\";\nimport { isSharedValue } from \"../utils\";\n\n/**\n * Currently the recorder only work if the GPU resources (e.g Images) are owned by the main thread.\n * It will crash otherwise on Ganesh (iOS/Android).\n */\nexport class ReanimatedRecorder implements BaseRecorder {\n private values = new Set<SharedValue<unknown>>();\n private recorder: JsiRecorder;\n\n constructor(Skia: Skia) {\n this.recorder = Skia.Recorder();\n }\n\n private processAnimationValues(props?: Record<string, unknown>) {\n if (!props) {\n return;\n }\n Object.values(props).forEach((value) => {\n if (isSharedValue(value) && !this.values.has(value)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n value.name = `variable${this.values.size}`;\n this.values.add(value as SharedValue<unknown>);\n }\n });\n }\n\n getRecorder() {\n return this.recorder;\n }\n\n getSharedValues() {\n return Array.from(this.values);\n }\n\n saveGroup(): void {\n this.recorder.saveGroup();\n }\n\n restoreGroup(): void {\n this.recorder.restoreGroup();\n }\n\n savePaint(props: AnimatedProps<PaintProps>, standalone: boolean): void {\n this.processAnimationValues(props);\n this.recorder.savePaint(props, standalone);\n }\n\n restorePaint(): void {\n this.recorder.restorePaint();\n }\n\n restorePaintDeclaration(): void {\n this.recorder.restorePaintDeclaration();\n }\n\n materializePaint(): void {\n this.recorder.materializePaint();\n }\n\n pushPathEffect(\n pathEffectType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushPathEffect(pathEffectType, props);\n }\n\n pushImageFilter(\n imageFilterType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushImageFilter(imageFilterType, props);\n }\n\n pushColorFilter(\n colorFilterType: NodeType,\n props: AnimatedProps<unknown>\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushColorFilter(colorFilterType, props);\n }\n\n pushShader(\n shaderType: NodeType,\n props: AnimatedProps<unknown>,\n children: number\n ): void {\n this.processAnimationValues(props);\n this.recorder.pushShader(shaderType, props, children);\n }\n\n pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>): void {\n this.processAnimationValues(props);\n this.recorder.pushBlurMaskFilter(props);\n }\n\n composePathEffect(): void {\n this.recorder.composePathEffect();\n }\n\n composeColorFilter(): void {\n this.recorder.composeColorFilter();\n }\n\n composeImageFilter(): void {\n this.recorder.composeImageFilter();\n }\n\n saveCTM(props: AnimatedProps<CTMProps>): void {\n this.processAnimationValues(props);\n this.recorder.saveCTM(props);\n }\n\n restoreCTM(): void {\n this.recorder.restoreCTM();\n }\n\n drawPaint(): void {\n this.recorder.drawPaint();\n }\n\n saveLayer(): void {\n this.recorder.saveLayer();\n }\n\n saveBackdropFilter(): void {\n this.recorder.saveBackdropFilter();\n }\n\n drawBox(\n boxProps: AnimatedProps<BoxProps>,\n shadows: {\n props: BoxShadowProps;\n }[]\n ): void {\n this.processAnimationValues(boxProps);\n shadows.forEach((shadow) => {\n this.processAnimationValues(\n shadow.props as AnimatedProps<BoxShadowProps>\n );\n });\n this.recorder.drawBox(\n boxProps,\n // TODO: Fix this type BaseRecorder.drawBox()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n shadows.map((s) => s.props)\n );\n }\n\n drawImage(props: AnimatedProps<ImageProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawImage(props);\n }\n\n drawCircle(props: AnimatedProps<CircleProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawCircle(props);\n }\n\n drawPoints(props: AnimatedProps<PointsProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPoints(props);\n }\n\n drawPath(props: AnimatedProps<PathProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPath(props);\n }\n\n drawRect(props: AnimatedProps<RectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawRect(props);\n }\n\n drawRRect(props: AnimatedProps<RoundedRectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawRRect(props);\n }\n\n drawOval(props: AnimatedProps<OvalProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawOval(props);\n }\n\n drawLine(props: AnimatedProps<LineProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawLine(props);\n }\n\n drawPatch(props: AnimatedProps<PatchProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPatch(props);\n }\n\n drawVertices(props: AnimatedProps<VerticesProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawVertices(props);\n }\n\n drawDiffRect(props: AnimatedProps<DiffRectProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawDiffRect(props);\n }\n\n drawText(props: AnimatedProps<TextProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawText(props);\n }\n\n drawTextPath(props: AnimatedProps<TextPathProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawTextPath(props);\n }\n\n drawTextBlob(props: AnimatedProps<TextBlobProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawTextBlob(props);\n }\n\n drawGlyphs(props: AnimatedProps<GlyphsProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawGlyphs(props);\n }\n\n drawPicture(props: AnimatedProps<PictureProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawPicture(props);\n }\n\n drawImageSVG(props: AnimatedProps<ImageSVGProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawImageSVG(props);\n }\n\n drawParagraph(props: AnimatedProps<ParagraphProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawParagraph(props);\n }\n\n drawAtlas(props: AnimatedProps<AtlasProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawAtlas(props);\n }\n\n drawSkottie(props: AnimatedProps<SkottieProps>): void {\n this.processAnimationValues(props);\n this.recorder.drawSkottie(props);\n }\n}\n"],"mappings":";;;AAgCA,SAASA,aAAa,QAAQ,UAAU;;AAExC;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,CAAyB;EAItDC,WAAWA,CAACC,IAAU,EAAE;IAAAC,eAAA,iBAHP,IAAIC,GAAG,CAAuB,CAAC;IAAAD,eAAA;IAI9C,IAAI,CAACE,QAAQ,GAAGH,IAAI,CAACI,QAAQ,CAAC,CAAC;EACjC;EAEQC,sBAAsBA,CAACC,KAA+B,EAAE;IAC9D,IAAI,CAACA,KAAK,EAAE;MACV;IACF;IACAC,MAAM,CAACC,MAAM,CAACF,KAAK,CAAC,CAACG,OAAO,CAAEC,KAAK,IAAK;MACtC,IAAIb,aAAa,CAACa,KAAK,CAAC,IAAI,CAAC,IAAI,CAACF,MAAM,CAACG,GAAG,CAACD,KAAK,CAAC,EAAE;QACnD;QACA;QACAA,KAAK,CAACE,IAAI,GAAG,WAAW,IAAI,CAACJ,MAAM,CAACK,IAAI,EAAE;QAC1C,IAAI,CAACL,MAAM,CAACM,GAAG,CAACJ,KAA6B,CAAC;MAChD;IACF,CAAC,CAAC;EACJ;EAEAK,WAAWA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACZ,QAAQ;EACtB;EAEAa,eAAeA,CAAA,EAAG;IAChB,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACV,MAAM,CAAC;EAChC;EAEAW,SAASA,CAAA,EAAS;IAChB,IAAI,CAAChB,QAAQ,CAACgB,SAAS,CAAC,CAAC;EAC3B;EAEAC,YAAYA,CAAA,EAAS;IACnB,IAAI,CAACjB,QAAQ,CAACiB,YAAY,CAAC,CAAC;EAC9B;EAEAC,SAASA,CAACf,KAAgC,EAAEgB,UAAmB,EAAQ;IACrE,IAAI,CAACjB,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACkB,SAAS,CAACf,KAAK,EAAEgB,UAA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AAC;EACpC;EAEA8D,SAASA,CAAC9D,KAAgC,EAAQ;IAChD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACiE,SAAS,CAAC9D,KAAK,CAAC;EAChC;EAEA+D,WAAWA,CAAC/D,KAAkC,EAAQ;IACpD,IAAI,CAACD,sBAAsB,CAACC,KAAK,CAAC;IAClC,IAAI,CAACH,QAAQ,CAACkE,WAAW,CAAC/D,KAAK,CAAC;EAClC;AACF","ignoreList":[]}
|
@@ -1,4 +1,8 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
|
+
/**
|
3
|
+
* Currently the recorder only work if the GPU resources (e.g Images) are owned by the main thread.
|
4
|
+
* It will crash otherwise on Ganesh (iOS/Android).
|
5
|
+
*/
|
2
6
|
export class ReanimatedRecorder {
|
3
7
|
constructor(Skia: any);
|
4
8
|
recorder: any;
|