@shopify/react-native-skia 1.9.1 → 1.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. package/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +1 -0
  2. package/lib/commonjs/dom/nodes/datatypes/Gradient.js +14 -2
  3. package/lib/commonjs/dom/nodes/datatypes/Gradient.js.map +1 -1
  4. package/lib/commonjs/index.d.ts +1 -1
  5. package/lib/commonjs/index.js +8 -8
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/renderer/Canvas.d.ts +9 -10
  8. package/lib/commonjs/renderer/Canvas.js +67 -59
  9. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  10. package/lib/commonjs/renderer/CanvasOld.d.ts +11 -0
  11. package/lib/commonjs/renderer/CanvasOld.js +96 -0
  12. package/lib/commonjs/renderer/CanvasOld.js.map +1 -0
  13. package/lib/commonjs/sksg/Container.js +11 -6
  14. package/lib/commonjs/sksg/Container.js.map +1 -1
  15. package/lib/commonjs/sksg/HostConfig2.d.ts +19 -0
  16. package/lib/commonjs/sksg/HostConfig2.js +159 -0
  17. package/lib/commonjs/sksg/HostConfig2.js.map +1 -0
  18. package/lib/commonjs/sksg/Recorder/Core.js +1 -0
  19. package/lib/commonjs/sksg/Recorder/Core.js.map +1 -1
  20. package/lib/commonjs/sksg/Recorder/Player.js +2 -2
  21. package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
  22. package/lib/commonjs/sksg/Recorder/Recorder.js +0 -1
  23. package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
  24. package/lib/commonjs/sksg/Recorder/commands/Box.js +1 -1
  25. package/lib/commonjs/sksg/Recorder/commands/Box.js.map +1 -1
  26. package/lib/commonjs/sksg/Recorder/commands/ColorFilters.js +1 -1
  27. package/lib/commonjs/sksg/Recorder/commands/ColorFilters.js.map +1 -1
  28. package/lib/commonjs/sksg/Recorder/commands/Drawing.js +4 -4
  29. package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
  30. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +1 -1
  31. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  32. package/lib/commonjs/sksg/Recorder/commands/Paint.d.ts +0 -1
  33. package/lib/commonjs/sksg/Recorder/commands/Paint.js +2 -14
  34. package/lib/commonjs/sksg/Recorder/commands/Paint.js.map +1 -1
  35. package/lib/commonjs/sksg/Recorder/commands/Shaders.js +1 -1
  36. package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
  37. package/lib/module/dom/nodes/datatypes/Gradient.d.ts +1 -0
  38. package/lib/module/dom/nodes/datatypes/Gradient.js +12 -1
  39. package/lib/module/dom/nodes/datatypes/Gradient.js.map +1 -1
  40. package/lib/module/index.d.ts +1 -1
  41. package/lib/module/index.js +1 -1
  42. package/lib/module/index.js.map +1 -1
  43. package/lib/module/renderer/Canvas.d.ts +9 -10
  44. package/lib/module/renderer/Canvas.js +65 -55
  45. package/lib/module/renderer/Canvas.js.map +1 -1
  46. package/lib/module/renderer/CanvasOld.d.ts +11 -0
  47. package/lib/module/renderer/CanvasOld.js +87 -0
  48. package/lib/module/renderer/CanvasOld.js.map +1 -0
  49. package/lib/module/sksg/Container.js +11 -6
  50. package/lib/module/sksg/Container.js.map +1 -1
  51. package/lib/module/sksg/HostConfig2.d.ts +19 -0
  52. package/lib/module/sksg/HostConfig2.js +152 -0
  53. package/lib/module/sksg/HostConfig2.js.map +1 -0
  54. package/lib/module/sksg/Recorder/Core.js +1 -0
  55. package/lib/module/sksg/Recorder/Core.js.map +1 -1
  56. package/lib/module/sksg/Recorder/Player.js +2 -2
  57. package/lib/module/sksg/Recorder/Player.js.map +1 -1
  58. package/lib/module/sksg/Recorder/Recorder.js +0 -1
  59. package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
  60. package/lib/module/sksg/Recorder/commands/Box.js +2 -2
  61. package/lib/module/sksg/Recorder/commands/Box.js.map +1 -1
  62. package/lib/module/sksg/Recorder/commands/ColorFilters.js +2 -2
  63. package/lib/module/sksg/Recorder/commands/ColorFilters.js.map +1 -1
  64. package/lib/module/sksg/Recorder/commands/Drawing.js +5 -5
  65. package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
  66. package/lib/module/sksg/Recorder/commands/ImageFilters.js +2 -2
  67. package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  68. package/lib/module/sksg/Recorder/commands/Paint.d.ts +0 -1
  69. package/lib/module/sksg/Recorder/commands/Paint.js +1 -12
  70. package/lib/module/sksg/Recorder/commands/Paint.js.map +1 -1
  71. package/lib/module/sksg/Recorder/commands/Shaders.js +2 -2
  72. package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
  73. package/lib/typescript/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +1 -0
  74. package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +2 -2
  75. package/lib/typescript/lib/commonjs/renderer/CanvasOld.d.ts +3 -0
  76. package/lib/typescript/lib/commonjs/sksg/HostConfig2.d.ts +44 -0
  77. package/lib/typescript/lib/commonjs/sksg/Recorder/commands/Paint.d.ts +0 -1
  78. package/lib/typescript/lib/module/dom/nodes/datatypes/Gradient.d.ts +1 -0
  79. package/lib/typescript/lib/module/index.d.ts +1 -1
  80. package/lib/typescript/lib/module/mock/index.d.ts +1 -0
  81. package/lib/typescript/lib/module/renderer/Canvas.d.ts +1 -3
  82. package/lib/typescript/lib/module/renderer/CanvasOld.d.ts +3 -0
  83. package/lib/typescript/lib/module/sksg/HostConfig2.d.ts +43 -0
  84. package/lib/typescript/lib/module/sksg/Recorder/commands/Paint.d.ts +0 -1
  85. package/lib/typescript/src/dom/nodes/datatypes/Gradient.d.ts +1 -0
  86. package/lib/typescript/src/index.d.ts +1 -1
  87. package/lib/typescript/src/renderer/Canvas.d.ts +9 -10
  88. package/lib/typescript/src/renderer/CanvasOld.d.ts +11 -0
  89. package/lib/typescript/src/sksg/HostConfig2.d.ts +19 -0
  90. package/lib/typescript/src/sksg/Recorder/commands/Paint.d.ts +0 -1
  91. package/package.json +1 -1
  92. package/src/dom/nodes/datatypes/Gradient.ts +17 -1
  93. package/src/index.ts +1 -1
  94. package/src/renderer/Canvas.tsx +80 -78
  95. package/src/renderer/CanvasOld.tsx +126 -0
  96. package/src/sksg/Container.ts +6 -2
  97. package/src/sksg/HostConfig2.ts +247 -0
  98. package/src/sksg/Recorder/Core.ts +1 -0
  99. package/src/sksg/Recorder/Player.ts +2 -2
  100. package/src/sksg/Recorder/Recorder.ts +0 -1
  101. package/src/sksg/Recorder/commands/Box.ts +2 -2
  102. package/src/sksg/Recorder/commands/ColorFilters.ts +2 -2
  103. package/src/sksg/Recorder/commands/Drawing.ts +5 -4
  104. package/src/sksg/Recorder/commands/ImageFilters.ts +2 -2
  105. package/src/sksg/Recorder/commands/Paint.ts +1 -17
  106. package/src/sksg/Recorder/commands/Shaders.ts +2 -1
  107. package/lib/commonjs/renderer/Canvas2.d.ts +0 -10
  108. package/lib/commonjs/renderer/Canvas2.js +0 -104
  109. package/lib/commonjs/renderer/Canvas2.js.map +0 -1
  110. package/lib/commonjs/renderer/Canvas2.web.d.ts +0 -3
  111. package/lib/commonjs/renderer/Canvas2.web.js +0 -9
  112. package/lib/commonjs/renderer/Canvas2.web.js.map +0 -1
  113. package/lib/module/renderer/Canvas2.d.ts +0 -10
  114. package/lib/module/renderer/Canvas2.js +0 -97
  115. package/lib/module/renderer/Canvas2.js.map +0 -1
  116. package/lib/module/renderer/Canvas2.web.d.ts +0 -3
  117. package/lib/module/renderer/Canvas2.web.js +0 -3
  118. package/lib/module/renderer/Canvas2.web.js.map +0 -1
  119. package/lib/typescript/lib/commonjs/renderer/Canvas2.d.ts +0 -3
  120. package/lib/typescript/lib/commonjs/renderer/Canvas2.web.d.ts +0 -2
  121. package/lib/typescript/lib/module/renderer/Canvas2.d.ts +0 -1
  122. package/lib/typescript/lib/module/renderer/Canvas2.web.d.ts +0 -1
  123. package/lib/typescript/src/renderer/Canvas2.d.ts +0 -10
  124. package/lib/typescript/src/renderer/Canvas2.web.d.ts +0 -3
  125. package/src/renderer/Canvas2.tsx +0 -128
  126. package/src/renderer/Canvas2.web.tsx +0 -6
