@shopify/react-native-skia 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +13 -8
- package/cpp/rnskia/RNSkPlatformContext.h +2 -2
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +1 -5
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.h +42 -7
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +178 -5
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +8 -11
- package/lib/commonjs/external/ModuleProxy.d.ts +10 -0
- package/lib/commonjs/external/ModuleProxy.js +36 -0
- package/lib/commonjs/external/ModuleProxy.js.map +1 -0
- package/lib/commonjs/external/reanimated/ReanimatedProxy.d.ts +3 -0
- package/lib/commonjs/external/reanimated/ReanimatedProxy.js +18 -0
- package/lib/commonjs/external/reanimated/ReanimatedProxy.js.map +1 -0
- package/lib/commonjs/external/reanimated/buffers.js +9 -6
- package/lib/commonjs/external/reanimated/buffers.js.map +1 -1
- package/lib/commonjs/external/reanimated/interpolators.js +8 -7
- package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
- package/lib/commonjs/external/reanimated/renderHelpers.js +27 -11
- package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/commonjs/external/reanimated/textures.js +4 -3
- package/lib/commonjs/external/reanimated/textures.js.map +1 -1
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +6 -6
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
- package/lib/commonjs/external/reanimated/useDerivedValueOnJS.js +6 -5
- package/lib/commonjs/external/reanimated/useDerivedValueOnJS.js.map +1 -1
- package/lib/commonjs/renderer/Offscreen.js +1 -5
- package/lib/commonjs/renderer/Offscreen.js.map +1 -1
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +1 -1
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +0 -2
- package/lib/commonjs/specs/NativeSkiaModule.web.js +0 -8
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/module/external/ModuleProxy.d.ts +10 -0
- package/lib/module/external/ModuleProxy.js +28 -0
- package/lib/module/external/ModuleProxy.js.map +1 -0
- package/lib/module/external/reanimated/ReanimatedProxy.d.ts +3 -0
- package/lib/module/external/reanimated/ReanimatedProxy.js +12 -0
- package/lib/module/external/reanimated/ReanimatedProxy.js.map +1 -0
- package/lib/module/external/reanimated/buffers.js +8 -6
- package/lib/module/external/reanimated/buffers.js.map +1 -1
- package/lib/module/external/reanimated/interpolators.js +7 -7
- package/lib/module/external/reanimated/interpolators.js.map +1 -1
- package/lib/module/external/reanimated/renderHelpers.js +26 -11
- package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/module/external/reanimated/textures.js +3 -3
- package/lib/module/external/reanimated/textures.js.map +1 -1
- package/lib/module/external/reanimated/useAnimatedImageValue.js +5 -6
- package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
- package/lib/module/external/reanimated/useDerivedValueOnJS.js +5 -5
- package/lib/module/external/reanimated/useDerivedValueOnJS.js.map +1 -1
- package/lib/module/renderer/Offscreen.js +1 -5
- package/lib/module/renderer/Offscreen.js.map +1 -1
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +1 -1
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +0 -2
- package/lib/module/specs/NativeSkiaModule.web.js +0 -3
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/typescript/src/external/ModuleProxy.d.ts +10 -0
- package/lib/typescript/src/external/reanimated/ReanimatedProxy.d.ts +3 -0
- package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +1 -1
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +0 -2
- package/libs/ios/libskia.xcframework/Info.plist +5 -5
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/Info.plist +5 -5
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
- package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +1 -1
- package/src/external/ModuleProxy.ts +30 -0
- package/src/external/reanimated/ReanimatedProxy.ts +18 -0
- package/src/external/reanimated/buffers.ts +7 -6
- package/src/external/reanimated/interpolators.ts +7 -12
- package/src/external/reanimated/renderHelpers.ts +31 -18
- package/src/external/reanimated/textures.tsx +3 -3
- package/src/external/reanimated/useAnimatedImageValue.ts +5 -10
- package/src/external/reanimated/useDerivedValueOnJS.ts +5 -10
- package/src/renderer/Offscreen.tsx +1 -7
- package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +1 -1
- package/src/specs/NativeSkiaModule.web.ts +0 -4
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDrawViewManagerDelegate.java +0 -34
- package/cpp/skia/include/gpu/GrBackendDrawableInfo.h +0 -9
- package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +0 -15
- package/lib/commonjs/external/reanimated/moduleWrapper.js +0 -46
- package/lib/commonjs/external/reanimated/moduleWrapper.js.map +0 -1
- package/lib/module/external/reanimated/moduleWrapper.d.ts +0 -15
- package/lib/module/external/reanimated/moduleWrapper.js +0 -37
- package/lib/module/external/reanimated/moduleWrapper.js.map +0 -1
- package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +0 -15
- package/src/external/reanimated/moduleWrapper.ts +0 -83
@@ -6,19 +6,35 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.bindReanimatedProps = bindReanimatedProps;
|
7
7
|
exports.extractReanimatedProps = extractReanimatedProps;
|
8
8
|
exports.unbindReanimatedNode = void 0;
|
9
|
-
var
|
9
|
+
var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
11
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
11
12
|
|
13
|
+
let HAS_REANIMATED = false;
|
14
|
+
let HAS_REANIMATED_3 = false;
|
15
|
+
try {
|
16
|
+
require("react-native-reanimated");
|
17
|
+
HAS_REANIMATED = true;
|
18
|
+
const reanimatedVersion = require("react-native-reanimated/package.json").version;
|
19
|
+
if (reanimatedVersion && (reanimatedVersion >= "3.0.0" || reanimatedVersion.includes("3.0.0-"))) {
|
20
|
+
HAS_REANIMATED_3 = true;
|
21
|
+
}
|
22
|
+
} catch (e) {
|
23
|
+
HAS_REANIMATED = false;
|
24
|
+
}
|
12
25
|
const _bindings = new WeakMap();
|
13
26
|
const unbindReanimatedNode = node => {
|
27
|
+
if (!HAS_REANIMATED) {
|
28
|
+
return;
|
29
|
+
}
|
14
30
|
const previousMapperId = _bindings.get(node);
|
15
31
|
if (previousMapperId !== undefined) {
|
16
|
-
|
32
|
+
_ReanimatedProxy.default.stopMapper(previousMapperId);
|
17
33
|
}
|
18
34
|
};
|
19
35
|
exports.unbindReanimatedNode = unbindReanimatedNode;
|
20
36
|
function extractReanimatedProps(props) {
|
21
|
-
if (!
|
37
|
+
if (!HAS_REANIMATED) {
|
22
38
|
return [props, {}];
|
23
39
|
}
|
24
40
|
const reanimatedProps = {};
|
@@ -28,7 +44,7 @@ function extractReanimatedProps(props) {
|
|
28
44
|
continue;
|
29
45
|
}
|
30
46
|
const propValue = props[propName];
|
31
|
-
if (
|
47
|
+
if (_ReanimatedProxy.default.isSharedValue(propValue)) {
|
32
48
|
reanimatedProps[propName] = propValue;
|
33
49
|
otherProps[propName] = propValue.value;
|
34
50
|
} else {
|
@@ -41,7 +57,7 @@ function bindReanimatedProps2(container, node, reanimatedProps) {
|
|
41
57
|
const sharedValues = Object.values(reanimatedProps);
|
42
58
|
const previousMapperId = _bindings.get(node);
|
43
59
|
if (previousMapperId !== undefined) {
|
44
|
-
|
60
|
+
_ReanimatedProxy.default.stopMapper(previousMapperId);
|
45
61
|
}
|
46
62
|
if (sharedValues.length > 0) {
|
47
63
|
const viewId = container.getNativeId();
|
@@ -62,32 +78,32 @@ function bindReanimatedProps2(container, node, reanimatedProps) {
|
|
62
78
|
container.redraw();
|
63
79
|
}
|
64
80
|
};
|
65
|
-
const mapperId =
|
81
|
+
const mapperId = _ReanimatedProxy.default.startMapper(() => {
|
66
82
|
"worklet";
|
67
83
|
|
68
|
-
|
84
|
+
_ReanimatedProxy.default.runOnJS(updateProps)();
|
69
85
|
}, sharedValues);
|
70
86
|
_bindings.set(node, mapperId);
|
71
87
|
}
|
72
88
|
}
|
73
89
|
function bindReanimatedProps(container, node, reanimatedProps) {
|
74
|
-
if (
|
90
|
+
if (HAS_REANIMATED && !HAS_REANIMATED_3) {
|
75
91
|
return bindReanimatedProps2(container, node, reanimatedProps);
|
76
92
|
}
|
77
|
-
if (!
|
93
|
+
if (!HAS_REANIMATED) {
|
78
94
|
return;
|
79
95
|
}
|
80
96
|
const sharedValues = Object.values(reanimatedProps);
|
81
97
|
const previousMapperId = _bindings.get(node);
|
82
98
|
if (previousMapperId !== undefined) {
|
83
|
-
|
99
|
+
_ReanimatedProxy.default.stopMapper(previousMapperId);
|
84
100
|
}
|
85
101
|
if (sharedValues.length > 0) {
|
86
102
|
const viewId = container.getNativeId();
|
87
103
|
const {
|
88
104
|
SkiaViewApi
|
89
105
|
} = global;
|
90
|
-
const mapperId =
|
106
|
+
const mapperId = _ReanimatedProxy.default.startMapper(() => {
|
91
107
|
"worklet";
|
92
108
|
|
93
109
|
if (node) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_ReanimatedProxy","_interopRequireDefault","require","obj","__esModule","default","HAS_REANIMATED","HAS_REANIMATED_3","reanimatedVersion","version","includes","e","_bindings","WeakMap","unbindReanimatedNode","node","previousMapperId","get","undefined","Rea","stopMapper","exports","extractReanimatedProps","props","reanimatedProps","otherProps","propName","propValue","isSharedValue","value","bindReanimatedProps2","container","sharedValues","Object","values","length","viewId","getNativeId","SkiaViewApi","global","updateProps","setProp","requestRedraw","redraw","mapperId","startMapper","runOnJS","set","bindReanimatedProps"],"sources":["renderHelpers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Container } from \"../../renderer/Container\";\nimport type { AnimatedProps } from \"../../renderer/processors\";\nimport type { Node } from \"../../dom/types\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nlet HAS_REANIMATED = false;\nlet HAS_REANIMATED_3 = false;\ntry {\n require(\"react-native-reanimated\");\n HAS_REANIMATED = true;\n const reanimatedVersion =\n require(\"react-native-reanimated/package.json\").version;\n if (\n reanimatedVersion &&\n (reanimatedVersion >= \"3.0.0\" || reanimatedVersion.includes(\"3.0.0-\"))\n ) {\n HAS_REANIMATED_3 = true;\n }\n} catch (e) {\n HAS_REANIMATED = false;\n}\n\nconst _bindings = new WeakMap<Node<unknown>, unknown>();\n\nexport const unbindReanimatedNode = (node: Node<unknown>) => {\n if (!HAS_REANIMATED) {\n return;\n }\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n Rea.stopMapper(previousMapperId as number);\n }\n};\n\nexport function extractReanimatedProps(props: AnimatedProps<any>) {\n if (!HAS_REANIMATED) {\n return [props, {}];\n }\n const reanimatedProps = {} as AnimatedProps<any>;\n const otherProps = {} as AnimatedProps<any>;\n for (const propName in props) {\n if (propName === \"children\") {\n continue;\n }\n const propValue = props[propName];\n if (Rea.isSharedValue(propValue)) {\n reanimatedProps[propName] = propValue;\n otherProps[propName] = propValue.value;\n } else {\n otherProps[propName] = propValue;\n }\n }\n return [otherProps, reanimatedProps];\n}\n\nfunction bindReanimatedProps2(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n Rea.stopMapper(previousMapperId as number);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const updateProps = () => {\n for (const propName in reanimatedProps) {\n node && node.setProp(propName, reanimatedProps[propName].value);\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n };\n const mapperId = Rea.startMapper(() => {\n \"worklet\";\n Rea.runOnJS(updateProps)();\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n\nexport function bindReanimatedProps(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n if (HAS_REANIMATED && !HAS_REANIMATED_3) {\n return bindReanimatedProps2(container, node, reanimatedProps);\n }\n if (!HAS_REANIMATED) {\n return;\n }\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n Rea.stopMapper(previousMapperId as number);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const mapperId = Rea.startMapper(() => {\n \"worklet\";\n if (node) {\n for (const propName in reanimatedProps) {\n node.setProp(propName, reanimatedProps[propName].value);\n }\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n"],"mappings":";;;;;;;;AAMA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAoC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AANpC;;AAQA,IAAIG,cAAc,GAAG,KAAK;AAC1B,IAAIC,gBAAgB,GAAG,KAAK;AAC5B,IAAI;EACFL,OAAO,CAAC,yBAAyB,CAAC;EAClCI,cAAc,GAAG,IAAI;EACrB,MAAME,iBAAiB,GACrBN,OAAO,CAAC,sCAAsC,CAAC,CAACO,OAAO;EACzD,IACED,iBAAiB,KAChBA,iBAAiB,IAAI,OAAO,IAAIA,iBAAiB,CAACE,QAAQ,CAAC,QAAQ,CAAC,CAAC,EACtE;IACAH,gBAAgB,GAAG,IAAI;EACzB;AACF,CAAC,CAAC,OAAOI,CAAC,EAAE;EACVL,cAAc,GAAG,KAAK;AACxB;AAEA,MAAMM,SAAS,GAAG,IAAIC,OAAO,CAAyB,CAAC;AAEhD,MAAMC,oBAAoB,GAAIC,IAAmB,IAAK;EAC3D,IAAI,CAACT,cAAc,EAAE;IACnB;EACF;EACA,MAAMU,gBAAgB,GAAGJ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GC,MAAM;IAC9B,MAAMK,QAAQ,GAAGzB,wBAAG,CAAC0B,WAAW,CAAC,MAAM;MACrC,SAAS;;MACT,IAAI9B,IAAI,EAAE;QACR,KAAK,MAAMW,QAAQ,IAAIF,eAAe,EAAE;UACtCT,IAAI,CAAC0B,OAAO,CAACf,QAAQ,EAAEF,eAAe,CAACE,QAAQ,CAAC,CAACG,KAAK,CAAC;QACzD;MACF;MACA;MACA;MACA;MACA;MACA,IAAIS,WAAW,EAAE;QACfA,WAAW,CAACI,aAAa,CAACN,MAAM,CAAC;MACnC,CAAC,MAAM;QACLL,SAAS,CAACY,MAAM,CAAC,CAAC;MACpB;IACF,CAAC,EAAEX,YAAY,CAAC;IAChBpB,SAAS,CAACmC,GAAG,CAAChC,IAAI,EAAE6B,QAAQ,CAAC;EAC/B;AACF"}
|
@@ -7,7 +7,8 @@ exports.useTextureValueFromPicture = exports.useTextureAsValue = exports.useText
|
|
7
7
|
var _react = require("react");
|
8
8
|
var _Offscreen = require("../../renderer/Offscreen");
|
9
9
|
var _skia = require("../../skia");
|
10
|
-
var
|
10
|
+
var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
12
|
const createTexture = (texture, picture, size) => {
|
12
13
|
"worklet";
|
13
14
|
|
@@ -40,10 +41,10 @@ const useTextureValueFromPicture = (picture, size) => {
|
|
40
41
|
};
|
41
42
|
exports.useTextureValueFromPicture = useTextureValueFromPicture;
|
42
43
|
const usePictureAsTexture = (picture, size) => {
|
43
|
-
const texture =
|
44
|
+
const texture = _ReanimatedProxy.default.useSharedValue(null);
|
44
45
|
(0, _react.useEffect)(() => {
|
45
46
|
if (picture !== null) {
|
46
|
-
|
47
|
+
_ReanimatedProxy.default.runOnUI(createTexture)(texture, picture, size);
|
47
48
|
}
|
48
49
|
}, [texture, picture, size]);
|
49
50
|
return texture;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_Offscreen","_skia","
|
1
|
+
{"version":3,"names":["_react","require","_Offscreen","_skia","_ReanimatedProxy","_interopRequireDefault","obj","__esModule","default","createTexture","texture","picture","size","value","drawAsImageFromPicture","useTexture","element","width","height","useMemo","drawAsPicture","x","y","usePictureAsTexture","exports","useTextureAsValue","console","warn","useTextureValueFromPicture","Rea","useSharedValue","useEffect","runOnUI","useImageAsTexture","source","image","useImage","recorder","Skia","PictureRecorder","canvas","beginRecording","drawImage","finishRecordingAsPicture"],"sources":["textures.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport type { 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 {\n drawAsImageFromPicture,\n drawAsPicture,\n} from \"../../renderer/Offscreen\";\nimport { Skia, useImage } from \"../../skia\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst createTexture = (\n texture: SharedValue<SkImage | null>,\n picture: SkPicture,\n size: SkSize\n) => {\n \"worklet\";\n texture.value = drawAsImageFromPicture(picture, size);\n};\n\nexport const useTexture = (element: ReactElement, size: SkSize) => {\n const { width, height } = size;\n const picture = useMemo(() => {\n return drawAsPicture(element, {\n x: 0,\n y: 0,\n width,\n height,\n });\n }, [element, width, height]);\n return usePictureAsTexture(picture, size);\n};\n\nexport const useTextureAsValue = (element: ReactElement, size: SkSize) => {\n console.warn(\"useTextureAsValue has been renamed to use useTexture\");\n return useTexture(element, size);\n};\n\nexport const useTextureValueFromPicture = (\n picture: SkPicture | null,\n size: SkSize\n) => {\n console.warn(\n \"useTextureValueFromPicture has been renamed to use usePictureAsTexture\"\n );\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 }, [texture, picture, size]);\n return texture;\n};\n\nexport const useImageAsTexture = (source: DataSourceParam) => {\n const image = useImage(source);\n const size = useMemo(() => {\n if (image) {\n return { width: image.width(), height: image.height() };\n }\n return { width: 0, height: 0 };\n }, [image]);\n const picture = useMemo(() => {\n if (image) {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording({\n x: 0,\n y: 0,\n width: size.width,\n height: size.height,\n });\n canvas.drawImage(image, 0, 0);\n return recorder.finishRecordingAsPicture();\n } else {\n return null;\n }\n }, [size, image]);\n return usePictureAsTexture(picture, size);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAUA,IAAAC,UAAA,GAAAD,OAAA;AAIA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,gBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAAoC,SAAAI,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEpC,MAAMG,aAAa,GAAGA,CACpBC,OAAoC,EACpCC,OAAkB,EAClBC,IAAY,KACT;EACH,SAAS;;EACTF,OAAO,CAACG,KAAK,GAAG,IAAAC,iCAAsB,EAACH,OAAO,EAAEC,IAAI,CAAC;AACvD,CAAC;AAEM,MAAMG,UAAU,GAAGA,CAACC,OAAqB,EAAEJ,IAAY,KAAK;EACjE,MAAM;IAAEK,KAAK;IAAEC;EAAO,CAAC,GAAGN,IAAI;EAC9B,MAAMD,OAAO,GAAG,IAAAQ,cAAO,EAAC,MAAM;IAC5B,OAAO,IAAAC,wBAAa,EAACJ,OAAO,EAAE;MAC5BK,CAAC,EAAE,CAAC;MACJC,CAAC,EAAE,CAAC;MACJL,KAAK;MACLC;IACF,CAAC,CAAC;EACJ,CAAC,EAAE,CAACF,OAAO,EAAEC,KAAK,EAAEC,MAAM,CAAC,CAAC;EAC5B,OAAOK,mBAAmB,CAACZ,OAAO,EAAEC,IAAI,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OAAO;MAAED,KAAK,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAE,CAAC;EAChC,CAAC,EAAE,CAACiB,KAAK,CAAC,CAAC;EACX,MAAMxB,OAAO,GAAG,IAAAQ,cAAO,EAAC,MAAM;IAC5B,IAAIgB,KAAK,EAAE;MACT,MAAME,QAAQ,GAAGC,UAAI,CAACC,eAAe,CAAC,CAAC;MACvC,MAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAc,CAAC;QACrCpB,CAAC,EAAE,CAAC;QACJC,CAAC,EAAE,CAAC;QACJL,KAAK,EAAEL,IAAI,CAACK,KAAK;QACjBC,MAAM,EAAEN,IAAI,CAACM;MACf,CAAC,CAAC;MACFsB,MAAM,CAACE,SAAS,CAACP,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;MAC7B,OAAOE,QAAQ,CAACM,wBAAwB,CAAC,CAAC;IAC5C,CAAC,MAAM;MACL,OAAO,IAAI;IACb;EACF,CAAC,EAAE,CAAC/B,IAAI,EAAEuB,KAAK,CAAC,CAAC;EACjB,OAAOZ,mBAAmB,CAACZ,OAAO,EAAEC,IAAI,CAAC;AAC3C,CAAC;AAACY,OAAA,CAAAS,iBAAA,GAAAA,iBAAA"}
|
@@ -6,20 +6,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.useAnimatedImageValue = void 0;
|
7
7
|
var _react = require("react");
|
8
8
|
var _AnimatedImage = require("../../skia/core/AnimatedImage");
|
9
|
-
var
|
9
|
+
var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
11
|
const DEFAULT_FRAME_DURATION = 60;
|
11
12
|
const useAnimatedImageValue = (source, paused) => {
|
12
|
-
|
13
|
-
const defaultPaused = (0, _moduleWrapper.useSharedValue)(false);
|
13
|
+
const defaultPaused = _ReanimatedProxy.default.useSharedValue(false);
|
14
14
|
const isPaused = paused !== null && paused !== void 0 ? paused : defaultPaused;
|
15
|
-
const currentFrame =
|
16
|
-
const lastTimestamp =
|
15
|
+
const currentFrame = _ReanimatedProxy.default.useSharedValue(null);
|
16
|
+
const lastTimestamp = _ReanimatedProxy.default.useSharedValue(-1);
|
17
17
|
const animatedImage = (0, _AnimatedImage.useAnimatedImage)(source, err => {
|
18
18
|
console.error(err);
|
19
19
|
throw new Error(`Could not load animated image - got '${err.message}'`);
|
20
20
|
}, false);
|
21
21
|
const frameDuration = (animatedImage === null || animatedImage === void 0 ? void 0 : animatedImage.currentFrameDuration()) || DEFAULT_FRAME_DURATION;
|
22
|
-
|
22
|
+
_ReanimatedProxy.default.useFrameCallback(frameInfo => {
|
23
23
|
if (!animatedImage) {
|
24
24
|
currentFrame.value = null;
|
25
25
|
return;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_AnimatedImage","
|
1
|
+
{"version":3,"names":["_react","require","_AnimatedImage","_ReanimatedProxy","_interopRequireDefault","obj","__esModule","default","DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","paused","defaultPaused","Rea","useSharedValue","isPaused","currentFrame","lastTimestamp","animatedImage","useAnimatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","useFrameCallback","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame","useEffect","exports"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { type FrameInfo, type SharedValue } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (\n source: DataSourceParam,\n paused?: SharedValue<boolean>\n) => {\n const defaultPaused = Rea.useSharedValue(false);\n const isPaused = paused ?? defaultPaused;\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const lastTimestamp = Rea.useSharedValue(-1);\n const animatedImage = useAnimatedImage(\n source,\n (err) => {\n console.error(err);\n throw new Error(`Could not load animated image - got '${err.message}'`);\n },\n false\n );\n const frameDuration =\n animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;\n\n Rea.useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n if (isPaused.value && lastTimestamp.value !== -1) {\n return;\n }\n const { timestamp } = frameInfo;\n const elapsed = timestamp - lastTimestamp.value;\n\n // Check if it's time to switch frames based on GIF frame duration\n if (elapsed < frameDuration) {\n return;\n }\n\n // Update the current frame\n animatedImage.decodeNextFrame();\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n currentFrame.value = animatedImage.getCurrentFrame();\n\n // Update the last timestamp\n lastTimestamp.value = timestamp;\n });\n useEffect(() => {\n return () => {\n animatedImage?.dispose();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return currentFrame;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AAGA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAoC,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEpC,MAAMG,sBAAsB,GAAG,EAAE;AAE1B,MAAMC,qBAAqB,GAAGA,CACnCC,MAAuB,EACvBC,MAA6B,KAC1B;EACH,MAAMC,aAAa,GAAGC,wBAAG,CAACC,cAAc,CAAC,KAAK,CAAC;EAC/C,MAAMC,QAAQ,GAAGJ,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIC,aAAa;EACxC,MAAMI,YAAY,GAAGH,wBAAG,CAACC,cAAc,CAAiB,IAAI,CAAC;EAC7D,MAAMG,aAAa,GAAGJ,wBAAG,CAACC,cAAc,CAAC,CAAC,CAAC,CAAC;EAC5C,MAAMI,aAAa,GAAG,IAA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
5
5
|
});
|
6
6
|
exports.useDerivedValueOnJS = void 0;
|
7
7
|
var _react = require("react");
|
8
|
-
var
|
8
|
+
var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
10
|
const useDerivedValueOnJS = (fn, deps) => {
|
10
11
|
const init = (0, _react.useMemo)(() => fn(), [fn]);
|
11
|
-
const value =
|
12
|
+
const value = _ReanimatedProxy.default.useSharedValue(init);
|
12
13
|
(0, _react.useEffect)(() => {
|
13
|
-
const mapperId =
|
14
|
+
const mapperId = _ReanimatedProxy.default.startMapper(() => {
|
14
15
|
"worklet";
|
15
16
|
|
16
|
-
|
17
|
+
_ReanimatedProxy.default.runOnJS(fn)();
|
17
18
|
}, deps);
|
18
|
-
return () =>
|
19
|
+
return () => _ReanimatedProxy.default.stopMapper(mapperId);
|
19
20
|
}, [deps, fn]);
|
20
21
|
return value;
|
21
22
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","require","
|
1
|
+
{"version":3,"names":["_react","require","_ReanimatedProxy","_interopRequireDefault","obj","__esModule","default","useDerivedValueOnJS","fn","deps","init","useMemo","value","Rea","useSharedValue","useEffect","mapperId","startMapper","runOnJS","stopMapper","exports"],"sources":["useDerivedValueOnJS.ts"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nexport const useDerivedValueOnJS = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fn: () => any,\n deps: unknown[]\n) => {\n const init = useMemo(() => fn(), [fn]);\n const value = Rea.useSharedValue(init);\n useEffect(() => {\n const mapperId = Rea.startMapper(() => {\n \"worklet\";\n Rea.runOnJS(fn)();\n }, deps);\n return () => Rea.stopMapper(mapperId);\n }, [deps, fn]);\n return value;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAoC,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE7B,MAAMG,mBAAmB,GAAGA,CAEjCC,EAAa,EACbC,IAAe,KACZ;EACH,MAAMC,IAAI,GAAG,IAAAC,cAAO,EAAC,MAAMH,EAAE,CAAC,CAAC,EAAE,CAACA,EAAE,CAAC,CAAC;EACtC,MAAMI,KAAK,GAAGC,wBAAG,CAACC,cAAc,CAACJ,IAAI,CAAC;EACtC,IAAAK,gBAAS,EAAC,MAAM;IACd,MAAMC,QAAQ,GAAGH,wBAAG,CAACI,WAAW,CAAC,MAAM;MACrC,SAAS;;MACTJ,wBAAG,CAACK,OAAO,CAACV,EAAE,CAAC,CAAC,CAAC;IACnB,CAAC,EAAEC,IAAI,CAAC;IACR,OAAO,MAAMI,wBAAG,CAACM,UAAU,CAACH,QAAQ,CAAC;EACvC,CAAC,EAAE,CAACP,IAAI,EAAED,EAAE,CAAC,CAAC;EACd,OAAOI,KAAK;AACd,CAAC;AAACQ,OAAA,CAAAb,mBAAA,GAAAA,mBAAA"}
|
@@ -30,16 +30,12 @@ exports.drawAsPicture = drawAsPicture;
|
|
30
30
|
const drawAsImage = (element, size) => {
|
31
31
|
return drawAsImageFromPicture(drawAsPicture(element), size);
|
32
32
|
};
|
33
|
-
|
34
|
-
// TODO: We're not sure yet why PixelRatio is not needed here.
|
35
33
|
exports.drawAsImage = drawAsImage;
|
36
|
-
const pd = 1;
|
37
34
|
const drawAsImageFromPicture = (picture, size) => {
|
38
35
|
"worklet";
|
39
36
|
|
40
|
-
const surface = _skia.Skia.Surface.MakeOffscreen(size.width
|
37
|
+
const surface = _skia.Skia.Surface.MakeOffscreen(size.width, size.height);
|
41
38
|
const canvas = surface.getCanvas();
|
42
|
-
canvas.scale(pd, pd);
|
43
39
|
canvas.drawPicture(picture);
|
44
40
|
surface.flush();
|
45
41
|
const image = surface.makeImageSnapshot();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_types","require","_skia","_Platform","_Reconciler","isOnMainThread","_WORKLET","Platform","OS","exports","drawAsPicture","element","bounds","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaRoot","render","ctx","JsiDrawingContext","dom","picture","finishRecordingAsPicture","unmount","drawAsImage","size","drawAsImageFromPicture","
|
1
|
+
{"version":3,"names":["_types","require","_skia","_Platform","_Reconciler","isOnMainThread","_WORKLET","Platform","OS","exports","drawAsPicture","element","bounds","recorder","Skia","PictureRecorder","canvas","beginRecording","root","SkiaRoot","render","ctx","JsiDrawingContext","dom","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 { JsiDrawingContext } from \"../dom/types\";\nimport type { SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\n\nimport { SkiaRoot } from \"./Reconciler\";\n\n// We call it main thread because on web main is JS thread\nexport const isOnMainThread = () => {\n \"worklet\";\n return (\n (typeof _WORKLET !== \"undefined\" && _WORKLET === true) ||\n Platform.OS === \"web\"\n );\n};\n\nexport const drawAsPicture = (element: ReactElement, bounds?: SkRect) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(bounds);\n const root = new SkiaRoot(Skia, false);\n root.render(element);\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.dom.render(ctx);\n const picture = recorder.finishRecordingAsPicture();\n root.unmount();\n return picture;\n};\n\nexport const drawAsImage = (element: ReactElement, size: SkSize) => {\n return drawAsImageFromPicture(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 // If we are not on the main thread or if we are on Web, we need to make the image non-texture.\n if (!isOnMainThread() || Platform.OS === \"web\") {\n return image.makeNonTextureImage();\n } else {\n return image;\n }\n};\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAEA;AACO,MAAMI,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,GAAGA,CAACC,OAAqB,EAAEC,MAAe,KAAK;EACvE,MAAMC,QAAQ,GAAGC,UAAI,CAACC,eAAe,CAAC,CAAC;EACvC,MAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAc,CAACL,MAAM,CAAC;EAC9C,MAAMM,IAAI,GAAG,IAAIC,oBAAQ,CAACL,UAAI,EAAE,KAAK,CAAC;EACtCI,IAAI,CAACE,MAAM,CAACT,OAAO,CAAC;EACpB,MAAMU,GAAG,GAAG,IAAIC,wBAAiB,CAACR,UAAI,EAAEE,MAAM,CAAC;EAC/CE,IAAI,CAACK,GAAG,CAACH,MAAM,CAACC,GAAG,CAAC;EACpB,MAAMG,OAAO,GAAGX,QAAQ,CAACY,wBAAwB,CAAC,CAAC;EACnDP,IAAI,CAACQ,OAAO,CAAC,CAAC;EACd,OAAOF,OAAO;AAChB,CAAC;AAACf,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEK,MAAMiB,WAAW,GAAGA,CAAChB,OAAqB,EAAEiB,IAAY,KAAK;EAClE,OAAOC,sBAAsB,CAACnB,aAAa,CAACC,OAAO,CAAC,EAAEiB,IAAI,CAAC;AAC7D,CAAC;AAACnB,OAAA,CAAAkB,WAAA,GAAAA,WAAA;AAEK,MAAME,sBAAsB,GAAGA,CAACL,OAAkB,EAAEI,IAAY,KAAK;EAC1E,SAAS;;EACT,MAAME,OAAO,GAAGhB,UAAI,CAACiB,OAAO,CAACC,aAAa,CAACJ,IAAI,CAACK,KAAK,EAAEL,IAAI,CAACM,MAAM,CAAE;EACpE,MAAMlB,MAAM,GAAGc,OAAO,CAACK,SAAS,CAAC,CAAC;EAClCnB,MAAM,CAACoB,WAAW,CAACZ,OAAO,CAAC;EAC3BM,OAAO,CAACO,KAAK,CAAC,CAAC;EACf,MAAMC,KAAK,GAAGR,OAAO,CAACS,iBAAiB,CAAC,CAAC;EACzC;EACA,IAAI,CAAClC,cAAc,CAAC,CAAC,IAAIE,kBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;IAC9C,OAAO8B,KAAK,CAACE,mBAAmB,CAAC,CAAC;EACpC,CAAC,MAAM;IACL,OAAOF,KAAK;EACd;AACF,CAAC;AAAC7B,OAAA,CAAAoB,sBAAA,GAAAA,sBAAA"}
|
@@ -8,7 +8,7 @@ export declare const isNativeBufferWeb: (buffer: NativeBuffer) => buffer is Canv
|
|
8
8
|
export declare const isNativeBufferNode: (buffer: NativeBuffer) => buffer is ArrayBuffer;
|
9
9
|
export interface NativeBufferFactory {
|
10
10
|
/**
|
11
|
-
* Copy pixels to a
|
11
|
+
* Copy pixels to a native buffer.
|
12
12
|
*/
|
13
13
|
MakeFromImage: (image: SkImage) => NativeBuffer;
|
14
14
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["isNativeBufferAddr","buffer","BigInt","exports","isNativeBufferWeb","HTMLVideoElement","HTMLCanvasElement","ImageBitmap","OffscreenCanvas","VideoFrame","HTMLImageElement","SVGImageElement","isNativeBufferNode","ArrayBuffer"],"sources":["NativeBufferFactory.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\n\nexport type NativeBuffer<\n T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown\n> = T;\n\nexport type NativeBufferAddr = NativeBuffer<bigint>;\nexport type NativeBufferWeb = NativeBuffer<CanvasImageSource>;\nexport type NativeBufferNode = NativeBuffer<ArrayBuffer>;\n\nexport const isNativeBufferAddr = (\n buffer: NativeBuffer\n): buffer is NativeBufferAddr => buffer instanceof BigInt;\nexport const isNativeBufferWeb = (\n buffer: NativeBuffer\n): buffer is NativeBufferWeb =>\n buffer instanceof HTMLVideoElement ||\n buffer instanceof HTMLCanvasElement ||\n buffer instanceof ImageBitmap ||\n buffer instanceof OffscreenCanvas ||\n buffer instanceof VideoFrame ||\n buffer instanceof HTMLImageElement ||\n buffer instanceof SVGImageElement;\n\nexport const isNativeBufferNode = (\n buffer: NativeBuffer\n): buffer is NativeBufferNode => buffer instanceof ArrayBuffer;\n\nexport interface NativeBufferFactory {\n /**\n * Copy pixels to a
|
1
|
+
{"version":3,"names":["isNativeBufferAddr","buffer","BigInt","exports","isNativeBufferWeb","HTMLVideoElement","HTMLCanvasElement","ImageBitmap","OffscreenCanvas","VideoFrame","HTMLImageElement","SVGImageElement","isNativeBufferNode","ArrayBuffer"],"sources":["NativeBufferFactory.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\n\nexport type NativeBuffer<\n T extends bigint | ArrayBuffer | CanvasImageSource | unknown = unknown\n> = T;\n\nexport type NativeBufferAddr = NativeBuffer<bigint>;\nexport type NativeBufferWeb = NativeBuffer<CanvasImageSource>;\nexport type NativeBufferNode = NativeBuffer<ArrayBuffer>;\n\nexport const isNativeBufferAddr = (\n buffer: NativeBuffer\n): buffer is NativeBufferAddr => buffer instanceof BigInt;\nexport const isNativeBufferWeb = (\n buffer: NativeBuffer\n): buffer is NativeBufferWeb =>\n buffer instanceof HTMLVideoElement ||\n buffer instanceof HTMLCanvasElement ||\n buffer instanceof ImageBitmap ||\n buffer instanceof OffscreenCanvas ||\n buffer instanceof VideoFrame ||\n buffer instanceof HTMLImageElement ||\n buffer instanceof SVGImageElement;\n\nexport const isNativeBufferNode = (\n buffer: NativeBuffer\n): buffer is NativeBufferNode => buffer instanceof ArrayBuffer;\n\nexport interface NativeBufferFactory {\n /**\n * Copy pixels to a native buffer.\n */\n MakeFromImage: (image: SkImage) => NativeBuffer;\n /**\n * Release a platform buffer that was created with `MakeFromImage`.\n */\n Release: (platformBuffer: NativeBuffer) => void;\n}\n"],"mappings":";;;;;;AAUO,MAAMA,kBAAkB,GAC7BC,MAAoB,IACWA,MAAM,YAAYC,MAAM;AAACC,OAAA,CAAAH,kBAAA,GAAAA,kBAAA;AACnD,MAAMI,iBAAiB,GAC5BH,MAAoB,IAEpBA,MAAM,YAAYI,gBAAgB,IAClCJ,MAAM,YAAYK,iBAAiB,IACnCL,MAAM,YAAYM,WAAW,IAC7BN,MAAM,YAAYO,eAAe,IACjCP,MAAM,YAAYQ,UAAU,IAC5BR,MAAM,YAAYS,gBAAgB,IAClCT,MAAM,YAAYU,eAAe;AAACR,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AAE7B,MAAMQ,kBAAkB,GAC7BX,MAAoB,IACWA,MAAM,YAAYY,WAAW;AAACV,OAAA,CAAAS,kBAAA,GAAAA,kBAAA"}
|
@@ -1,10 +1,2 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
var _moduleWrapper = require("../external/reanimated/moduleWrapper");
|
8
|
-
// eslint-disable-next-line import/no-default-export
|
9
|
-
var _default = exports.default = _moduleWrapper.throwOnMissingReanimated;
|
10
2
|
//# sourceMappingURL=NativeSkiaModule.web.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[
|
1
|
+
{"version":3,"names":[],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":[""],"mappings":""}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
type ImportType = ReturnType<typeof require>;
|
2
|
+
/**
|
3
|
+
* Create a lazily-imported module proxy.
|
4
|
+
* This is useful for lazily requiring optional dependencies.
|
5
|
+
*/
|
6
|
+
export declare const createModuleProxy: <TModule>(getModule: () => ImportType) => TModule;
|
7
|
+
export declare class OptionalDependencyNotInstalledError extends Error {
|
8
|
+
constructor(name: string);
|
9
|
+
}
|
10
|
+
export {};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// https://github.com/mrousavy/react-native-vision-camera/blob/main/package/src/dependencies/ModuleProxy.ts
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Create a lazily-imported module proxy.
|
5
|
+
* This is useful for lazily requiring optional dependencies.
|
6
|
+
*/
|
7
|
+
export const createModuleProxy = getModule => {
|
8
|
+
const holder = {
|
9
|
+
module: undefined
|
10
|
+
};
|
11
|
+
const proxy = new Proxy(holder, {
|
12
|
+
get: (target, property) => {
|
13
|
+
if (target.module == null) {
|
14
|
+
// lazy initialize module via require()
|
15
|
+
// caller needs to make sure the require() call is wrapped in a try/catch
|
16
|
+
target.module = getModule();
|
17
|
+
}
|
18
|
+
return target.module[property];
|
19
|
+
}
|
20
|
+
});
|
21
|
+
return proxy;
|
22
|
+
};
|
23
|
+
export class OptionalDependencyNotInstalledError extends Error {
|
24
|
+
constructor(name) {
|
25
|
+
super(`${name} is not installed!`);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
//# sourceMappingURL=ModuleProxy.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["createModuleProxy","getModule","holder","module","undefined","proxy","Proxy","get","target","property","OptionalDependencyNotInstalledError","Error","constructor","name"],"sources":["ModuleProxy.ts"],"sourcesContent":["// https://github.com/mrousavy/react-native-vision-camera/blob/main/package/src/dependencies/ModuleProxy.ts\ntype ImportType = ReturnType<typeof require>;\n\n/**\n * Create a lazily-imported module proxy.\n * This is useful for lazily requiring optional dependencies.\n */\nexport const createModuleProxy = <TModule>(\n getModule: () => ImportType\n): TModule => {\n const holder: { module: TModule | undefined } = { module: undefined };\n\n const proxy = new Proxy(holder, {\n get: (target, property) => {\n if (target.module == null) {\n // lazy initialize module via require()\n // caller needs to make sure the require() call is wrapped in a try/catch\n target.module = getModule() as TModule;\n }\n return target.module[property as keyof typeof holder.module];\n },\n });\n return proxy as unknown as TModule;\n};\n\nexport class OptionalDependencyNotInstalledError extends Error {\n constructor(name: string) {\n super(`${name} is not installed!`);\n }\n}\n"],"mappings":"AAAA;;AAGA;AACA;AACA;AACA;AACA,OAAO,MAAMA,iBAAiB,GAC5BC,SAA2B,IACf;EACZ,MAAMC,MAAuC,GAAG;IAAEC,MAAM,EAAEC;EAAU,CAAC;EAErE,MAAMC,KAAK,GAAG,IAAIC,KAAK,CAACJ,MAAM,EAAE;IAC9BK,GAAG,EAAEA,CAACC,MAAM,EAAEC,QAAQ,KAAK;MACzB,IAAID,MAAM,CAACL,MAAM,IAAI,IAAI,EAAE;QACzB;QACA;QACAK,MAAM,CAACL,MAAM,GAAGF,SAAS,CAAC,CAAY;MACxC;MACA,OAAOO,MAAM,CAACL,MAAM,CAACM,QAAQ,CAA+B;IAC9D;EACF,CAAC,CAAC;EACF,OAAOJ,KAAK;AACd,CAAC;AAED,OAAO,MAAMK,mCAAmC,SAASC,KAAK,CAAC;EAC7DC,WAAWA,CAACC,IAAY,EAAE;IACxB,KAAK,CAAE,GAAEA,IAAK,oBAAmB,CAAC;EACpC;AACF"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { OptionalDependencyNotInstalledError, createModuleProxy } from "../ModuleProxy";
|
2
|
+
const Reanimated = createModuleProxy(() => {
|
3
|
+
try {
|
4
|
+
return require("react-native-reanimated");
|
5
|
+
} catch (e) {
|
6
|
+
throw new OptionalDependencyNotInstalledError("react-native-reanimated");
|
7
|
+
}
|
8
|
+
});
|
9
|
+
|
10
|
+
// eslint-disable-next-line import/no-default-export
|
11
|
+
export default Reanimated;
|
12
|
+
//# sourceMappingURL=ReanimatedProxy.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["OptionalDependencyNotInstalledError","createModuleProxy","Reanimated","require","e"],"sources":["ReanimatedProxy.ts"],"sourcesContent":["import type * as ReanimatedT from \"react-native-reanimated\";\n\nimport {\n OptionalDependencyNotInstalledError,\n createModuleProxy,\n} from \"../ModuleProxy\";\ntype TReanimated = typeof ReanimatedT;\n\nconst Reanimated = createModuleProxy<TReanimated>(() => {\n try {\n return require(\"react-native-reanimated\");\n } catch (e) {\n throw new OptionalDependencyNotInstalledError(\"react-native-reanimated\");\n }\n});\n\n// eslint-disable-next-line import/no-default-export\nexport default Reanimated;\n"],"mappings":"AAEA,SACEA,mCAAmC,EACnCC,iBAAiB,QACZ,gBAAgB;AAGvB,MAAMC,UAAU,GAAGD,iBAAiB,CAAc,MAAM;EACtD,IAAI;IACF,OAAOE,OAAO,CAAC,yBAAyB,CAAC;EAC3C,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,MAAM,IAAIJ,mCAAmC,CAAC,yBAAyB,CAAC;EAC1E;AACF,CAAC,CAAC;;AAEF;AACA,eAAeE,UAAU"}
|
@@ -1,16 +1,18 @@
|
|
1
1
|
import { useEffect, useMemo } from "react";
|
2
2
|
import { Skia } from "../../skia";
|
3
|
-
import { startMapper, stopMapper, makeMutable } from "./moduleWrapper";
|
4
3
|
import { notifyChange } from "./interpolators";
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
import Rea from "./ReanimatedProxy";
|
5
|
+
const useBufferValue = (size, bufferInitializer) => {
|
6
|
+
return useMemo(() => Rea.makeMutable(new Array(size).fill(0).map(bufferInitializer)),
|
7
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
8
|
+
[size]);
|
9
|
+
};
|
8
10
|
const useBuffer = (size, bufferInitializer, modifier) => {
|
9
11
|
var _mod$__closure;
|
10
12
|
const values = useBufferValue(size, bufferInitializer);
|
11
13
|
const mod = modifier;
|
12
14
|
const deps = [size, ...Object.values((_mod$__closure = mod.__closure) !== null && _mod$__closure !== void 0 ? _mod$__closure : {})];
|
13
|
-
const mapperId = startMapper(() => {
|
15
|
+
const mapperId = Rea.startMapper(() => {
|
14
16
|
"worklet";
|
15
17
|
|
16
18
|
values.value.forEach((val, index) => {
|
@@ -20,7 +22,7 @@ const useBuffer = (size, bufferInitializer, modifier) => {
|
|
20
22
|
}, deps);
|
21
23
|
useEffect(() => {
|
22
24
|
return () => {
|
23
|
-
stopMapper(mapperId);
|
25
|
+
Rea.stopMapper(mapperId);
|
24
26
|
};
|
25
27
|
}, [mapperId]);
|
26
28
|
return values;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useEffect","useMemo","Skia","
|
1
|
+
{"version":3,"names":["useEffect","useMemo","Skia","notifyChange","Rea","useBufferValue","size","bufferInitializer","makeMutable","Array","fill","map","useBuffer","modifier","_mod$__closure","values","mod","deps","Object","__closure","mapperId","startMapper","value","forEach","val","index","stopMapper","useRectBuffer","XYWHRect","useRSXformBuffer","RSXform","usePointBuffer","Point","useColorBuffer","Color"],"sources":["buffers.ts"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport type { WorkletFunction } from \"react-native-reanimated/lib/typescript/reanimated2/commonTypes\";\n\nimport type { SkColor, SkHostRect, SkPoint, SkRSXform } from \"../../skia/types\";\nimport { Skia } from \"../../skia\";\n\nimport { notifyChange } from \"./interpolators\";\nimport Rea from \"./ReanimatedProxy\";\n\ntype Modifier<T> = (input: T, index: number) => void;\n\nconst useBufferValue = <T>(size: number, bufferInitializer: () => T) => {\n return useMemo(\n () => Rea.makeMutable(new Array(size).fill(0).map(bufferInitializer)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [size]\n );\n};\n\nconst useBuffer = <T>(\n size: number,\n bufferInitializer: () => T,\n modifier: Modifier<T>\n) => {\n const values = useBufferValue(size, bufferInitializer);\n const mod = modifier as WorkletFunction;\n const deps = [size, ...Object.values(mod.__closure ?? {})];\n const mapperId = Rea.startMapper(() => {\n \"worklet\";\n values.value.forEach((val, index) => {\n modifier(val, index);\n });\n notifyChange(values);\n }, deps);\n\n useEffect(() => {\n return () => {\n Rea.stopMapper(mapperId);\n };\n }, [mapperId]);\n\n return values;\n};\n\nexport const useRectBuffer = (size: number, modifier: Modifier<SkHostRect>) =>\n useBuffer(size, () => Skia.XYWHRect(0, 0, 0, 0), modifier);\n\n// Usage for RSXform Buffer\nexport const useRSXformBuffer = (size: number, modifier: Modifier<SkRSXform>) =>\n useBuffer(size, () => Skia.RSXform(1, 0, 0, 0), modifier);\n\n// Usage for Point Buffer\nexport const usePointBuffer = (size: number, modifier: Modifier<SkPoint>) =>\n useBuffer(size, () => Skia.Point(0, 0), modifier);\n\n// Usage for Color Buffer\nexport const useColorBuffer = (size: number, modifier: Modifier<SkColor>) =>\n useBuffer(size, () => Skia.Color(\"black\"), modifier);\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAI1C,SAASC,IAAI,QAAQ,YAAY;AAEjC,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,OAAOC,GAAG,MAAM,mBAAmB;AAInC,MAAMC,cAAc,GAAGA,CAAIC,IAAY,EAAEC,iBAA0B,KAAK;EACtE,OAAON,OAAO,CACZ,MAAMG,GAAG,CAACI,WAAW,CAAC,IAAIC,KAAK,CAACH,IAAI,CAAC,CAACI,IAAI,CAAC,CAAC,CAAC,CAACC,GAAG,CAACJ,iBAAiB,CAAC,CAAC;EACrE;EACA,CAACD,IAAI,CACP,CAAC;AACH,CAAC;AAED,MAAMM,SAAS,GAAGA,CAChBN,IAAY,EACZC,iBAA0B,EAC1BM,QAAqB,KAClB;EAAA,IAAAC,cAAA;EACH,MAAMC,MAAM,GAAGV,cAAc,CAACC,IAAI,EAAEC,iBAAiB,CAAC;EACtD,MAAMS,GAAG,GAAGH,QAA2B;EACvC,MAAMI,IAAI,GAAG,CAACX,IAAI,EAAE,GAAGY,MAAM,CAACH,MAAM,EAAAD,cAAA,GAACE,GAAG,CAACG,SAAS,cAAAL,cAAA,cAAA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"}
|
@@ -2,7 +2,7 @@ import { useCallback, useMemo } from "react";
|
|
2
2
|
import { interpolatePaths, interpolateVector } from "../../animation";
|
3
3
|
import { Skia } from "../../skia";
|
4
4
|
import { isOnMainThread } from "../../renderer/Offscreen";
|
5
|
-
import
|
5
|
+
import Rea from "./ReanimatedProxy";
|
6
6
|
export const notifyChange = value => {
|
7
7
|
"worklet";
|
8
8
|
|
@@ -13,8 +13,8 @@ export const notifyChange = value => {
|
|
13
13
|
};
|
14
14
|
export const usePathValue = (cb, init) => {
|
15
15
|
const pathInit = useMemo(() => Skia.Path.Make(), []);
|
16
|
-
const path = useSharedValue(pathInit);
|
17
|
-
useDerivedValue(() => {
|
16
|
+
const path = Rea.useSharedValue(pathInit);
|
17
|
+
Rea.useDerivedValue(() => {
|
18
18
|
path.value.reset();
|
19
19
|
if (init !== undefined) {
|
20
20
|
path.value.addPath(init);
|
@@ -25,13 +25,13 @@ export const usePathValue = (cb, init) => {
|
|
25
25
|
return path;
|
26
26
|
};
|
27
27
|
export const useClock = () => {
|
28
|
-
const clock = useSharedValue(0);
|
28
|
+
const clock = Rea.useSharedValue(0);
|
29
29
|
const callback = useCallback(info => {
|
30
30
|
"worklet";
|
31
31
|
|
32
32
|
clock.value = info.timeSinceFirstFrame;
|
33
33
|
}, [clock]);
|
34
|
-
useFrameCallback(callback);
|
34
|
+
Rea.useFrameCallback(callback);
|
35
35
|
return clock;
|
36
36
|
};
|
37
37
|
|
@@ -42,8 +42,8 @@ export const useClock = () => {
|
|
42
42
|
const useInterpolator = (factory, value, interpolator, input, output, options) => {
|
43
43
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
44
44
|
const init = useMemo(() => factory(), []);
|
45
|
-
const result = useSharedValue(init);
|
46
|
-
useAnimatedReaction(() => value.value, val => {
|
45
|
+
const result = Rea.useSharedValue(init);
|
46
|
+
Rea.useAnimatedReaction(() => value.value, val => {
|
47
47
|
result.value = interpolator(val, input, output, options, result.value);
|
48
48
|
notifyChange(result);
|
49
49
|
}, [input, output, options]);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useCallback","useMemo","interpolatePaths","interpolateVector","Skia","isOnMainThread","
|
1
|
+
{"version":3,"names":["useCallback","useMemo","interpolatePaths","interpolateVector","Skia","isOnMainThread","Rea","notifyChange","value","_value","usePathValue","cb","init","pathInit","Path","Make","path","useSharedValue","useDerivedValue","reset","undefined","addPath","useClock","clock","callback","info","timeSinceFirstFrame","useFrameCallback","useInterpolator","factory","interpolator","input","output","options","result","useAnimatedReaction","val","usePathInterpolation","outputRange","allPathsInterpolable","slice","every","isInterpolatable","Error","useVectorInterpolation","Point"],"sources":["interpolators.ts"],"sourcesContent":["import type {\n ExtrapolationType,\n FrameInfo,\n SharedValue,\n} from \"react-native-reanimated\";\nimport { useCallback, useMemo } from \"react\";\n\nimport type { SkPath, SkPoint } from \"../../skia/types\";\nimport { interpolatePaths, interpolateVector } from \"../../animation\";\nimport { Skia } from \"../../skia\";\nimport { isOnMainThread } from \"../../renderer/Offscreen\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nexport const notifyChange = (value: SharedValue<unknown>) => {\n \"worklet\";\n if (isOnMainThread()) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (value as any)._value = value.value;\n }\n};\n\nexport const usePathValue = (cb: (path: SkPath) => void, init?: SkPath) => {\n const pathInit = useMemo(() => Skia.Path.Make(), []);\n const path = Rea.useSharedValue(pathInit);\n Rea.useDerivedValue(() => {\n path.value.reset();\n if (init !== undefined) {\n path.value.addPath(init);\n }\n cb(path.value);\n notifyChange(path);\n });\n return path;\n};\n\nexport const useClock = () => {\n const clock = Rea.useSharedValue(0);\n const callback = useCallback(\n (info: FrameInfo) => {\n \"worklet\";\n clock.value = info.timeSinceFirstFrame;\n },\n [clock]\n );\n Rea.useFrameCallback(callback);\n return clock;\n};\n\n/**\n * @worklet\n */\ntype Interpolator<T> = (\n value: number,\n input: number[],\n output: T[],\n options: ExtrapolationType,\n result: T\n) => T;\n\nconst useInterpolator = <T>(\n factory: () => T,\n value: SharedValue<number>,\n interpolator: Interpolator<T>,\n input: number[],\n output: T[],\n options?: ExtrapolationType\n) => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const init = useMemo(() => factory(), []);\n const result = Rea.useSharedValue(init);\n Rea.useAnimatedReaction(\n () => value.value,\n (val) => {\n result.value = interpolator(val, input, output, options, result.value);\n notifyChange(result);\n },\n [input, output, options]\n );\n return result;\n};\n\nexport const usePathInterpolation = (\n value: SharedValue<number>,\n input: number[],\n outputRange: SkPath[],\n options?: ExtrapolationType\n) => {\n // Check if all paths in outputRange are interpolable\n const allPathsInterpolable = outputRange\n .slice(1)\n .every((path) => outputRange[0].isInterpolatable(path));\n if (!allPathsInterpolable) {\n // Handle the case where not all paths are interpolable\n // For example, throw an error or return early\n throw new Error(\n `Not all paths in the output range are interpolable.\nSee: https://shopify.github.io/react-native-skia/docs/animations/hooks#usepathinterpolation`\n );\n }\n return useInterpolator(\n () => Skia.Path.Make(),\n value,\n interpolatePaths,\n input,\n outputRange,\n options\n );\n};\n\nexport const useVectorInterpolation = (\n value: SharedValue<number>,\n input: number[],\n outputRange: SkPoint[],\n options?: ExtrapolationType\n) =>\n useInterpolator(\n () => Skia.Point(0, 0),\n value,\n interpolateVector,\n input,\n outputRange,\n options\n );\n"],"mappings":"AAKA,SAASA,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAG5C,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,iBAAiB;AACrE,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,OAAOC,GAAG,MAAM,mBAAmB;AAEnC,OAAO,MAAMC,YAAY,GAAIC,KAA2B,IAAK;EAC3D,SAAS;;EACT,IAAIH,cAAc,CAAC,CAAC,EAAE;IACpB;IACCG,KAAK,CAASC,MAAM,GAAGD,KAAK,CAACA,KAAK;EACrC;AACF,CAAC;AAED,OAAO,MAAME,YAAY,GAAGA,CAACC,EA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