@@ -1,8 +1,12 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import React, { useEffect, useCallback, useMemo, forwardRef, useRef } from "react";
3
- import { SkiaDomView } from "../views";
4
- import { SkiaRoot } from "./Reconciler";
5
- export const useCanvasRef = () => useRef(null);
2
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from "react";
3
+ import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
4
+ import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
5
+ import { SkiaSGRoot } from "../sksg/Reconciler";
6
+ import { Skia } from "../skia";
7
+ const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
8
+
9
+ // TODO: no need to go through the JS thread for this
6
10
  const useOnSizeEvent = (resultValue, onLayout) => {
7
11
  return useCallback(event => {
8
12
  if (onLayout) {
@@ -21,67 +25,73 @@ const useOnSizeEvent = (resultValue, onLayout) => {
21
25
  }, [onLayout, resultValue]);
22
26
  };
23
27
  export const Canvas = /*#__PURE__*/forwardRef(({
24
- children,
25
- style,
28
+ mode,
26
29
  debug,
27
- mode = "default",
28
- onSize: _onSize,
30
+ opaque,
31
+ children,
32
+ onSize,
29
33
  onLayout: _onLayout,
30
- ...props
31
- }, forwardedRef) => {
32
- const onLayout = useOnSizeEvent(_onSize, _onLayout);
33
- const innerRef = useCanvasRef();
34
- const ref = useCombinedRefs(forwardedRef, innerRef);
35
- const redraw = useCallback(() => {
36
- var _innerRef$current;
37
- (_innerRef$current = innerRef.current) === null || _innerRef$current === void 0 || _innerRef$current.redraw();
38
- }, [innerRef]);
39
- const getNativeId = useCallback(() => {
40
- var _innerRef$current$nat, _innerRef$current2;
41
- const id = (_innerRef$current$nat = (_innerRef$current2 = innerRef.current) === null || _innerRef$current2 === void 0 ? void 0 : _innerRef$current2.nativeId) !== null && _innerRef$current$nat !== void 0 ? _innerRef$current$nat : -1;
42
- return id;
43
- }, [innerRef]);
44
- const root = useMemo(() => new SkiaRoot(redraw, getNativeId), [redraw, getNativeId]);
34
+ ...viewProps
35
+ }, ref) => {
36
+ const rafId = useRef(null);
37
+ const onLayout = useOnSizeEvent(onSize, _onLayout);
38
+ // Native ID
39
+ const nativeId = useMemo(() => {
40
+ return SkiaViewNativeId.current++;
41
+ }, []);
42
+
43
+ // Root
44
+ const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);
45
45
 
46
- // Render effect
46
+ // Render effects
47
47
  useEffect(() => {
48
48
  root.render(children);
49
- }, [children, root, redraw]);
49
+ }, [children, root]);
50
50
  useEffect(() => {
51
51
  return () => {
52
52
  root.unmount();
53
53
  };
54
54
  }, [root]);
55
- return /*#__PURE__*/React.createElement(SkiaDomView, _extends({
56
- ref: ref,
57
- style: style,
58
- root: root.dom,
59
- onLayout: onLayout,
60
- debug: debug,
61
- mode: mode
62
- }, props));
63
- });
64
-
65
- /**
66
- * Combines a list of refs into a single ref. This can be used to provide
67
- * both a forwarded ref and an internal ref keeping the same functionality
68
- * on both of the refs.
69
- * @param refs Array of refs to combine
70
- * @returns A single ref that can be used in a ref prop.
71
- */
72
- const useCombinedRefs = (...refs) => {
73
- const targetRef = React.useRef(null);
74
- React.useEffect(() => {
75
- refs.forEach(ref => {
76
- if (ref) {
77
- if (typeof ref === "function") {
78
- ref(targetRef.current);
79
- } else {
80
- ref.current = targetRef.current;
81
- }
55
+ const requestRedraw = useCallback(() => {
56
+ rafId.current = requestAnimationFrame(() => {
57
+ root.render(children);
58
+ if (mode === "continuous") {
59
+ requestRedraw();
82
60
  }
83
61
  });
84
- }, [refs]);
85
- return targetRef;
86
- };
62
+ }, [children, mode, root]);
63
+ useEffect(() => {
64
+ if (mode === "continuous") {
65
+ console.warn("The `mode` property in `Canvas` is deprecated.");
66
+ requestRedraw();
67
+ }
68
+ return () => {
69
+ if (rafId.current !== null) {
70
+ cancelAnimationFrame(rafId.current);
71
+ }
72
+ };
73
+ }, [mode, requestRedraw]);
74
+ // Component methods
75
+ useImperativeHandle(ref, () => ({
76
+ makeImageSnapshot: rect => {
77
+ return SkiaViewApi.makeImageSnapshot(nativeId, rect);
78
+ },
79
+ makeImageSnapshotAsync: rect => {
80
+ return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);
81
+ },
82
+ redraw: () => {
83
+ SkiaViewApi.requestRedraw(nativeId);
84
+ },
85
+ getNativeId: () => {
86
+ return nativeId;
87
+ }
88
+ }));
89
+ return /*#__PURE__*/React.createElement(NativeSkiaPictureView, _extends({
90
+ collapsable: false,
91
+ nativeID: `${nativeId}`,
92
+ debug: debug,
93
+ opaque: opaque,
94
+ onLayout: onLayout
95
+ }, viewProps));
96
+ });
87
97
  //# sourceMappingURL=Canvas.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEffect","useCallback","useMemo","forwardRef","useRef","SkiaDomView","SkiaRoot","useCanvasRef","useOnSizeEvent","resultValue","onLayout","event","width","height","nativeEvent","layout","value","Canvas","children","style","debug","mode","onSize","_onSize","_onLayout","props","forwardedRef","innerRef","ref","useCombinedRefs","redraw","_innerRef$current","current","getNativeId","_innerRef$current$nat","_innerRef$current2","id","nativeId","root","render","unmount","createElement","_extends","dom","refs","targetRef","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n MutableRefObject,\n ForwardedRef,\n FunctionComponent,\n} from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport { SkiaDomView } from \"../views\";\nimport type { SkiaBaseViewProps } from \"../views\";\n\nimport { SkiaRoot } from \"./Reconciler\";\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nexport interface CanvasProps extends SkiaBaseViewProps {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n mode?: \"default\" | \"continuous\";\n}\n\nconst useOnSizeEvent = (\n resultValue: SkiaBaseViewProps[\"onSize\"],\n onLayout?: (event: LayoutChangeEvent) => void\n) => {\n return useCallback(\n (event: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(event);\n }\n const { width, height } = event.nativeEvent.layout;\n\n if (resultValue) {\n resultValue.value = { width, height };\n }\n },\n [onLayout, resultValue]\n );\n};\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n (\n {\n children,\n style,\n debug,\n mode = \"default\",\n onSize: _onSize,\n onLayout: _onLayout,\n ...props\n },\n forwardedRef\n ) => {\n const onLayout = useOnSizeEvent(_onSize, _onLayout);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const redraw = useCallback(() => {\n innerRef.current?.redraw();\n }, [innerRef]);\n const getNativeId = useCallback(() => {\n const id = innerRef.current?.nativeId ?? -1;\n return id;\n }, [innerRef]);\n\n const root = useMemo(\n () => new SkiaRoot(redraw, getNativeId),\n [redraw, getNativeId]\n );\n\n // Render effect\n useEffect(() => {\n root.render(children);\n }, [children, root, redraw]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={root.dom}\n onLayout={onLayout}\n debug={debug}\n mode={mode}\n {...props}\n />\n );\n }\n) as FunctionComponent<CanvasProps & React.RefAttributes<SkiaDomView>>;\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"],"mappings":";AAAA,OAAOA,KAAK,IACVC,SAAS,EACTC,WAAW,EACXC,OAAO,EACPC,UAAU,EACVC,MAAM,QACD,OAAO;AAUd,SAASC,WAAW,QAAQ,UAAU;AAGtC,SAASC,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,YAAY,GAAGA,CAAA,KAAMH,MAAM,CAAc,IAAI,CAAC;AAQ3D,MAAMI,cAAc,GAAGA,CACrBC,WAAwC,EACxCC,QAA6C,KAC1C;EACH,OAAOT,WAAW,CACfU,KAAwB,IAAK;IAC5B,IAAID,QAAQ,EAAE;MACZA,QAAQ,CAACC,KAAK,CAAC;IACjB;IACA,MAAM;MAAEC,KAAK;MAAEC;IAAO,CAAC,GAAGF,KAAK,CAACG,WAAW,CAACC,MAAM;IAElD,IAAIN,WAAW,EAAE;MACfA,WAAW,CAACO,KAAK,GAAG;QAAEJ,KAAK;QAAEC;MAAO,CAAC;IACvC;EACF,CAAC,EACD,CAACH,QAAQ,EAAED,WAAW,CACxB,CAAC;AACH,CAAC;AAED,OAAO,MAAMQ,MAAM,gBAAGd,UAAU,CAC9B,CACE;EACEe,QAAQ;EACRC,KAAK;EACLC,KAAK;EACLC,IAAI,GAAG,SAAS;EAChBC,MAAM,EAAEC,OAAO;EACfb,QAAQ,EAAEc,SAAS;EACnB,GAAGC;AACL,CAAC,EACDC,YAAY,KACT;EACH,MAAMhB,QAAQ,GAAGF,cAAc,CAACe,OAAO,EAAEC,SAAS,CAAC;EACnD,MAAMG,QAAQ,GAAGpB,YAAY,CAAC,CAAC;EAC/B,MAAMqB,GAAG,GAAGC,eAAe,CAACH,YAAY,EAAEC,QAAQ,CAAC;EACnD,MAAMG,MAAM,GAAG7B,WAAW,CAAC,MAAM;IAAA,IAAA8B,iBAAA;IAC/B,CAAAA,iBAAA,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AS,GAAG9C,KAAK,CAACK,MAAM,CAAI,IAAI,CAAC;EACvCL,KAAK,CAACC,SAAS,CAAC,MAAM;IACpB4C,IAAI,CAACE,OAAO,CAAElB,GAAG,IAAK;MACpB,IAAIA,GAAG,EAAE;QACP,IAAI,OAAOA,GAAG,KAAK,UAAU,EAAE;UAC7BA,GAAG,CAACiB,SAAS,CAACb,OAAO,CAAC;QACxB,CAAC,MAAM;UACLJ,GAAG,CAACI,OAAO,GAAGa,SAAS,CAACb,OAAO;QACjC;MACF;IACF,CAAC,CAAC;EACJ,CAAC,EAAE,CAACY,IAAI,CAAC,CAAC;EACV,OAAOC,SAAS;AAClB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["forwardRef","useCallback","useEffect","useImperativeHandle","useMemo","useRef","SkiaViewNativeId","SkiaPictureViewNativeComponent","SkiaSGRoot","Skia","NativeSkiaPictureView","useOnSizeEvent","resultValue","onLayout","event","width","height","nativeEvent","layout","value","Canvas","mode","debug","opaque","children","onSize","_onLayout","viewProps","ref","rafId","nativeId","current","root","render","unmount","requestRedraw","requestAnimationFrame","console","warn","cancelAnimationFrame","makeImageSnapshot","rect","SkiaViewApi","makeImageSnapshotAsync","redraw","getNativeId","React","createElement","_extends","collapsable","nativeID"],"sources":["Canvas.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from \"react\";\nimport type { LayoutChangeEvent, ViewProps } from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport { SkiaViewNativeId } from \"../views/SkiaViewNativeId\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\nimport type { SkRect, SkSize } from \"../skia/types\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\nimport { Skia } from \"../skia\";\nimport type { SkiaBaseViewProps } from \"../views\";\n\nconst NativeSkiaPictureView = SkiaPictureViewNativeComponent;\n\n// TODO: no need to go through the JS thread for this\nconst useOnSizeEvent = (\n resultValue: SkiaBaseViewProps[\"onSize\"],\n onLayout?: (event: LayoutChangeEvent) => void\n) => {\n return useCallback(\n (event: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(event);\n }\n const { width, height } = event.nativeEvent.layout;\n\n if (resultValue) {\n resultValue.value = { width, height };\n }\n },\n [onLayout, resultValue]\n );\n};\n\nexport interface CanvasProps extends ViewProps {\n debug?: boolean;\n opaque?: boolean;\n onSize?: SharedValue<SkSize>;\n mode?: \"continuous\" | \"default\";\n}\n\nexport const Canvas = forwardRef(\n (\n {\n mode,\n debug,\n opaque,\n children,\n onSize,\n onLayout: _onLayout,\n ...viewProps\n }: CanvasProps,\n ref\n ) => {\n const rafId = useRef<number | null>(null);\n const onLayout = useOnSizeEvent(onSize, _onLayout);\n // Native ID\n const nativeId = useMemo(() => {\n return SkiaViewNativeId.current++;\n }, []);\n\n // Root\n const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);\n\n // Render effects\n useEffect(() => {\n root.render(children);\n }, [children, root]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n const requestRedraw = useCallback(() => {\n rafId.current = requestAnimationFrame(() => {\n root.render(children);\n if (mode === \"continuous\") {\n requestRedraw();\n }\n });\n }, [children, mode, root]);\n\n useEffect(() => {\n if (mode === \"continuous\") {\n console.warn(\"The `mode` property in `Canvas` is deprecated.\");\n requestRedraw();\n }\n return () => {\n if (rafId.current !== null) {\n cancelAnimationFrame(rafId.current);\n }\n };\n }, [mode, requestRedraw]);\n // Component methods\n useImperativeHandle(ref, () => ({\n makeImageSnapshot: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshot(nativeId, rect);\n },\n makeImageSnapshotAsync: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);\n },\n redraw: () => {\n SkiaViewApi.requestRedraw(nativeId);\n },\n getNativeId: () => {\n return nativeId;\n },\n }));\n return (\n <NativeSkiaPictureView\n collapsable={false}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,QAAQ,EAAEW,IAAI,CAAC;IAC3D,CAAC;IACDG,MAAM,EAAEA,CAAA,KAAM;MACZF,WAAW,CAACP,aAAa,CAACL,QAAQ,CAAC;IACrC,CAAC;IACDe,WAAW,EAAEA,CAAA,KAAM;MACjB,OAAOf,QAAQ;IACjB;EACF,CAAC,CAAC,CAAC;EACH,oBACEgB,KAAA,CAAAC,aAAA,CAACrC,qBAAqB,EAAAsC,QAAA;IACpBC,WAAW,EAAE,KAAM;IACnBC,QAAQ,EAAE,GAAGpB,QAAQ,EAAG;IACxBR,KAAK,EAAEA,KAAM;IACbC,MAAM,EAAEA,MAAO;IACfV,QAAQ,EAAEA;EAAS,GACfc,SAAS,CACd,CAAC;AAEN,CACF,CAAC","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import type { RefObject, ReactNode, FunctionComponent } from "react";
3
+ import { SkiaDomView } from "../views";
4
+ import type { SkiaBaseViewProps } from "../views";
5
+ export declare const useCanvasRef: () => React.RefObject<SkiaDomView>;
6
+ export interface CanvasOldProps extends SkiaBaseViewProps {
7
+ ref?: RefObject<SkiaDomView>;
8
+ children: ReactNode;
9
+ mode?: "default" | "continuous";
10
+ }
11
+ export declare const CanvasOld: FunctionComponent<CanvasOldProps & React.RefAttributes<SkiaDomView>>;
@@ -0,0 +1,87 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import React, { useEffect, useCallback, useMemo, forwardRef, useRef } from "react";
3
+ import { SkiaDomView } from "../views";
4
+ import { SkiaRoot } from "./Reconciler";
5
+ export const useCanvasRef = () => useRef(null);
6
+ const useOnSizeEvent = (resultValue, onLayout) => {
7
+ return useCallback(event => {
8
+ if (onLayout) {
9
+ onLayout(event);
10
+ }
11
+ const {
12
+ width,
13
+ height
14
+ } = event.nativeEvent.layout;
15
+ if (resultValue) {
16
+ resultValue.value = {
17
+ width,
18
+ height
19
+ };
20
+ }
21
+ }, [onLayout, resultValue]);
22
+ };
23
+ export const CanvasOld = /*#__PURE__*/forwardRef(({
24
+ children,
25
+ style,
26
+ debug,
27
+ mode = "default",
28
+ onSize: _onSize,
29
+ onLayout: _onLayout,
30
+ ...props
31
+ }, forwardedRef) => {
32
+ const onLayout = useOnSizeEvent(_onSize, _onLayout);
33
+ const innerRef = useCanvasRef();
34
+ const ref = useCombinedRefs(forwardedRef, innerRef);
35
+ const redraw = useCallback(() => {
36
+ var _innerRef$current;
37
+ (_innerRef$current = innerRef.current) === null || _innerRef$current === void 0 || _innerRef$current.redraw();
38
+ }, [innerRef]);
39
+ const getNativeId = useCallback(() => {
40
+ var _innerRef$current$nat, _innerRef$current2;
41
+ const id = (_innerRef$current$nat = (_innerRef$current2 = innerRef.current) === null || _innerRef$current2 === void 0 ? void 0 : _innerRef$current2.nativeId) !== null && _innerRef$current$nat !== void 0 ? _innerRef$current$nat : -1;
42
+ return id;
43
+ }, [innerRef]);
44
+ const root = useMemo(() => new SkiaRoot(redraw, getNativeId), [redraw, getNativeId]);
45
+
46
+ // Render effect
47
+ useEffect(() => {
48
+ root.render(children);
49
+ }, [children, root, redraw]);
50
+ useEffect(() => {
51
+ return () => {
52
+ root.unmount();
53
+ };
54
+ }, [root]);
55
+ return /*#__PURE__*/React.createElement(SkiaDomView, _extends({
56
+ ref: ref,
57
+ style: style,
58
+ root: root.dom,
59
+ onLayout: onLayout,
60
+ debug: debug,
61
+ mode: mode
62
+ }, props));
63
+ });
64
+
65
+ /**
66
+ * Combines a list of refs into a single ref. This can be used to provide
67
+ * both a forwarded ref and an internal ref keeping the same functionality
68
+ * on both of the refs.
69
+ * @param refs Array of refs to combine
70
+ * @returns A single ref that can be used in a ref prop.
71
+ */
72
+ const useCombinedRefs = (...refs) => {
73
+ const targetRef = React.useRef(null);
74
+ React.useEffect(() => {
75
+ refs.forEach(ref => {
76
+ if (ref) {
77
+ if (typeof ref === "function") {
78
+ ref(targetRef.current);
79
+ } else {
80
+ ref.current = targetRef.current;
81
+ }
82
+ }
83
+ });
84
+ }, [refs]);
85
+ return targetRef;
86
+ };
87
+ //# sourceMappingURL=CanvasOld.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useEffect","useCallback","useMemo","forwardRef","useRef","SkiaDomView","SkiaRoot","useCanvasRef","useOnSizeEvent","resultValue","onLayout","event","width","height","nativeEvent","layout","value","CanvasOld","children","style","debug","mode","onSize","_onSize","_onLayout","props","forwardedRef","innerRef","ref","useCombinedRefs","redraw","_innerRef$current","current","getNativeId","_innerRef$current$nat","_innerRef$current2","id","nativeId","root","render","unmount","createElement","_extends","dom","refs","targetRef","forEach"],"sources":["CanvasOld.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n MutableRefObject,\n ForwardedRef,\n FunctionComponent,\n} from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport { SkiaDomView } from \"../views\";\nimport type { SkiaBaseViewProps } from \"../views\";\n\nimport { SkiaRoot } from \"./Reconciler\";\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nexport interface CanvasOldProps extends SkiaBaseViewProps {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n mode?: \"default\" | \"continuous\";\n}\n\nconst useOnSizeEvent = (\n resultValue: SkiaBaseViewProps[\"onSize\"],\n onLayout?: (event: LayoutChangeEvent) => void\n) => {\n return useCallback(\n (event: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(event);\n }\n const { width, height } = event.nativeEvent.layout;\n\n if (resultValue) {\n resultValue.value = { width, height };\n }\n },\n [onLayout, resultValue]\n );\n};\n\nexport const CanvasOld = forwardRef<SkiaDomView, CanvasOldProps>(\n (\n {\n children,\n style,\n debug,\n mode = \"default\",\n onSize: _onSize,\n onLayout: _onLayout,\n ...props\n },\n forwardedRef\n ) => {\n const onLayout = useOnSizeEvent(_onSize, _onLayout);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const redraw = useCallback(() => {\n innerRef.current?.redraw();\n }, [innerRef]);\n const getNativeId = useCallback(() => {\n const id = innerRef.current?.nativeId ?? -1;\n return id;\n }, [innerRef]);\n\n const root = useMemo(\n () => new SkiaRoot(redraw, getNativeId),\n [redraw, getNativeId]\n );\n\n // Render effect\n useEffect(() => {\n root.render(children);\n }, [children, root, redraw]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={root.dom}\n onLayout={onLayout}\n debug={debug}\n mode={mode}\n {...props}\n />\n );\n }\n) as FunctionComponent<CanvasOldProps & React.RefAttributes<SkiaDomView>>;\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"],"mappings":";AAAA,OAAOA,KAAK,IACVC,SAAS,EACTC,WAAW,EACXC,OAAO,EACPC,UAAU,EACVC,MAAM,QACD,OAAO;AAUd,SAASC,WAAW,QAAQ,UAAU;AAGtC,SAASC,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,YAAY,GAAGA,CAAA,KAAMH,MAAM,CAAc,IAAI,CAAC;AAQ3D,MAAMI,cAAc,GAAGA,CACrBC,WAAwC,EACxCC,QAA6C,KAC1C;EACH,OAAOT,WAAW,CACfU,KAAwB,IAAK;IAC5B,IAAID,QA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=> {
12
12
 
13
13
  const rec = Skia.PictureRecorder();
14
14
  const canvas = rec.beginRecording();
15
- // const start = performance.now();
15
+ //const start = performance.now();
16
16
 
17
17
  const ctx = createDrawingContext(Skia, recording.paintPool, canvas);
18
18
  replay(ctx, recording.commands);
@@ -76,18 +76,23 @@ class ReanimatedContainer extends Container {
76
76
  commands: record.commands,
77
77
  paintPool: record.paintPool
78
78
  };
79
+ const {
80
+ nativeId,
81
+ Skia,
82
+ recording
83
+ } = this;
79
84
  if (animationValues.size > 0) {
80
- const {
81
- nativeId,
82
- Skia,
83
- recording
84
- } = this;
85
85
  this.mapperId = Rea.startMapper(() => {
86
86
  "worklet";
87
87
 
88
88
  drawOnscreen(Skia, nativeId, recording);
89
89
  }, Array.from(animationValues));
90
90
  }
91
+ Rea.runOnUI(() => {
92
+ "worklet";
93
+
94
+ drawOnscreen(Skia, nativeId, recording);
95
+ })();
91
96
  }
92
97
  }
93
98
  export const createContainer = (Skia, nativeId) => {
@@ -1 +1 @@
1
- {"version":3,"names":["Rea","HAS_REANIMATED_3","Recorder","visit","replay","createDrawingContext","drawOnscreen","Skia","nativeId","recording","rec","PictureRecorder","canvas","beginRecording","ctx","paintPool","commands","picture","finishRecordingAsPicture","SkiaViewApi","setJsiProperty","dispose","Container","constructor","_defineProperty","drawOnCanvas","Error","StaticContainer","redraw","recorder","root","getRecording","isOnScreen","ReanimatedContainer","mapperId","stopMapper","record","animationValues","size","startMapper","Array","from","createContainer"],"sources":["Container.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkCanvas } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\n\nimport type { Node } from \"./Node\";\nimport type { Recording } from \"./Recorder/Recorder\";\nimport { Recorder } from \"./Recorder/Recorder\";\nimport { visit } from \"./Recorder/Visitor\";\nimport { replay } from \"./Recorder/Player\";\nimport { createDrawingContext } from \"./Recorder/DrawingContext\";\n\nconst drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {\n \"worklet\";\n\n const rec = Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n // const start = performance.now();\n\n const ctx = createDrawingContext(Skia, recording.paintPool, canvas);\n replay(ctx, recording.commands);\n const picture = rec.finishRecordingAsPicture();\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n rec.dispose();\n picture.dispose();\n};\n\nexport abstract class Container {\n public root: Node[] = [];\n protected recording: Recording | null = null;\n\n constructor(protected Skia: Skia, protected nativeId: number) {}\n\n drawOnCanvas(canvas: SkCanvas) {\n if (!this.recording) {\n throw new Error(\"No recording to draw\");\n }\n const ctx = createDrawingContext(\n this.Skia,\n this.recording.paintPool,\n canvas\n );\n //console.log(this.recording.commands);\n replay(ctx, this.recording.commands);\n }\n\n abstract redraw(): void;\n}\n\nclass StaticContainer extends Container {\n constructor(Skia: Skia, nativeId: number) {\n super(Skia, nativeId);\n }\n\n redraw() {\n const recorder = new Recorder();\n visit(recorder, this.root);\n this.recording = recorder.getRecording();\n const isOnScreen = this.nativeId !== -1;\n if (isOnScreen) {\n const rec = this.Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n this.drawOnCanvas(canvas);\n const picture = rec.finishRecordingAsPicture();\n SkiaViewApi.setJsiProperty(this.nativeId, \"picture\", picture);\n }\n }\n}\n\nclass ReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(Skia: Skia, nativeId: number) {\n super(Skia, nativeId);\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n const recorder = new Recorder();\n visit(recorder, this.root);\n const record = recorder.getRecording();\n const { animationValues } = record;\n this.recording = {\n commands: record.commands,\n paintPool: record.paintPool,\n };\n if (animationValues.size > 0) {\n const { nativeId, Skia, recording } = this;\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n }, Array.from(animationValues));\n }\n }\n}\n\nexport const createContainer = (Skia: Skia, nativeId: number) => {\n return HAS_REANIMATED_3 && nativeId !== -1\n ? new ReanimatedContainer(Skia, nativeId)\n : new StaticContainer(Skia, nativeId);\n};\n"],"mappings":";;;AAAA,OAAOA,GAAG,MAAM,wCAAwC;AAExD,SAASC,gBAAgB,QAAQ,sCAAsC;AAIvE,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE,MAAMC,YAAY,GAAGA,CAACC,IAAU,EAAEC,QAAgB,EAAEC,SAAoB,KAAK;EAC3E,SAAS;;EAET,MAAMC,GAAG,GAAGH,IAAI,CAACI,eAAe,CAAC,CAAC;EAClC,MAAMC,MAAM,GAAGF,GAAG,CAACG,cAAc,CAAC,CAAC;EACnC;;EAEA,MAAMC,GAAG,GAAGT,oBAAoB,CAACE,IAAI,EAAEE,SAAS,CAACM,SAAS,EAAEH,MAAM,CAAC;EACnER,MAAM,CAACU,GAAG,EAAEL,SAAS,CAACO,QAAQ,CAAC;EAC/B,MAAMC,OAAO,GAAGP,GAAG,CAACQ,wBAAwB,CAAC,CAAC;EAC9C;EACA;EACAC,WAAW,CAACC,cAAc,CAACZ,QAAQ,EAAE,SAAS,EAAES,OAAO,CAAC;EACxDP,GAAG,CAACW,OAAO,CAAC,CAAC;EACbJ,OAAO,CAACI,OAAO,CAAC,CAAC;AACnB,CAAC;AAED,OAAO,MAAeC,SAAS,CAAC;EAI9BC,WAAWA,CAAWhB,IAAU,EAAYC,QAAgB,EAAE;IAAA,KAAxCD,IAAU,GAAVA,IAAU;IAAA,KAAYC,QAAgB,GAAhBA,QAAgB;IAAAgB,eAAA,eAHtC,EAAE;IAAAA,eAAA,oBACgB,IAAI;EAEmB;EAE/DC,YAAYA,CAACb,MAAgB,EAAE;IAC7B,IAAI,CAAC,IAAI,CAACH,SAAS,EAAE;MAC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AAK,IAAI,EAAE;MAC1BlC,GAAG,CAACmC,UAAU,CAAC,IAAI,CAACD,QAAQ,CAAC;IAC/B;IACA,MAAML,QAAQ,GAAG,IAAI3B,QAAQ,CAAC,CAAC;IAC/BC,KAAK,CAAC0B,QAAQ,EAAE,IAAI,CAACC,IAAI,CAAC;IAC1B,MAAMM,MAAM,GAAGP,QAAQ,CAACE,YAAY,CAAC,CAAC;IACtC,MAAM;MAAEM;IAAgB,CAAC,GAAGD,MAAM;IAClC,IAAI,CAAC3B,SAAS,GAAG;MACfO,QAAQ,EAAEoB,MAAM,CAACpB,QAAQ;MACzBD,SAAS,EAAEqB,MAAM,CAACrB;IACpB,CAAC;IACD,IAAIsB,eAAe,CAACC,IAAI,GAAG,CAAC,EAAE;MAC5B,MAAM;QAAE9B,QAAQ;QAAED,IAAI;QAAEE;MAAU,CAAC,GAAG,IAAI;MAC1C,IAAI,CAACyB,QAAQ,GAAGlC,GAAG,CAACuC,WAAW,CAAC,MAAM;QACpC,SAAS;;QACTjC,YAAY,CAACC,IAAI,EAAEC,QAAQ,EAAEC,SAAU,CAAC;MAC1C,CAAC,EAAE+B,KAAK,CAACC,IAAI,CAACJ,eAAe,CAAC,CAAC;IACjC;EACF;AACF;AAEA,OAAO,MAAMK,eAAe,GAAGA,CAACnC,IAAU,EAAEC,QAAgB,KAAK;EAC/D,OAAOP,gBAAgB,IAAIO,QAAQ,KAAK,CAAC,CAAC,GACtC,IAAIyB,mBAAmB,CAAC1B,IAAI,EAAEC,QAAQ,CAAC,GACvC,IAAImB,eAAe,CAACpB,IAAI,EAAEC,QAAQ,CAAC;AACzC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Rea","HAS_REANIMATED_3","Recorder","visit","replay","createDrawingContext","drawOnscreen","Skia","nativeId","recording","rec","PictureRecorder","canvas","beginRecording","ctx","paintPool","commands","picture","finishRecordingAsPicture","SkiaViewApi","setJsiProperty","dispose","Container","constructor","_defineProperty","drawOnCanvas","Error","StaticContainer","redraw","recorder","root","getRecording","isOnScreen","ReanimatedContainer","mapperId","stopMapper","record","animationValues","size","startMapper","Array","from","runOnUI","createContainer"],"sources":["Container.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkCanvas } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\n\nimport type { Node } from \"./Node\";\nimport type { Recording } from \"./Recorder/Recorder\";\nimport { Recorder } from \"./Recorder/Recorder\";\nimport { visit } from \"./Recorder/Visitor\";\nimport { replay } from \"./Recorder/Player\";\nimport { createDrawingContext } from \"./Recorder/DrawingContext\";\n\nconst drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {\n \"worklet\";\n\n const rec = Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n //const start = performance.now();\n\n const ctx = createDrawingContext(Skia, recording.paintPool, canvas);\n replay(ctx, recording.commands);\n const picture = rec.finishRecordingAsPicture();\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n rec.dispose();\n picture.dispose();\n};\n\nexport abstract class Container {\n public root: Node[] = [];\n protected recording: Recording | null = null;\n\n constructor(protected Skia: Skia, protected nativeId: number) {}\n\n drawOnCanvas(canvas: SkCanvas) {\n if (!this.recording) {\n throw new Error(\"No recording to draw\");\n }\n const ctx = createDrawingContext(\n this.Skia,\n this.recording.paintPool,\n canvas\n );\n //console.log(this.recording.commands);\n replay(ctx, this.recording.commands);\n }\n\n abstract redraw(): void;\n}\n\nclass StaticContainer extends Container {\n constructor(Skia: Skia, nativeId: number) {\n super(Skia, nativeId);\n }\n\n redraw() {\n const recorder = new Recorder();\n visit(recorder, this.root);\n this.recording = recorder.getRecording();\n const isOnScreen = this.nativeId !== -1;\n if (isOnScreen) {\n const rec = this.Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n this.drawOnCanvas(canvas);\n const picture = rec.finishRecordingAsPicture();\n SkiaViewApi.setJsiProperty(this.nativeId, \"picture\", picture);\n }\n }\n}\n\nclass ReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(Skia: Skia, nativeId: number) {\n super(Skia, nativeId);\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n const recorder = new Recorder();\n visit(recorder, this.root);\n const record = recorder.getRecording();\n const { animationValues } = record;\n this.recording = {\n commands: record.commands,\n paintPool: record.paintPool,\n };\n const { nativeId, Skia, recording } = this;\n if (animationValues.size > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n }, Array.from(animationValues));\n }\n Rea.runOnUI(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n })();\n }\n}\n\nexport const createContainer = (Skia: Skia, nativeId: number) => {\n return HAS_REANIMATED_3 && nativeId !== -1\n ? new ReanimatedContainer(Skia, nativeId)\n : new StaticContainer(Skia, nativeId);\n};\n"],"mappings":";;;AAAA,OAAOA,GAAG,MAAM,wCAAwC;AAExD,SAASC,gBAAgB,QAAQ,sCAAsC;AAIvE,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE,MAAMC,YAAY,GAAGA,CAACC,IAAU,EAAEC,QAAgB,EAAEC,SAAoB,KAAK;EAC3E,SAAS;;EAET,MAAMC,GAAG,GAAGH,IAAI,CAACI,eAAe,CAAC,CAAC;EAClC,MAAMC,MAAM,GAAGF,GAAG,CAACG,cAAc,CAAC,CAAC;EACnC;;EAEA,MAAMC,GAAG,GAAGT,oBAAoB,CAACE,IAAI,EAAEE,SAAS,CAACM,SAAS,EAAEH,MAAM,CAAC;EACnER,MAAM,CAACU,GAAG,EAAEL,SAAS,CAACO,QAAQ,CAAC;EAC/B,MAAMC,OAAO,GAAGP,GAAG,CAACQ,wBAAwB,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AAG,CAAC0C,OAAO,CAAC,MAAM;MAChB,SAAS;;MACTpC,YAAY,CAACC,IAAI,EAAEC,QAAQ,EAAEC,SAAU,CAAC;IAC1C,CAAC,CAAC,CAAC,CAAC;EACN;AACF;AAEA,OAAO,MAAMkC,eAAe,GAAGA,CAACpC,IAAU,EAAEC,QAAgB,KAAK;EAC/D,OAAOP,gBAAgB,IAAIO,QAAQ,KAAK,CAAC,CAAC,GACtC,IAAIyB,mBAAmB,CAAC1B,IAAI,EAAEC,QAAQ,CAAC,GACvC,IAAImB,eAAe,CAACpB,IAAI,EAAEC,QAAQ,CAAC;AACzC,CAAC","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ import type { HostConfig } from "react-reconciler";
2
+ import type { NodeType } from "../dom/types";
3
+ import type { Container } from "./Container";
4
+ import type { Node } from "./Node";
5
+ export declare const debug: (message?: any, ...optionalParams: any[]) => void;
6
+ type Instance = Node<unknown>;
7
+ type Props = object;
8
+ type TextInstance = Node<unknown>;
9
+ type SuspenseInstance = Instance;
10
+ type HydratableInstance = Instance;
11
+ type PublicInstance = Instance;
12
+ type HostContext = null;
13
+ type UpdatePayload = Container;
14
+ type ChildSet = unknown;
15
+ type TimeoutHandle = NodeJS.Timeout;
16
+ type NoTimeout = -1;
17
+ type SkiaHostConfig = HostConfig<NodeType, Props, Container, Instance, TextInstance, SuspenseInstance, HydratableInstance, PublicInstance, HostContext, UpdatePayload, ChildSet, TimeoutHandle, NoTimeout>;
18
+ export declare const sksgHostConfig: SkiaHostConfig;
19
+ export {};
@@ -0,0 +1,152 @@
1
+ /*global NodeJS*/
2
+
3
+ import { DefaultEventPriority } from "react-reconciler/constants";
4
+ import { shallowEq } from "../renderer/typeddash";
5
+ const DEBUG = false;
6
+ export const debug = (...args) => {
7
+ if (DEBUG) {
8
+ console.log(...args);
9
+ }
10
+ };
11
+ const appendNode = (parent, child) => {
12
+ parent.children.push(child);
13
+ };
14
+ const removeNode = (parent, child) => {
15
+ parent.children.splice(parent.children.indexOf(child), 1);
16
+ };
17
+ const insertBefore = (parent, child, before) => {
18
+ parent.children.splice(parent.children.indexOf(before), 0, child);
19
+ };
20
+ export const sksgHostConfig = {
21
+ /**
22
+ * This function is used by the reconciler in order to calculate current time for prioritising work.
23
+ */
24
+ supportsMutation: true,
25
+ isPrimaryRenderer: false,
26
+ supportsPersistence: false,
27
+ supportsHydration: false,
28
+ //supportsMicrotask: true,
29
+
30
+ scheduleTimeout: setTimeout,
31
+ cancelTimeout: clearTimeout,
32
+ noTimeout: -1,
33
+ appendChildToContainer(container, child) {
34
+ debug("appendChildToContainer");
35
+ container.root.push(child);
36
+ },
37
+ appendChild(parent, child) {
38
+ debug("appendChild", parent, child);
39
+ appendNode(parent, child);
40
+ },
41
+ getRootHostContext: _rootContainerInstance => {
42
+ debug("getRootHostContext");
43
+ return null;
44
+ },
45
+ getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {
46
+ debug("getChildHostContext");
47
+ return null;
48
+ },
49
+ shouldSetTextContent(_type, _props) {
50
+ return false;
51
+ },
52
+ createTextInstance(_text, _rootContainerInstance, _hostContext, _internalInstanceHandle) {
53
+ debug("createTextInstance");
54
+ // return SpanNode({}, text) as SkNode;
55
+ throw new Error("Text nodes are not supported yet");
56
+ },
57
+ createInstance(type, propsWithChildren, _container, _hostContext, _internalInstanceHandle) {
58
+ debug("createInstance", type);
59
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
+ const {
61
+ children,
62
+ ...props
63
+ } = propsWithChildren;
64
+ debug("createInstance", type);
65
+ const instance = {
66
+ type,
67
+ props,
68
+ children: []
69
+ };
70
+ return instance;
71
+ },
72
+ appendInitialChild(parentInstance, child) {
73
+ debug("appendInitialChild");
74
+ appendNode(parentInstance, child);
75
+ },
76
+ finalizeInitialChildren(parentInstance, _type, _props, _rootContainerInstance, _hostContext) {
77
+ debug("finalizeInitialChildren", parentInstance);
78
+ return false;
79
+ },
80
+ commitMount() {
81
+ // if finalizeInitialChildren = true
82
+ debug("commitMount");
83
+ },
84
+ prepareForCommit(_containerInfo) {
85
+ debug("prepareForCommit");
86
+ return null;
87
+ },
88
+ resetAfterCommit(container) {
89
+ debug("resetAfterCommit");
90
+ container.redraw();
91
+ },
92
+ getPublicInstance(node) {
93
+ debug("getPublicInstance");
94
+ return node;
95
+ },
96
+ prepareUpdate: (_instance, type, oldProps, newProps, rootContainerInstance, _hostContext) => {
97
+ debug("prepareUpdate");
98
+ const propsAreEqual = shallowEq(oldProps, newProps);
99
+ if (propsAreEqual) {
100
+ return null;
101
+ }
102
+ debug("update ", type);
103
+ return rootContainerInstance;
104
+ },
105
+ commitUpdate(instance, _updatePayload, type, prevProps, nextProps, _internalHandle) {
106
+ debug("commitUpdate: ", type);
107
+ if (shallowEq(prevProps, nextProps)) {
108
+ return;
109
+ }
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+ const {
112
+ children,
113
+ ...props
114
+ } = nextProps;
115
+ instance.props = props;
116
+ },
117
+ commitTextUpdate: (_textInstance, _oldText, _newText) => {
118
+ // textInstance.instance = newText;
119
+ },
120
+ clearContainer: container => {
121
+ debug("clearContainer");
122
+ container.root = [];
123
+ },
124
+ preparePortalMount: () => {
125
+ debug("preparePortalMount");
126
+ },
127
+ removeChild: (parent, child) => {
128
+ removeNode(parent, child);
129
+ },
130
+ removeChildFromContainer: (container, child) => {
131
+ container.root.splice(container.root.indexOf(child), 1);
132
+ },
133
+ insertInContainerBefore: (container, child, before) => {
134
+ container.root.splice(container.root.indexOf(before), 0, child);
135
+ },
136
+ insertBefore: (parent, child, before) => {
137
+ insertBefore(parent, child, before);
138
+ },
139
+ // see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
140
+ getCurrentEventPriority: () => DefaultEventPriority,
141
+ beforeActiveInstanceBlur: () => {},
142
+ afterActiveInstanceBlur: () => {},
143
+ detachDeletedInstance: () => {},
144
+ getInstanceFromNode: function (_node) {
145
+ return null;
146
+ },
147
+ prepareScopeUpdate: function (_scopeInstance, _instance) {},
148
+ getInstanceFromScope: function (_scopeInstance) {
149
+ return null;
150
+ }
151
+ };
152
+ //# sourceMappingURL=HostConfig2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DefaultEventPriority","shallowEq","DEBUG","debug","args","console","log","appendNode","parent","child","children","push","removeNode","splice","indexOf","insertBefore","before","sksgHostConfig","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","container","root","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","type","propsWithChildren","_container","props","instance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","resetAfterCommit","redraw","getPublicInstance","node","prepareUpdate","_instance","oldProps","newProps","rootContainerInstance","propsAreEqual","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore","getCurrentEventPriority","beforeActiveInstanceBlur","afterActiveInstanceBlur","detachDeletedInstance","getInstanceFromNode","_node","prepareScopeUpdate","_scopeInstance","getInstanceFromScope"],"sources":["HostConfig2.ts"],"sourcesContent":["/*global NodeJS*/\nimport type { Fiber, HostConfig } from \"react-reconciler\";\nimport { DefaultEventPriority } from \"react-reconciler/constants\";\n\nimport type { NodeType } from \"../dom/types\";\nimport { shallowEq } from \"../renderer/typeddash\";\n\nimport type { Container } from \"./Container\";\nimport type { Node } from \"./Node\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ntype Instance = Node<unknown>;\n\ntype Props = object;\ntype TextInstance = Node<unknown>;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = Container;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\nconst appendNode = (parent: Node<unknown>, child: Node<unknown>) => {\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node<unknown>, child: Node<unknown>) => {\n parent.children.splice(parent.children.indexOf(child), 1);\n};\n\nconst insertBefore = (\n parent: Node<unknown>,\n child: Node<unknown>,\n before: Node<unknown>\n) => {\n parent.children.splice(parent.children.indexOf(before), 0, child);\n};\n\nexport const sksgHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\");\n container.root.push(child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Container) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n propsWithChildren,\n _container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { children, ...props } = propsWithChildren as any;\n debug(\"createInstance\", type);\n const instance = {\n type,\n props,\n children: [],\n };\n return instance;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n _instance,\n type,\n oldProps,\n newProps,\n rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual) {\n return null;\n }\n debug(\"update \", type);\n return rootContainerInstance;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps)) {\n return;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const { children, ...props } = nextProps as any;\n instance.props = props;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.root = [];\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (container, child) => {\n container.root.splice(container.root.indexOf(child), 1);\n },\n\n insertInContainerBefore: (container, child, before) => {\n container.root.splice(container.root.indexOf(before), 0, child);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n // see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874\n getCurrentEventPriority: () => DefaultEventPriority,\n beforeActiveInstanceBlur: () => {},\n afterActiveInstanceBlur: () => {},\n detachDeletedInstance: () => {},\n\n getInstanceFromNode: function (_node): Fiber | null | undefined {\n return null;\n },\n prepareScopeUpdate: function (_scopeInstance, _instance): void {},\n getInstanceFromScope: function (_scopeInstance): Instance | null {\n return null;\n },\n};\n"],"mappings":"AAAA;;AAEA,SAASA,oBAAoB,QAAQ,4BAA4B;AAGjE,SAASC,SAAS,QAAQ,uBAAuB;AAKjD,MAAMC,KAAK,GAAG,KAAK;AACnB,OAAO,MAAMC,KAAK,GAAGA,CAAC,GAAGC,IAAoC,KAAK;EAChE,IAAIF,KAAK,EAAE;IACTG,OAAO,CAACC,GAAG,CAAC,GAAGF,IAAI,CAAC;EACtB;AACF,CAAC;AA+BD,MAAMG,UAAU,GAAGA,CAACC,MAAqB,EAAEC,KAAoB,KAAK;EAClED,MAAM,CAACE,QAAQ,CAACC,IAAI,CAACF,KAAK,CAAC;AAC7B,CAAC;AAED,MAAMG,UAAU,GAAGA,CAACJ,MAAqB,EAAEC,KAAoB,KAAK;EAClED,MAAM,CAACE,QAAQ,CAACG,MAAM,CAACL,MAAM,CAACE,QAAQ,CAACI,OAAO,CAACL,KAAK,CAAC,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,MAAMM,YAAY,GAAGA,CACnBP,MAAqB,EACrBC,KAAoB,EACpBO,MAAqB,KAClB;EACHR,MAAM,CAACE,QAAQ,CAACG,MAAM,CAACL,MAAM,CAACE,QAAQ,CAACI,OAAO,CAACE,MAAM,CAAC,EAAE,CAAC,EAAEP,KAAK,CAAC;AACnE,CAAC;AAED,OAAO,MAAMQ,cAA8B,GAAG;EAC5C;AACF;AACA;EACEC,gBAAgB,EAAE,IAAI;EACtBC,iBAAiB,EAAE,KAAK;EACxBC,mBAAmB,EAAE,KAAK;EAC1BC,iBAAiB,EAAE,KAAK;EACxB;;EAEAC,eAAe,EAAEC,UAAU;EAC3BC,aAAa,EA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CAAC;EACjCC,qBAAqB,EAAEA,CAAA,KAAM,CAAC,CAAC;EAE/BC,mBAAmB,EAAE,SAAAA,CAAUC,KAAK,EAA4B;IAC9D,OAAO,IAAI;EACb,CAAC;EACDC,kBAAkB,EAAE,SAAAA,CAAUC,cAAc,EAAE1B,SAAS,EAAQ,CAAC,CAAC;EACjE2B,oBAAoB,EAAE,SAAAA,CAAUD,cAAc,EAAmB;IAC/D,OAAO,IAAI;EACb;AACF,CAAC","ignoreList":[]}
@@ -1,5 +1,6 @@
1
1
  // export enum CommandType {
2
2
  // // Context
3
+ // Group = "Group",
3
4
  // SavePaint = "SavePaint",
4
5
  // RestorePaint = "RestorePaint",
5
6
  // SaveCTM = "SaveCTM",
@@ -1 +1 @@
1
- {"version":3,"names":["CommandType","materializeProps","command","animatedProps","key","props","value","isCommand","type","isGroup","Group","isDrawCommand"],"sources":["Core.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type {\n BlurMaskFilterProps,\n CircleProps,\n CTMProps,\n ImageProps,\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 DrawingNodeProps,\n} from \"../../dom/types\";\n\n// export enum CommandType {\n// // Context\n// SavePaint = \"SavePaint\",\n// RestorePaint = \"RestorePaint\",\n// SaveCTM = \"SaveCTM\",\n// RestoreCTM = \"RestoreCTM\",\n// PushColorFilter = \"PushColorFilter\",\n// PushBlurMaskFilter = \"PushBlurMaskFilter\",\n// PushImageFilter = \"PushImageFilter\",\n// PushPathEffect = \"PushPathEffect\",\n// PushShader = \"PushShader\",\n// ComposeColorFilter = \"ComposeColorFilter\",\n// ComposeImageFilter = \"ComposeImageFilter\",\n// ComposePathEffect = \"ComposePathEffect\",\n// MaterializePaint = \"MaterializePaint\",\n// SaveBackdropFilter = \"SaveBackdropFilter\",\n// SaveLayer = \"SaveLayer\",\n// RestorePaintDeclaration = \"RestorePaintDeclaration\",\n// // Drawing\n// DrawBox = \"DrawBox\",\n// DrawImage = \"DrawImage\",\n// DrawCircle = \"DrawCircle\",\n// DrawPaint = \"DrawPaint\",\n// DrawPoints = \"DrawPoints\",\n// DrawPath = \"DrawPath\",\n// DrawRect = \"DrawRect\",\n// DrawRRect = \"DrawRRect\",\n// DrawOval = \"DrawOval\",\n// DrawLine = \"DrawLine\",\n// DrawPatch = \"DrawPatch\",\n// DrawVertices = \"DrawVertices\",\n// DrawDiffRect = \"DrawDiffRect\",\n// DrawText = \"DrawText\",\n// DrawTextPath = \"DrawTextPath\",\n// DrawTextBlob = \"DrawTextBlob\",\n// DrawGlyphs = \"DrawGlyphs\",\n// DrawPicture = \"DrawPicture\",\n// DrawImageSVG = \"DrawImageSVG\",\n// DrawParagraph = \"DrawParagraph\",\n// DrawAtlas = \"DrawAtlas\",\n// }\nexport enum CommandType {\n // Context\n Group,\n SavePaint,\n RestorePaint,\n SaveCTM,\n RestoreCTM,\n PushColorFilter,\n PushBlurMaskFilter,\n PushImageFilter,\n PushPathEffect,\n PushShader,\n ComposeColorFilter,\n ComposeImageFilter,\n ComposePathEffect,\n MaterializePaint,\n SaveBackdropFilter,\n SaveLayer,\n RestorePaintDeclaration,\n // Drawing\n DrawBox,\n DrawImage,\n DrawCircle,\n DrawPaint,\n DrawPoints,\n DrawPath,\n DrawRect,\n DrawRRect,\n DrawOval,\n DrawLine,\n DrawPatch,\n DrawVertices,\n DrawDiffRect,\n DrawText,\n DrawTextPath,\n DrawTextBlob,\n DrawGlyphs,\n DrawPicture,\n DrawImageSVG,\n DrawParagraph,\n DrawAtlas,\n}\n\nexport type Command<T extends CommandType = CommandType> = {\n type: T;\n [key: string]: unknown;\n};\n\nexport const materializeProps = (command: {\n props: Record<string, unknown>;\n animatedProps?: Record<string, SharedValue<unknown>>;\n}) => {\n \"worklet\";\n if (command.animatedProps) {\n for (const key in command.animatedProps) {\n command.props[key] = command.animatedProps[key].value;\n }\n }\n};\n\nexport const isCommand = <T extends CommandType>(\n command: Command,\n type: T\n): command is Command<T> => {\n \"worklet\";\n return command.type === type;\n};\n\ninterface GroupCommand extends Command<CommandType.Group> {\n children: Command[];\n}\n\nexport const isGroup = (command: Command): command is GroupCommand => {\n \"worklet\";\n return command.type === CommandType.Group;\n};\n\ninterface Props {\n [CommandType.DrawImage]: ImageProps;\n [CommandType.DrawCircle]: CircleProps;\n [CommandType.SaveCTM]: CTMProps;\n [CommandType.SavePaint]: DrawingNodeProps;\n [CommandType.PushBlurMaskFilter]: BlurMaskFilterProps;\n [CommandType.DrawPoints]: PointsProps;\n [CommandType.DrawPath]: PathProps;\n [CommandType.DrawRect]: RectProps;\n [CommandType.DrawRRect]: RoundedRectProps;\n [CommandType.DrawOval]: OvalProps;\n [CommandType.DrawLine]: LineProps;\n [CommandType.DrawPatch]: PatchProps;\n [CommandType.DrawVertices]: VerticesProps;\n [CommandType.DrawDiffRect]: DiffRectProps;\n [CommandType.DrawText]: TextProps;\n [CommandType.DrawTextPath]: TextPathProps;\n [CommandType.DrawTextBlob]: TextBlobProps;\n [CommandType.DrawGlyphs]: GlyphsProps;\n [CommandType.DrawPicture]: PictureProps;\n [CommandType.DrawImageSVG]: ImageSVGProps;\n [CommandType.DrawParagraph]: ParagraphProps;\n [CommandType.DrawAtlas]: AtlasProps;\n}\n\ninterface DrawCommand<T extends CommandType> extends Command<T> {\n props: T extends keyof Props ? Props[T] : never;\n}\n\nexport const isDrawCommand = <T extends keyof Props>(\n command: Command,\n type: T\n): command is DrawCommand<T> => {\n \"worklet\";\n return command.type === type;\n};\n"],"mappings":"AA2BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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CAACC,aAAa,EAAE;MACvCD,OAAO,CAACG,KAAK,CAACD,GAAG,CAAC,GAAGF,OAAO,CAACC,aAAa,CAACC,GAAG,CAAC,CAACE,KAAK;IACvD;EACF;AACF,CAAC;AAED,OAAO,MAAMC,SAAS,GAAGA,CACvBL,OAAgB,EAChBM,IAAO,KACmB;EAC1B,SAAS;;EACT,OAAON,OAAO,CAACM,IAAI,KAAKA,IAAI;AAC9B,CAAC;AAMD,OAAO,MAAMC,OAAO,GAAIP,OAAgB,IAA8B;EACpE,SAAS;;EACT,OAAOA,OAAO,CAACM,IAAI,KAAKR,WAAW,CAACU,KAAK;AAC3C,CAAC;AA+BD,OAAO,MAAMC,aAAa,GAAGA,CAC3BT,OAAgB,EAChBM,IAAO,KACuB;EAC9B,SAAS;;EACT,OAAON,OAAO,CAACM,IAAI,KAAKA,IAAI;AAC9B,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["CommandType","materializeProps","command","animatedProps","key","props","value","isCommand","type","isGroup","Group","isDrawCommand"],"sources":["Core.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type {\n BlurMaskFilterProps,\n CircleProps,\n CTMProps,\n ImageProps,\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 DrawingNodeProps,\n} from \"../../dom/types\";\n\n// export enum CommandType {\n// // Context\n// Group = \"Group\",\n// SavePaint = \"SavePaint\",\n// RestorePaint = \"RestorePaint\",\n// SaveCTM = \"SaveCTM\",\n// RestoreCTM = \"RestoreCTM\",\n// PushColorFilter = \"PushColorFilter\",\n// PushBlurMaskFilter = \"PushBlurMaskFilter\",\n// PushImageFilter = \"PushImageFilter\",\n// PushPathEffect = \"PushPathEffect\",\n// PushShader = \"PushShader\",\n// ComposeColorFilter = \"ComposeColorFilter\",\n// ComposeImageFilter = \"ComposeImageFilter\",\n// ComposePathEffect = \"ComposePathEffect\",\n// MaterializePaint = \"MaterializePaint\",\n// SaveBackdropFilter = \"SaveBackdropFilter\",\n// SaveLayer = \"SaveLayer\",\n// RestorePaintDeclaration = \"RestorePaintDeclaration\",\n// // Drawing\n// DrawBox = \"DrawBox\",\n// DrawImage = \"DrawImage\",\n// DrawCircle = \"DrawCircle\",\n// DrawPaint = \"DrawPaint\",\n// DrawPoints = \"DrawPoints\",\n// DrawPath = \"DrawPath\",\n// DrawRect = \"DrawRect\",\n// DrawRRect = \"DrawRRect\",\n// DrawOval = \"DrawOval\",\n// DrawLine = \"DrawLine\",\n// DrawPatch = \"DrawPatch\",\n// DrawVertices = \"DrawVertices\",\n// DrawDiffRect = \"DrawDiffRect\",\n// DrawText = \"DrawText\",\n// DrawTextPath = \"DrawTextPath\",\n// DrawTextBlob = \"DrawTextBlob\",\n// DrawGlyphs = \"DrawGlyphs\",\n// DrawPicture = \"DrawPicture\",\n// DrawImageSVG = \"DrawImageSVG\",\n// DrawParagraph = \"DrawParagraph\",\n// DrawAtlas = \"DrawAtlas\",\n// }\nexport enum CommandType {\n // Context\n Group,\n SavePaint,\n RestorePaint,\n SaveCTM,\n RestoreCTM,\n PushColorFilter,\n PushBlurMaskFilter,\n PushImageFilter,\n PushPathEffect,\n PushShader,\n ComposeColorFilter,\n ComposeImageFilter,\n ComposePathEffect,\n MaterializePaint,\n SaveBackdropFilter,\n SaveLayer,\n RestorePaintDeclaration,\n // Drawing\n DrawBox,\n DrawImage,\n DrawCircle,\n DrawPaint,\n DrawPoints,\n DrawPath,\n DrawRect,\n DrawRRect,\n DrawOval,\n DrawLine,\n DrawPatch,\n DrawVertices,\n DrawDiffRect,\n DrawText,\n DrawTextPath,\n DrawTextBlob,\n DrawGlyphs,\n DrawPicture,\n DrawImageSVG,\n DrawParagraph,\n DrawAtlas,\n}\n\nexport type Command<T extends CommandType = CommandType> = {\n type: T;\n [key: string]: unknown;\n};\n\nexport const materializeProps = (command: {\n props: Record<string, unknown>;\n animatedProps?: Record<string, SharedValue<unknown>>;\n}) => {\n \"worklet\";\n if (command.animatedProps) {\n for (const key in command.animatedProps) {\n command.props[key] = command.animatedProps[key].value;\n }\n }\n};\n\nexport const isCommand = <T extends CommandType>(\n command: Command,\n type: T\n): command is Command<T> => {\n \"worklet\";\n return command.type === type;\n};\n\ninterface GroupCommand extends Command<CommandType.Group> {\n children: Command[];\n}\n\nexport const isGroup = (command: Command): command is GroupCommand => {\n \"worklet\";\n return command.type === CommandType.Group;\n};\n\ninterface Props {\n [CommandType.DrawImage]: ImageProps;\n [CommandType.DrawCircle]: CircleProps;\n [CommandType.SaveCTM]: CTMProps;\n [CommandType.SavePaint]: DrawingNodeProps;\n [CommandType.PushBlurMaskFilter]: BlurMaskFilterProps;\n [CommandType.DrawPoints]: PointsProps;\n [CommandType.DrawPath]: PathProps;\n [CommandType.DrawRect]: RectProps;\n [CommandType.DrawRRect]: RoundedRectProps;\n [CommandType.DrawOval]: OvalProps;\n [CommandType.DrawLine]: LineProps;\n [CommandType.DrawPatch]: PatchProps;\n [CommandType.DrawVertices]: VerticesProps;\n [CommandType.DrawDiffRect]: DiffRectProps;\n [CommandType.DrawText]: TextProps;\n [CommandType.DrawTextPath]: TextPathProps;\n [CommandType.DrawTextBlob]: TextBlobProps;\n [CommandType.DrawGlyphs]: GlyphsProps;\n [CommandType.DrawPicture]: PictureProps;\n [CommandType.DrawImageSVG]: ImageSVGProps;\n [CommandType.DrawParagraph]: ParagraphProps;\n [CommandType.DrawAtlas]: AtlasProps;\n}\n\ninterface DrawCommand<T extends CommandType> extends Command<T> {\n props: T extends keyof Props ? Props[T] : never;\n}\n\nexport const isDrawCommand = <T extends keyof Props>(\n command: Command,\n type: T\n): command is DrawCommand<T> => {\n \"worklet\";\n return command.type === type;\n};\n"],"mappings":"AA2BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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