@shopify/react-native-skia 0.1.189 → 0.1.191

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. package/cpp/rnskia/dom/nodes/JsiImageSvgNode.h +24 -3
  2. package/cpp/rnskia/dom/nodes/JsiPathNode.h +11 -11
  3. package/jestSetup.js +17 -3
  4. package/lib/commonjs/Platform/IPlatform.d.ts +12 -0
  5. package/lib/commonjs/Platform/IPlatform.js +6 -0
  6. package/lib/commonjs/Platform/IPlatform.js.map +1 -0
  7. package/lib/commonjs/Platform/Platform.d.ts +2 -0
  8. package/lib/commonjs/Platform/Platform.js +24 -0
  9. package/lib/commonjs/Platform/Platform.js.map +1 -0
  10. package/lib/commonjs/Platform/Platform.web.d.ts +2 -0
  11. package/lib/commonjs/Platform/Platform.web.js +157 -0
  12. package/lib/commonjs/Platform/Platform.web.js.map +1 -0
  13. package/lib/commonjs/Platform/index.d.ts +1 -0
  14. package/lib/commonjs/Platform/index.js +19 -0
  15. package/lib/commonjs/Platform/index.js.map +1 -0
  16. package/lib/commonjs/dom/nodes/drawings/ImageSVG.d.ts +7 -2
  17. package/lib/commonjs/dom/nodes/drawings/ImageSVG.js +29 -7
  18. package/lib/commonjs/dom/nodes/drawings/ImageSVG.js.map +1 -1
  19. package/lib/commonjs/dom/nodes/drawings/PathNode.js +6 -2
  20. package/lib/commonjs/dom/nodes/drawings/PathNode.js.map +1 -1
  21. package/lib/commonjs/dom/types/Drawings.d.ts +7 -2
  22. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  23. package/lib/commonjs/renderer/processors/math/Math.d.ts +1 -0
  24. package/lib/commonjs/renderer/processors/math/Math.js +9 -1
  25. package/lib/commonjs/renderer/processors/math/Math.js.map +1 -1
  26. package/lib/commonjs/skia/NativeSetup.js +3 -3
  27. package/lib/commonjs/skia/NativeSetup.js.map +1 -1
  28. package/lib/commonjs/skia/core/Data.js +2 -8
  29. package/lib/commonjs/skia/core/Data.js.map +1 -1
  30. package/lib/commonjs/skia/core/Image.js +3 -3
  31. package/lib/commonjs/skia/core/Image.js.map +1 -1
  32. package/lib/commonjs/views/SkiaBaseWebView.d.ts +6 -1
  33. package/lib/commonjs/views/SkiaBaseWebView.js +41 -29
  34. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  35. package/lib/commonjs/views/SkiaDomView.js +2 -2
  36. package/lib/commonjs/views/SkiaDomView.js.map +1 -1
  37. package/lib/commonjs/views/SkiaPictureView.js +2 -2
  38. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  39. package/lib/commonjs/views/SkiaView.js +3 -2
  40. package/lib/commonjs/views/SkiaView.js.map +1 -1
  41. package/lib/commonjs/views/useTouchHandler.js +3 -3
  42. package/lib/commonjs/views/useTouchHandler.js.map +1 -1
  43. package/lib/commonjs/web/WithSkiaWeb.js +2 -2
  44. package/lib/commonjs/web/WithSkiaWeb.js.map +1 -1
  45. package/lib/module/Platform/IPlatform.d.ts +12 -0
  46. package/lib/module/Platform/IPlatform.js +2 -0
  47. package/lib/module/Platform/IPlatform.js.map +1 -0
  48. package/lib/module/Platform/Platform.d.ts +2 -0
  49. package/lib/module/Platform/Platform.js +14 -0
  50. package/lib/module/Platform/Platform.js.map +1 -0
  51. package/lib/module/Platform/Platform.web.d.ts +2 -0
  52. package/lib/module/Platform/Platform.web.js +143 -0
  53. package/lib/module/Platform/Platform.web.js.map +1 -0
  54. package/lib/module/Platform/index.d.ts +1 -0
  55. package/lib/module/Platform/index.js +2 -0
  56. package/lib/module/Platform/index.js.map +1 -0
  57. package/lib/module/dom/nodes/drawings/ImageSVG.d.ts +7 -2
  58. package/lib/module/dom/nodes/drawings/ImageSVG.js +29 -6
  59. package/lib/module/dom/nodes/drawings/ImageSVG.js.map +1 -1
  60. package/lib/module/dom/nodes/drawings/PathNode.js +5 -2
  61. package/lib/module/dom/nodes/drawings/PathNode.js.map +1 -1
  62. package/lib/module/dom/types/Drawings.d.ts +7 -2
  63. package/lib/module/dom/types/Drawings.js.map +1 -1
  64. package/lib/module/renderer/processors/math/Math.d.ts +1 -0
  65. package/lib/module/renderer/processors/math/Math.js +5 -0
  66. package/lib/module/renderer/processors/math/Math.js.map +1 -1
  67. package/lib/module/skia/NativeSetup.js +2 -2
  68. package/lib/module/skia/NativeSetup.js.map +1 -1
  69. package/lib/module/skia/core/Data.js +2 -7
  70. package/lib/module/skia/core/Data.js.map +1 -1
  71. package/lib/module/skia/core/Image.js +2 -2
  72. package/lib/module/skia/core/Image.js.map +1 -1
  73. package/lib/module/views/SkiaBaseWebView.d.ts +6 -1
  74. package/lib/module/views/SkiaBaseWebView.js +40 -28
  75. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  76. package/lib/module/views/SkiaDomView.js +2 -2
  77. package/lib/module/views/SkiaDomView.js.map +1 -1
  78. package/lib/module/views/SkiaPictureView.js +2 -2
  79. package/lib/module/views/SkiaPictureView.js.map +1 -1
  80. package/lib/module/views/SkiaView.js +2 -2
  81. package/lib/module/views/SkiaView.js.map +1 -1
  82. package/lib/module/views/useTouchHandler.js +3 -3
  83. package/lib/module/views/useTouchHandler.js.map +1 -1
  84. package/lib/module/web/WithSkiaWeb.js +1 -1
  85. package/lib/module/web/WithSkiaWeb.js.map +1 -1
  86. package/lib/typescript/src/Platform/IPlatform.d.ts +12 -0
  87. package/lib/typescript/src/Platform/Platform.d.ts +2 -0
  88. package/lib/typescript/src/Platform/Platform.web.d.ts +2 -0
  89. package/lib/typescript/src/Platform/index.d.ts +1 -0
  90. package/lib/typescript/src/dom/nodes/drawings/ImageSVG.d.ts +7 -2
  91. package/lib/typescript/src/dom/types/Drawings.d.ts +7 -2
  92. package/lib/typescript/src/renderer/processors/math/Math.d.ts +1 -0
  93. package/lib/typescript/src/views/SkiaBaseWebView.d.ts +6 -1
  94. package/package.json +12 -9
  95. package/scripts/install-npm.js +2 -3
  96. package/src/Platform/IPlatform.ts +20 -0
  97. package/src/Platform/Platform.ts +28 -0
  98. package/src/Platform/Platform.web.tsx +136 -0
  99. package/src/Platform/index.ts +1 -0
  100. package/src/dom/nodes/drawings/ImageSVG.ts +17 -6
  101. package/src/dom/nodes/drawings/PathNode.ts +10 -1
  102. package/src/dom/types/Drawings.ts +7 -2
  103. package/src/renderer/processors/math/Math.ts +5 -0
  104. package/src/skia/NativeSetup.ts +2 -2
  105. package/src/skia/core/Data.ts +4 -15
  106. package/src/skia/core/Image.ts +2 -3
  107. package/src/views/SkiaBaseWebView.tsx +33 -23
  108. package/src/views/SkiaDomView.tsx +2 -2
  109. package/src/views/SkiaPictureView.tsx +2 -2
  110. package/src/views/SkiaView.tsx +2 -2
  111. package/src/views/useTouchHandler.ts +3 -3
  112. package/src/web/WithSkiaWeb.tsx +2 -1
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Image","PixelRatio","requireNativeComponent","Platform","RNPlatform","findNodeHandle","NativeModules","View","isRNModule","OS","get","resolveAsset","source","resolveAssetSource","uri","default"],"sources":["Platform.ts"],"sourcesContent":["import {\n Image,\n PixelRatio,\n requireNativeComponent,\n Platform as RNPlatform,\n findNodeHandle,\n NativeModules,\n View,\n} from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\nexport const Platform: IPlatform = {\n OS: RNPlatform.OS,\n PixelRatio: PixelRatio.get(),\n requireNativeComponent,\n resolveAsset: (source: DataModule) => {\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : source.default;\n },\n findNodeHandle,\n NativeModules,\n View,\n};\n"],"mappings":"AAAA,SACEA,KADF,EAEEC,UAFF,EAGEC,sBAHF,EAIEC,QAAQ,IAAIC,UAJd,EAKEC,cALF,EAMEC,aANF,EAOEC,IAPF,QAQO,cARP;AAWA,SAASC,UAAT,QAA2B,eAA3B;AAIA,OAAO,MAAML,QAAmB,GAAG;EACjCM,EAAE,EAAEL,UAAU,CAACK,EADkB;EAEjCR,UAAU,EAAEA,UAAU,CAACS,GAAX,EAFqB;EAGjCR,sBAHiC;EAIjCS,YAAY,EAAGC,MAAD,IAAwB;IACpC,OAAOJ,UAAU,CAACI,MAAD,CAAV,GACHZ,KAAK,CAACa,kBAAN,CAAyBD,MAAzB,EAAiCE,GAD9B,GAEHF,MAAM,CAACG,OAFX;EAGD,CARgC;EASjCV,cATiC;EAUjCC,aAViC;EAWjCC;AAXiC,CAA5B"}
@@ -0,0 +1,2 @@
1
+ import type { IPlatform } from "./IPlatform";
2
+ export declare const Platform: IPlatform;
@@ -0,0 +1,143 @@
1
+ import React, { useLayoutEffect, useMemo, useRef } from "react";
2
+ import { isRNModule } from "../skia/types";
3
+ // eslint-disable-next-line max-len
4
+ // https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/modules/useElementLayout/index.js
5
+ const DOM_LAYOUT_HANDLER_NAME = "__reactLayoutHandler";
6
+ let resizeObserver = null;
7
+
8
+ const getObserver = () => {
9
+ if (resizeObserver == null) {
10
+ resizeObserver = new window.ResizeObserver(function (entries) {
11
+ entries.forEach(entry => {
12
+ const node = entry.target;
13
+ const {
14
+ left,
15
+ top,
16
+ width,
17
+ height
18
+ } = entry.contentRect;
19
+ const onLayout = node[DOM_LAYOUT_HANDLER_NAME];
20
+
21
+ if (typeof onLayout === "function") {
22
+ // setTimeout 0 is taken from react-native-web (UIManager)
23
+ setTimeout(() => onLayout({
24
+ timeStamp: Date.now(),
25
+ nativeEvent: {
26
+ layout: {
27
+ x: left,
28
+ y: top,
29
+ width,
30
+ height
31
+ }
32
+ },
33
+ currentTarget: 0,
34
+ target: 0,
35
+ bubbles: false,
36
+ cancelable: false,
37
+ defaultPrevented: false,
38
+ eventPhase: 0,
39
+
40
+ isDefaultPrevented() {
41
+ throw new Error("Method not supported on web.");
42
+ },
43
+
44
+ isPropagationStopped() {
45
+ throw new Error("Method not supported on web.");
46
+ },
47
+
48
+ persist() {
49
+ throw new Error("Method not supported on web.");
50
+ },
51
+
52
+ preventDefault() {
53
+ throw new Error("Method not supported on web.");
54
+ },
55
+
56
+ stopPropagation() {
57
+ throw new Error("Method not supported on web.");
58
+ },
59
+
60
+ isTrusted: true,
61
+ type: ""
62
+ }), 0);
63
+ }
64
+ });
65
+ });
66
+ }
67
+
68
+ return resizeObserver;
69
+ };
70
+
71
+ const useElementLayout = (ref, onLayout) => {
72
+ const observer = getObserver();
73
+ useLayoutEffect(() => {
74
+ const node = ref.current;
75
+
76
+ if (node !== null) {
77
+ node[DOM_LAYOUT_HANDLER_NAME] = onLayout;
78
+ }
79
+ }, [ref, onLayout]);
80
+ useLayoutEffect(() => {
81
+ const node = ref.current;
82
+
83
+ if (node != null && observer != null) {
84
+ if (typeof node[DOM_LAYOUT_HANDLER_NAME] === "function") {
85
+ observer.observe(node);
86
+ } else {
87
+ observer.unobserve(node);
88
+ }
89
+ }
90
+
91
+ return () => {
92
+ if (node != null && observer != null) {
93
+ observer.unobserve(node);
94
+ }
95
+ };
96
+ }, [observer, ref]);
97
+ };
98
+
99
+ const View = _ref => {
100
+ let {
101
+ children,
102
+ onLayout,
103
+ style: rawStyle
104
+ } = _ref;
105
+ const style = useMemo(() => rawStyle !== null && rawStyle !== void 0 ? rawStyle : {}, [rawStyle]);
106
+ const ref = useRef(null);
107
+ useElementLayout(ref, onLayout);
108
+ const cssStyles = useMemo(() => {
109
+ return { ...style,
110
+ display: "flex",
111
+ flexDirection: style.flexDirection || "inherit",
112
+ flexWrap: style.flexWrap || "nowrap",
113
+ justifyContent: style.justifyContent || "flex-start",
114
+ alignItems: style.alignItems || "stretch",
115
+ alignContent: style.alignContent || "stretch"
116
+ };
117
+ }, [style]);
118
+ return /*#__PURE__*/React.createElement("div", {
119
+ ref: ref,
120
+ style: cssStyles
121
+ }, children);
122
+ };
123
+
124
+ export const Platform = {
125
+ OS: "web",
126
+ PixelRatio: window.devicePixelRatio,
127
+ requireNativeComponent: () => {
128
+ throw new Error("requireNativeComponent is not supported on the web");
129
+ },
130
+ resolveAsset: source => {
131
+ if (isRNModule(source)) {
132
+ throw new Error("Image source is a number - this is not supported on the web");
133
+ }
134
+
135
+ return source.default;
136
+ },
137
+ findNodeHandle: () => {
138
+ throw new Error("findNodeHandle is not supported on the web");
139
+ },
140
+ NativeModules: {},
141
+ View
142
+ };
143
+ //# sourceMappingURL=Platform.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useLayoutEffect","useMemo","useRef","isRNModule","DOM_LAYOUT_HANDLER_NAME","resizeObserver","getObserver","window","ResizeObserver","entries","forEach","entry","node","target","left","top","width","height","contentRect","onLayout","setTimeout","timeStamp","Date","now","nativeEvent","layout","x","y","currentTarget","bubbles","cancelable","defaultPrevented","eventPhase","isDefaultPrevented","Error","isPropagationStopped","persist","preventDefault","stopPropagation","isTrusted","type","useElementLayout","ref","observer","current","observe","unobserve","View","children","style","rawStyle","cssStyles","display","flexDirection","flexWrap","justifyContent","alignItems","alignContent","Platform","OS","PixelRatio","devicePixelRatio","requireNativeComponent","resolveAsset","source","default","findNodeHandle","NativeModules"],"sources":["Platform.web.tsx"],"sourcesContent":["import type { RefObject, CSSProperties } from \"react\";\nimport React, { useLayoutEffect, useMemo, useRef } from \"react\";\nimport type { LayoutChangeEvent, ViewComponent, ViewProps } from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\n// eslint-disable-next-line max-len\n// https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/modules/useElementLayout/index.js\nconst DOM_LAYOUT_HANDLER_NAME = \"__reactLayoutHandler\";\ntype OnLayout = ((event: LayoutChangeEvent) => void) | undefined;\ntype Div = HTMLDivElement & {\n __reactLayoutHandler: OnLayout;\n};\n\nlet resizeObserver: ResizeObserver | null = null;\n\nconst getObserver = () => {\n if (resizeObserver == null) {\n resizeObserver = new window.ResizeObserver(function (entries) {\n entries.forEach((entry) => {\n const node = entry.target as Div;\n const { left, top, width, height } = entry.contentRect;\n const onLayout = node[DOM_LAYOUT_HANDLER_NAME];\n if (typeof onLayout === \"function\") {\n // setTimeout 0 is taken from react-native-web (UIManager)\n setTimeout(\n () =>\n onLayout({\n timeStamp: Date.now(),\n nativeEvent: { layout: { x: left, y: top, width, height } },\n currentTarget: 0,\n target: 0,\n bubbles: false,\n cancelable: false,\n defaultPrevented: false,\n eventPhase: 0,\n isDefaultPrevented() {\n throw new Error(\"Method not supported on web.\");\n },\n isPropagationStopped() {\n throw new Error(\"Method not supported on web.\");\n },\n persist() {\n throw new Error(\"Method not supported on web.\");\n },\n preventDefault() {\n throw new Error(\"Method not supported on web.\");\n },\n stopPropagation() {\n throw new Error(\"Method not supported on web.\");\n },\n isTrusted: true,\n type: \"\",\n }),\n 0\n );\n }\n });\n });\n }\n return resizeObserver;\n};\n\nconst useElementLayout = (ref: RefObject<Div>, onLayout: OnLayout) => {\n const observer = getObserver();\n\n useLayoutEffect(() => {\n const node = ref.current;\n if (node !== null) {\n node[DOM_LAYOUT_HANDLER_NAME] = onLayout;\n }\n }, [ref, onLayout]);\n\n useLayoutEffect(() => {\n const node = ref.current;\n if (node != null && observer != null) {\n if (typeof node[DOM_LAYOUT_HANDLER_NAME] === \"function\") {\n observer.observe(node);\n } else {\n observer.unobserve(node);\n }\n }\n return () => {\n if (node != null && observer != null) {\n observer.unobserve(node);\n }\n };\n }, [observer, ref]);\n};\n\nconst View = (({ children, onLayout, style: rawStyle }: ViewProps) => {\n const style = useMemo(() => (rawStyle ?? {}) as CSSProperties, [rawStyle]);\n const ref = useRef<Div>(null);\n useElementLayout(ref, onLayout);\n const cssStyles = useMemo(() => {\n return {\n ...style,\n display: \"flex\",\n flexDirection: style.flexDirection || \"inherit\",\n flexWrap: style.flexWrap || \"nowrap\",\n justifyContent: style.justifyContent || \"flex-start\",\n alignItems: style.alignItems || \"stretch\",\n alignContent: style.alignContent || \"stretch\",\n };\n }, [style]);\n\n return (\n <div ref={ref} style={cssStyles}>\n {children}\n </div>\n );\n}) as unknown as typeof ViewComponent;\n\nexport const Platform: IPlatform = {\n OS: \"web\",\n PixelRatio: window.devicePixelRatio,\n requireNativeComponent: () => {\n throw new Error(\"requireNativeComponent is not supported on the web\");\n },\n resolveAsset: (source: DataModule) => {\n if (isRNModule(source)) {\n throw new Error(\n \"Image source is a number - this is not supported on the web\"\n );\n }\n return source.default;\n },\n findNodeHandle: () => {\n throw new Error(\"findNodeHandle is not supported on the web\");\n },\n NativeModules: {},\n View,\n};\n"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,eAAhB,EAAiCC,OAAjC,EAA0CC,MAA1C,QAAwD,OAAxD;AAIA,SAASC,UAAT,QAA2B,eAA3B;AAIA;AACA;AACA,MAAMC,uBAAuB,GAAG,sBAAhC;AAMA,IAAIC,cAAqC,GAAG,IAA5C;;AAEA,MAAMC,WAAW,GAAG,MAAM;EACxB,IAAID,cAAc,IAAI,IAAtB,EAA4B;IAC1BA,cAAc,GAAG,IAAIE,MAAM,CAACC,cAAX,CAA0B,UAAUC,OAAV,EAAmB;MAC5DA,OAAO,CAACC,OAAR,CAAiBC,KAAD,IAAW;QACzB,MAAMC,IAAI,GAAGD,KAAK,CAACE,MAAnB;QACA,MAAM;UAAEC,IAAF;UAAQC,GAAR;UAAaC,KAAb;UAAoBC;QAApB,IAA+BN,KAAK,CAACO,WAA3C;QACA,MAAMC,QAAQ,GAAGP,IAAI,CAACR,uBAAD,CAArB;;QACA,IAAI,OAAOe,QAAP,KAAoB,UAAxB,EAAoC;UAClC;UACAC,UAAU,CACR,MACED,QAAQ,CAAC;YACPE,SAAS,EAAEC,IAAI,CAACC,GAAL,EADJ;YAEPC,WAAW,EAAE;cAAEC,MAAM,EAAE;gBAAEC,CAAC,EAAEZ,IAAL;gBAAWa,CAAC,EAAEZ,GAAd;gBAAmBC,KAAnB;gBAA0BC;cAA1B;YAAV,CAFN;YAGPW,aAAa,EAAE,CAHR;YAIPf,MAAM,EAAE,CAJD;YAKPgB,OAAO,EAAE,KALF;YAMPC,UAAU,EAAE,KANL;YAOPC,gBAAgB,EAAE,KAPX;YAQPC,UAAU,EAAE,CARL;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AN;EACD,CALgC;EAMjC6B,YAAY,EAAGC,MAAD,IAAwB;IACpC,IAAI7D,UAAU,CAAC6D,MAAD,CAAd,EAAwB;MACtB,MAAM,IAAI9B,KAAJ,CACJ,6DADI,CAAN;IAGD;;IACD,OAAO8B,MAAM,CAACC,OAAd;EACD,CAbgC;EAcjCC,cAAc,EAAE,MAAM;IACpB,MAAM,IAAIhC,KAAJ,CAAU,4CAAV,CAAN;EACD,CAhBgC;EAiBjCiC,aAAa,EAAE,EAjBkB;EAkBjCpB;AAlBiC,CAA5B"}
@@ -0,0 +1 @@
1
+ export * from "./Platform";
@@ -0,0 +1,2 @@
1
+ export * from "./Platform";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Platform\";\n"],"mappings":"AAAA,cAAc,YAAd"}
@@ -1,8 +1,13 @@
1
1
  import type { DrawingContext, ImageSVGProps } from "../../types";
2
2
  import { JsiDrawingNode } from "../DrawingNode";
3
3
  import type { NodeContext } from "../Node";
4
- export declare class ImageSVGNode extends JsiDrawingNode<ImageSVGProps, null> {
4
+ export declare class ImageSVGNode extends JsiDrawingNode<ImageSVGProps, Pick<ImageSVGProps, "x" | "y" | "width" | "height">> {
5
5
  constructor(ctx: NodeContext, props: ImageSVGProps);
6
- deriveProps(): null;
6
+ deriveProps(): import("../../..").SkRect | {
7
+ x: number | undefined;
8
+ y: number | undefined;
9
+ width: number | undefined;
10
+ height: number | undefined;
11
+ };
7
12
  draw({ canvas }: DrawingContext): void;
8
13
  }
@@ -1,5 +1,4 @@
1
1
  import { NodeType } from "../../types";
2
- import { processRect } from "../datatypes";
3
2
  import { JsiDrawingNode } from "../DrawingNode";
4
3
  export class ImageSVGNode extends JsiDrawingNode {
5
4
  constructor(ctx, props) {
@@ -7,7 +6,22 @@ export class ImageSVGNode extends JsiDrawingNode {
7
6
  }
8
7
 
9
8
  deriveProps() {
10
- return null;
9
+ if (this.props.rect) {
10
+ return this.props.rect;
11
+ }
12
+
13
+ const {
14
+ x,
15
+ y,
16
+ width,
17
+ height
18
+ } = this.props;
19
+ return {
20
+ x,
21
+ y,
22
+ width,
23
+ height
24
+ };
11
25
  }
12
26
 
13
27
  draw(_ref) {
@@ -18,8 +32,8 @@ export class ImageSVGNode extends JsiDrawingNode {
18
32
  svg
19
33
  } = this.props;
20
34
 
21
- if (!svg) {
22
- return;
35
+ if (!this.derived) {
36
+ throw new Error("ImageSVGNode: derived props unresolved");
23
37
  }
24
38
 
25
39
  const {
@@ -27,9 +41,18 @@ export class ImageSVGNode extends JsiDrawingNode {
27
41
  y,
28
42
  width,
29
43
  height
30
- } = processRect(this.Skia, this.props);
44
+ } = this.derived;
45
+
46
+ if (svg === null) {
47
+ return;
48
+ }
49
+
31
50
  canvas.save();
32
- canvas.translate(x, y);
51
+
52
+ if (x && y) {
53
+ canvas.translate(x, y);
54
+ }
55
+
33
56
  canvas.drawSvg(svg, width, height);
34
57
  canvas.restore();
35
58
  }
@@ -1 +1 @@
1
- {"version":3,"names":["NodeType","processRect","JsiDrawingNode","ImageSVGNode","constructor","ctx","props","ImageSVG","deriveProps","draw","canvas","svg","x","y","width","height","Skia","save","translate","drawSvg","restore"],"sources":["ImageSVG.ts"],"sourcesContent":["import type { DrawingContext, ImageSVGProps } from \"../../types\";\nimport { NodeType } from \"../../types\";\nimport { processRect } from \"../datatypes\";\nimport { JsiDrawingNode } from \"../DrawingNode\";\nimport type { NodeContext } from \"../Node\";\n\nexport class ImageSVGNode extends JsiDrawingNode<ImageSVGProps, null> {\n constructor(ctx: NodeContext, props: ImageSVGProps) {\n super(ctx, NodeType.ImageSVG, props);\n }\n\n deriveProps() {\n return null;\n }\n\n draw({ canvas }: DrawingContext) {\n const { svg } = this.props;\n if (!svg) {\n return;\n }\n const { x, y, width, height } = processRect(this.Skia, this.props);\n canvas.save();\n canvas.translate(x, y);\n canvas.drawSvg(svg, width, height);\n canvas.restore();\n }\n}\n"],"mappings":"AACA,SAASA,QAAT,QAAyB,aAAzB;AACA,SAASC,WAAT,QAA4B,cAA5B;AACA,SAASC,cAAT,QAA+B,gBAA/B;AAGA,OAAO,MAAMC,YAAN,SAA2BD,cAA3B,CAA+D;EACpEE,WAAW,CAACC,GAAD,EAAmBC,KAAnB,EAAyC;IAClD,MAAMD,GAAN,EAAWL,QAAQ,CAACO,QAApB,EAA8BD,KAA9B;EACD;;EAEDE,WAAW,GAAG;IACZ,OAAO,IAAP;EACD;;EAEDC,IAAI,OAA6B;IAAA,IAA5B;MAAEC;IAAF,CAA4B;IAC/B,MAAM;MAAEC;IAAF,IAAU,KAAKL,KAArB;;IACA,IAAI,CAACK,GAAL,EAAU;MACR;IACD;;IACD,MAAM;MAAEC,CAAF;MAAKC,CAAL;MAAQC,KAAR;MAAeC;IAAf,IAA0Bd,WAAW,CAAC,KAAKe,IAAN,EAAY,KAAKV,KAAjB,CAA3C;IACAI,MAAM,CAACO,IAAP;IACAP,MAAM,CAACQ,SAAP,CAAiBN,CAAjB,EAAoBC,CAApB;IACAH,MAAM,CAACS,OAAP,CAAeR,GAAf,EAAoBG,KAApB,EAA2BC,MAA3B;IACAL,MAAM,CAACU,OAAP;EACD;;AAnBmE"}
1
+ {"version":3,"names":["NodeType","JsiDrawingNode","ImageSVGNode","constructor","ctx","props","ImageSVG","deriveProps","rect","x","y","width","height","draw","canvas","svg","derived","Error","save","translate","drawSvg","restore"],"sources":["ImageSVG.ts"],"sourcesContent":["import type { DrawingContext, ImageSVGProps } from \"../../types\";\nimport { NodeType } from \"../../types\";\nimport { JsiDrawingNode } from \"../DrawingNode\";\nimport type { NodeContext } from \"../Node\";\n\nexport class ImageSVGNode extends JsiDrawingNode<\n ImageSVGProps,\n Pick<ImageSVGProps, \"x\" | \"y\" | \"width\" | \"height\">\n> {\n constructor(ctx: NodeContext, props: ImageSVGProps) {\n super(ctx, NodeType.ImageSVG, props);\n }\n\n deriveProps() {\n if (this.props.rect) {\n return this.props.rect;\n }\n const { x, y, width, height } = this.props;\n return { x, y, width, height };\n }\n\n draw({ canvas }: DrawingContext) {\n const { svg } = this.props;\n if (!this.derived) {\n throw new Error(\"ImageSVGNode: derived props unresolved\");\n }\n const { x, y, width, height } = this.derived;\n if (svg === null) {\n return;\n }\n canvas.save();\n if (x && y) {\n canvas.translate(x, y);\n }\n canvas.drawSvg(svg, width, height);\n canvas.restore();\n }\n}\n"],"mappings":"AACA,SAASA,QAAT,QAAyB,aAAzB;AACA,SAASC,cAAT,QAA+B,gBAA/B;AAGA,OAAO,MAAMC,YAAN,SAA2BD,cAA3B,CAGL;EACAE,WAAW,CAACC,GAAD,EAAmBC,KAAnB,EAAyC;IAClD,MAAMD,GAAN,EAAWJ,QAAQ,CAACM,QAApB,EAA8BD,KAA9B;EACD;;EAEDE,WAAW,GAAG;IACZ,IAAI,KAAKF,KAAL,CAAWG,IAAf,EAAqB;MACnB,OAAO,KAAKH,KAAL,CAAWG,IAAlB;IACD;;IACD,MAAM;MAAEC,CAAF;MAAKC,CAAL;MAAQC,KAAR;MAAeC;IAAf,IAA0B,KAAKP,KAArC;IACA,OAAO;MAAEI,CAAF;MAAKC,CAAL;MAAQC,KAAR;MAAeC;IAAf,CAAP;EACD;;EAEDC,IAAI,OAA6B;IAAA,IAA5B;MAAEC;IAAF,CAA4B;IAC/B,MAAM;MAAEC;IAAF,IAAU,KAAKV,KAArB;;IACA,IAAI,CAAC,KAAKW,OAAV,EAAmB;MACjB,MAAM,IAAIC,KAAJ,CAAU,wCAAV,CAAN;IACD;;IACD,MAAM;MAAER,CAAF;MAAKC,CAAL;MAAQC,KAAR;MAAeC;IAAf,IAA0B,KAAKI,OAArC;;IACA,IAAID,GAAG,KAAK,IAAZ,EAAkB;MAChB;IACD;;IACDD,MAAM,CAACI,IAAP;;IACA,IAAIT,CAAC,IAAIC,CAAT,EAAY;MACVI,MAAM,CAACK,SAAP,CAAiBV,CAAjB,EAAoBC,CAApB;IACD;;IACDI,MAAM,CAACM,OAAP,CAAeL,GAAf,EAAoBJ,KAApB,EAA2BC,MAA3B;IACAE,MAAM,CAACO,OAAP;EACD;;AA5BD"}
@@ -1,3 +1,4 @@
1
+ import { saturate } from "../../../renderer/processors/math";
1
2
  import { FillType } from "../../../skia/types";
2
3
  import { NodeType } from "../../types";
3
4
  import { enumKey, processPath } from "../datatypes";
@@ -9,12 +10,14 @@ export class PathNode extends JsiDrawingNode {
9
10
 
10
11
  deriveProps() {
11
12
  const {
12
- start,
13
- end,
13
+ start: trimStart,
14
+ end: trimEnd,
14
15
  fillType,
15
16
  stroke,
16
17
  ...pathProps
17
18
  } = this.props;
19
+ const start = saturate(trimStart);
20
+ const end = saturate(trimEnd);
18
21
  const hasStartOffset = start !== 0;
19
22
  const hasEndOffset = end !== 1;
20
23
  const hasStrokeOptions = stroke !== undefined;
@@ -1 +1 @@
1
- {"version":3,"names":["FillType","NodeType","enumKey","processPath","JsiDrawingNode","PathNode","constructor","ctx","props","Path","deriveProps","start","end","fillType","stroke","pathProps","hasStartOffset","hasEndOffset","hasStrokeOptions","undefined","hasFillType","willMutatePath","pristinePath","Skia","path","copy","setFillType","trim","draw","canvas","paint","derived","Error","drawPath"],"sources":["PathNode.ts"],"sourcesContent":["import { FillType } from \"../../../skia/types\";\nimport type { SkPath } from \"../../../skia/types\";\nimport type { DrawingContext, PathProps } from \"../../types\";\nimport { NodeType } from \"../../types\";\nimport { enumKey, processPath } from \"../datatypes\";\nimport { JsiDrawingNode } from \"../DrawingNode\";\nimport type { NodeContext } from \"../Node\";\n\nexport class PathNode extends JsiDrawingNode<PathProps, SkPath> {\n constructor(ctx: NodeContext, props: PathProps) {\n super(ctx, NodeType.Path, props);\n }\n\n protected deriveProps() {\n const { start, end, fillType, stroke, ...pathProps } = this.props;\n const hasStartOffset = start !== 0;\n const hasEndOffset = end !== 1;\n const hasStrokeOptions = stroke !== undefined;\n const hasFillType = !!fillType;\n const willMutatePath =\n hasStartOffset || hasEndOffset || hasStrokeOptions || hasFillType;\n const pristinePath = processPath(this.Skia, pathProps.path);\n const path = willMutatePath ? pristinePath.copy() : pristinePath;\n if (hasFillType) {\n path.setFillType(FillType[enumKey(fillType)]);\n }\n if (hasStrokeOptions) {\n path.stroke(stroke);\n }\n if (hasStartOffset || hasEndOffset) {\n path.trim(start, end, false);\n }\n return path;\n }\n\n draw({ canvas, paint }: DrawingContext) {\n if (!this.derived) {\n throw new Error(\"Path not initialized\");\n }\n canvas.drawPath(this.derived, paint);\n }\n}\n"],"mappings":"AAAA,SAASA,QAAT,QAAyB,qBAAzB;AAGA,SAASC,QAAT,QAAyB,aAAzB;AACA,SAASC,OAAT,EAAkBC,WAAlB,QAAqC,cAArC;AACA,SAASC,cAAT,QAA+B,gBAA/B;AAGA,OAAO,MAAMC,QAAN,SAAuBD,cAAvB,CAAyD;EAC9DE,WAAW,CAACC,GAAD,EAAmBC,KAAnB,EAAqC;IAC9C,MAAMD,GAAN,EAAWN,QAAQ,CAACQ,IAApB,EAA0BD,KAA1B;EACD;;EAESE,WAAW,GAAG;IACtB,MAAM;MAAEC,KAAF;MAASC,GAAT;MAAcC,QAAd;MAAwBC,MAAxB;MAAgC,GAAGC;IAAnC,IAAiD,KAAKP,KAA5D;IACA,MAAMQ,cAAc,GAAGL,KAAK,KAAK,CAAjC;IACA,MAAMM,YAAY,GAAGL,GAAG,KAAK,CAA7B;IACA,MAAMM,gBAAgB,GAAGJ,MAAM,KAAKK,SAApC;IACA,MAAMC,WAAW,GAAG,CAAC,CAACP,QAAtB;IACA,MAAMQ,cAAc,GAClBL,cAAc,IAAIC,YAAlB,IAAkCC,gBAAlC,IAAsDE,WADxD;IAEA,MAAME,YAAY,GAAGnB,WAAW,CAAC,KAAKoB,IAAN,EAAYR,SAAS,CAACS,IAAtB,CAAhC;IACA,MAAMA,IAAI,GAAGH,cAAc,GAAGC,YAAY,CAACG,IAAb,EAAH,GAAyBH,YAApD;;IACA,IAAIF,WAAJ,EAAiB;MACfI,IAAI,CAACE,WAAL,CAAiB1B,QAAQ,CAACE,OAAO,CAACW,QAAD,CAAR,CAAzB;IACD;;IACD,IAAIK,gBAAJ,EAAsB;MACpBM,IAAI,CAACV,MAAL,CAAYA,MAAZ;IACD;;IACD,IAAIE,cAAc,IAAIC,YAAtB,EAAoC;MAClCO,IAAI,CAACG,IAAL,CAAUhB,KAAV,EAAiBC,GAAjB,EAAsB,KAAtB;IACD;;IACD,OAAOY,IAAP;EACD;;EAEDI,IAAI,OAAoC;IAAA,IAAnC;MAAEC,MAAF;MAAUC;IAAV,CAAmC;;IACtC,IAAI,CAAC,KAAKC,OAAV,EAAmB;MACjB,MAAM,IAAIC,KAAJ,CAAU,sBAAV,CAAN;IACD;;IACDH,MAAM,CAACI,QAAP,CAAgB,KAAKF,OAArB,EAA8BD,KAA9B;EACD;;AAhC6D"}
1
+ {"version":3,"names":["saturate","FillType","NodeType","enumKey","processPath","JsiDrawingNode","PathNode","constructor","ctx","props","Path","deriveProps","start","trimStart","end","trimEnd","fillType","stroke","pathProps","hasStartOffset","hasEndOffset","hasStrokeOptions","undefined","hasFillType","willMutatePath","pristinePath","Skia","path","copy","setFillType","trim","draw","canvas","paint","derived","Error","drawPath"],"sources":["PathNode.ts"],"sourcesContent":["import { saturate } from \"../../../renderer/processors/math\";\nimport { FillType } from \"../../../skia/types\";\nimport type { SkPath } from \"../../../skia/types\";\nimport type { DrawingContext, PathProps } from \"../../types\";\nimport { NodeType } from \"../../types\";\nimport { enumKey, processPath } from \"../datatypes\";\nimport { JsiDrawingNode } from \"../DrawingNode\";\nimport type { NodeContext } from \"../Node\";\n\nexport class PathNode extends JsiDrawingNode<PathProps, SkPath> {\n constructor(ctx: NodeContext, props: PathProps) {\n super(ctx, NodeType.Path, props);\n }\n\n protected deriveProps() {\n const {\n start: trimStart,\n end: trimEnd,\n fillType,\n stroke,\n ...pathProps\n } = this.props;\n const start = saturate(trimStart);\n const end = saturate(trimEnd);\n const hasStartOffset = start !== 0;\n const hasEndOffset = end !== 1;\n const hasStrokeOptions = stroke !== undefined;\n const hasFillType = !!fillType;\n const willMutatePath =\n hasStartOffset || hasEndOffset || hasStrokeOptions || hasFillType;\n const pristinePath = processPath(this.Skia, pathProps.path);\n const path = willMutatePath ? pristinePath.copy() : pristinePath;\n if (hasFillType) {\n path.setFillType(FillType[enumKey(fillType)]);\n }\n if (hasStrokeOptions) {\n path.stroke(stroke);\n }\n if (hasStartOffset || hasEndOffset) {\n path.trim(start, end, false);\n }\n return path;\n }\n\n draw({ canvas, paint }: DrawingContext) {\n if (!this.derived) {\n throw new Error(\"Path not initialized\");\n }\n canvas.drawPath(this.derived, paint);\n }\n}\n"],"mappings":"AAAA,SAASA,QAAT,QAAyB,mCAAzB;AACA,SAASC,QAAT,QAAyB,qBAAzB;AAGA,SAASC,QAAT,QAAyB,aAAzB;AACA,SAASC,OAAT,EAAkBC,WAAlB,QAAqC,cAArC;AACA,SAASC,cAAT,QAA+B,gBAA/B;AAGA,OAAO,MAAMC,QAAN,SAAuBD,cAAvB,CAAyD;EAC9DE,WAAW,CAACC,GAAD,EAAmBC,KAAnB,EAAqC;IAC9C,MAAMD,GAAN,EAAWN,QAAQ,CAACQ,IAApB,EAA0BD,KAA1B;EACD;;EAESE,WAAW,GAAG;IACtB,MAAM;MACJC,KAAK,EAAEC,SADH;MAEJC,GAAG,EAAEC,OAFD;MAGJC,QAHI;MAIJC,MAJI;MAKJ,GAAGC;IALC,IAMF,KAAKT,KANT;IAOA,MAAMG,KAAK,GAAGZ,QAAQ,CAACa,SAAD,CAAtB;IACA,MAAMC,GAAG,GAAGd,QAAQ,CAACe,OAAD,CAApB;IACA,MAAMI,cAAc,GAAGP,KAAK,KAAK,CAAjC;IACA,MAAMQ,YAAY,GAAGN,GAAG,KAAK,CAA7B;IACA,MAAMO,gBAAgB,GAAGJ,MAAM,KAAKK,SAApC;IACA,MAAMC,WAAW,GAAG,CAAC,CAACP,QAAtB;IACA,MAAMQ,cAAc,GAClBL,cAAc,IAAIC,YAAlB,IAAkCC,gBAAlC,IAAsDE,WADxD;IAEA,MAAME,YAAY,GAAGrB,WAAW,CAAC,KAAKsB,IAAN,EAAYR,SAAS,CAACS,IAAtB,CAAhC;IACA,MAAMA,IAAI,GAAGH,cAAc,GAAGC,YAAY,CAACG,IAAb,EAAH,GAAyBH,YAApD;;IACA,IAAIF,WAAJ,EAAiB;MACfI,IAAI,CAACE,WAAL,CAAiB5B,QAAQ,CAACE,OAAO,CAACa,QAAD,CAAR,CAAzB;IACD;;IACD,IAAIK,gBAAJ,EAAsB;MACpBM,IAAI,CAACV,MAAL,CAAYA,MAAZ;IACD;;IACD,IAAIE,cAAc,IAAIC,YAAtB,EAAoC;MAClCO,IAAI,CAACG,IAAL,CAAUlB,KAAV,EAAiBE,GAAjB,EAAsB,KAAtB;IACD;;IACD,OAAOa,IAAP;EACD;;EAEDI,IAAI,OAAoC;IAAA,IAAnC;MAAEC,MAAF;MAAUC;IAAV,CAAmC;;IACtC,IAAI,CAAC,KAAKC,OAAV,EAAmB;MACjB,MAAM,IAAIC,KAAJ,CAAU,sBAAV,CAAN;IACD;;IACDH,MAAM,CAACI,QAAP,CAAgB,KAAKF,OAArB,EAA8BD,KAA9B;EACD;;AAxC6D"}
@@ -50,9 +50,14 @@ export interface VerticesProps extends DrawingNodeProps {
50
50
  blendMode?: SkEnum<typeof BlendMode>;
51
51
  indices?: number[];
52
52
  }
53
- export declare type ImageSVGProps = RectDef & {
53
+ export interface ImageSVGProps extends DrawingNodeProps {
54
54
  svg: SkSVG | null;
55
- } & DrawingNodeProps;
55
+ x?: number;
56
+ y?: number;
57
+ width?: number;
58
+ height?: number;
59
+ rect?: SkRect;
60
+ }
56
61
  export interface PictureProps extends DrawingNodeProps {
57
62
  picture: SkPicture;
58
63
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["Drawings.ts"],"sourcesContent":["import type {\n FillType,\n SkImage,\n StrokeOpts,\n Vector,\n Color,\n SkPoint,\n BlendMode,\n PointMode,\n VertexMode,\n SkFont,\n SkRRect,\n SkTextBlob,\n SkPicture,\n SkSVG,\n SkPaint,\n SkRect,\n} from \"../../skia/types\";\n\nimport type {\n CircleDef,\n Fit,\n GroupProps,\n PathDef,\n RectDef,\n RRectDef,\n SkEnum,\n} from \"./Common\";\nimport type { DrawingContext } from \"./DrawingContext\";\n\nexport interface DrawingNodeProps extends GroupProps {\n paint?: SkPaint;\n}\n\nexport type ImageProps = DrawingNodeProps &\n RectDef & {\n fit?: Fit;\n image: SkImage | null;\n };\n\nexport type CircleProps = CircleDef & DrawingNodeProps;\n\nexport interface PathProps extends DrawingNodeProps {\n path: PathDef;\n start: number;\n end: number;\n stroke?: StrokeOpts;\n fillType?: SkEnum<typeof FillType>;\n}\n\nexport interface CustomDrawingNodeProps extends DrawingNodeProps {\n drawing: (ctx: DrawingContext) => void;\n}\n\nexport interface LineProps extends DrawingNodeProps {\n p1: Vector;\n p2: Vector;\n}\n\nexport type OvalProps = RectDef & DrawingNodeProps;\n\nexport type RectProps = RectDef & DrawingNodeProps;\n\nexport type RoundedRectProps = RRectDef & DrawingNodeProps;\n\nexport interface CubicBezierHandle {\n pos: Vector;\n c1: Vector;\n c2: Vector;\n}\n\nexport interface PatchProps extends DrawingNodeProps {\n colors?: Color[];\n patch: [\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle\n ];\n texture?: readonly [SkPoint, SkPoint, SkPoint, SkPoint];\n blendMode?: SkEnum<typeof BlendMode>;\n}\n\nexport interface VerticesProps extends DrawingNodeProps {\n colors?: string[];\n vertices: SkPoint[];\n textures?: SkPoint[];\n mode: SkEnum<typeof VertexMode>;\n blendMode?: SkEnum<typeof BlendMode>;\n indices?: number[];\n}\n\nexport type ImageSVGProps = RectDef & {\n svg: SkSVG | null;\n} & DrawingNodeProps;\n\nexport interface PictureProps extends DrawingNodeProps {\n picture: SkPicture;\n}\n\nexport interface PointsProps extends DrawingNodeProps {\n points: SkPoint[];\n mode: SkEnum<typeof PointMode>;\n}\n\nexport interface DiffRectProps extends DrawingNodeProps {\n inner: SkRRect;\n outer: SkRRect;\n}\n\nexport interface TextProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n x: number;\n y: number;\n}\n\nexport interface TextPathProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n path: PathDef;\n initialOffset: number;\n}\n\nexport interface TextBlobProps extends DrawingNodeProps {\n blob: SkTextBlob;\n x: number;\n y: number;\n}\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport interface GlyphsProps extends DrawingNodeProps {\n font: SkFont | null;\n x: number;\n y: number;\n glyphs: Glyph[];\n}\n\nexport interface BoxProps extends DrawingNodeProps {\n box: SkRRect | SkRect;\n}\n\nexport interface BoxShadowProps {\n dx?: number;\n dy?: number;\n spread?: number;\n blur: number;\n color?: Color;\n inner?: boolean;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["Drawings.ts"],"sourcesContent":["import type {\n FillType,\n SkImage,\n StrokeOpts,\n Vector,\n Color,\n SkPoint,\n BlendMode,\n PointMode,\n VertexMode,\n SkFont,\n SkRRect,\n SkTextBlob,\n SkPicture,\n SkSVG,\n SkPaint,\n SkRect,\n} from \"../../skia/types\";\n\nimport type {\n CircleDef,\n Fit,\n GroupProps,\n PathDef,\n RectDef,\n RRectDef,\n SkEnum,\n} from \"./Common\";\nimport type { DrawingContext } from \"./DrawingContext\";\n\nexport interface DrawingNodeProps extends GroupProps {\n paint?: SkPaint;\n}\n\nexport type ImageProps = DrawingNodeProps &\n RectDef & {\n fit?: Fit;\n image: SkImage | null;\n };\n\nexport type CircleProps = CircleDef & DrawingNodeProps;\n\nexport interface PathProps extends DrawingNodeProps {\n path: PathDef;\n start: number;\n end: number;\n stroke?: StrokeOpts;\n fillType?: SkEnum<typeof FillType>;\n}\n\nexport interface CustomDrawingNodeProps extends DrawingNodeProps {\n drawing: (ctx: DrawingContext) => void;\n}\n\nexport interface LineProps extends DrawingNodeProps {\n p1: Vector;\n p2: Vector;\n}\n\nexport type OvalProps = RectDef & DrawingNodeProps;\n\nexport type RectProps = RectDef & DrawingNodeProps;\n\nexport type RoundedRectProps = RRectDef & DrawingNodeProps;\n\nexport interface CubicBezierHandle {\n pos: Vector;\n c1: Vector;\n c2: Vector;\n}\n\nexport interface PatchProps extends DrawingNodeProps {\n colors?: Color[];\n patch: [\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle\n ];\n texture?: readonly [SkPoint, SkPoint, SkPoint, SkPoint];\n blendMode?: SkEnum<typeof BlendMode>;\n}\n\nexport interface VerticesProps extends DrawingNodeProps {\n colors?: string[];\n vertices: SkPoint[];\n textures?: SkPoint[];\n mode: SkEnum<typeof VertexMode>;\n blendMode?: SkEnum<typeof BlendMode>;\n indices?: number[];\n}\n\nexport interface ImageSVGProps extends DrawingNodeProps {\n svg: SkSVG | null;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n rect?: SkRect;\n}\n\nexport interface PictureProps extends DrawingNodeProps {\n picture: SkPicture;\n}\n\nexport interface PointsProps extends DrawingNodeProps {\n points: SkPoint[];\n mode: SkEnum<typeof PointMode>;\n}\n\nexport interface DiffRectProps extends DrawingNodeProps {\n inner: SkRRect;\n outer: SkRRect;\n}\n\nexport interface TextProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n x: number;\n y: number;\n}\n\nexport interface TextPathProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n path: PathDef;\n initialOffset: number;\n}\n\nexport interface TextBlobProps extends DrawingNodeProps {\n blob: SkTextBlob;\n x: number;\n y: number;\n}\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport interface GlyphsProps extends DrawingNodeProps {\n font: SkFont | null;\n x: number;\n y: number;\n glyphs: Glyph[];\n}\n\nexport interface BoxProps extends DrawingNodeProps {\n box: SkRRect | SkRect;\n}\n\nexport interface BoxShadowProps {\n dx?: number;\n dy?: number;\n spread?: number;\n blur: number;\n color?: Color;\n inner?: boolean;\n}\n"],"mappings":""}
@@ -13,3 +13,4 @@ export declare const mix: (value: number, x: number, y: number) => number;
13
13
  clamp(101, 0, 100); // 100
14
14
  */
15
15
  export declare const clamp: (value: number, lowerBound: number, upperBound: number) => number;
16
+ export declare const saturate: (value: number) => number;
@@ -22,4 +22,9 @@ export const clamp = (value, lowerBound, upperBound) => {
22
22
 
23
23
  return Math.min(Math.max(lowerBound, value), upperBound);
24
24
  };
25
+ export const saturate = value => {
26
+ "worklet";
27
+
28
+ return clamp(value, 0, 1);
29
+ };
25
30
  //# sourceMappingURL=Math.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["mix","value","x","y","clamp","lowerBound","upperBound","Math","min","max"],"sources":["Math.ts"],"sourcesContent":["/**\n * Linear interpolation\n * @param value\n * @param x\n * @param y\n */\nexport const mix = (value: number, x: number, y: number) => {\n \"worklet\";\n return x * (1 - value) + y * value;\n};\n\n/**\n * @summary Clamps a node with a lower and upper bound.\n * @example\n clamp(-1, 0, 100); // 0\n clamp(1, 0, 100); // 1\n clamp(101, 0, 100); // 100\n */\nexport const clamp = (\n value: number,\n lowerBound: number,\n upperBound: number\n) => {\n \"worklet\";\n return Math.min(Math.max(lowerBound, value), upperBound);\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,GAAG,GAAG,CAACC,KAAD,EAAgBC,CAAhB,EAA2BC,CAA3B,KAAyC;EAC1D;;EACA,OAAOD,CAAC,IAAI,IAAID,KAAR,CAAD,GAAkBE,CAAC,GAAGF,KAA7B;AACD,CAHM;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,KAAK,GAAG,CACnBH,KADmB,EAEnBI,UAFmB,EAGnBC,UAHmB,KAIhB;EACH;;EACA,OAAOC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,GAAL,CAASJ,UAAT,EAAqBJ,KAArB,CAAT,EAAsCK,UAAtC,CAAP;AACD,CAPM"}
1
+ {"version":3,"names":["mix","value","x","y","clamp","lowerBound","upperBound","Math","min","max","saturate"],"sources":["Math.ts"],"sourcesContent":["/**\n * Linear interpolation\n * @param value\n * @param x\n * @param y\n */\nexport const mix = (value: number, x: number, y: number) => {\n \"worklet\";\n return x * (1 - value) + y * value;\n};\n\n/**\n * @summary Clamps a node with a lower and upper bound.\n * @example\n clamp(-1, 0, 100); // 0\n clamp(1, 0, 100); // 1\n clamp(101, 0, 100); // 100\n */\nexport const clamp = (\n value: number,\n lowerBound: number,\n upperBound: number\n) => {\n \"worklet\";\n return Math.min(Math.max(lowerBound, value), upperBound);\n};\n\nexport const saturate = (value: number) => {\n \"worklet\";\n return clamp(value, 0, 1);\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,GAAG,GAAG,CAACC,KAAD,EAAgBC,CAAhB,EAA2BC,CAA3B,KAAyC;EAC1D;;EACA,OAAOD,CAAC,IAAI,IAAID,KAAR,CAAD,GAAkBE,CAAC,GAAGF,KAA7B;AACD,CAHM;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,KAAK,GAAG,CACnBH,KADmB,EAEnBI,UAFmB,EAGnBC,UAHmB,KAIhB;EACH;;EACA,OAAOC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,GAAL,CAASJ,UAAT,EAAqBJ,KAArB,CAAT,EAAsCK,UAAtC,CAAP;AACD,CAPM;AASP,OAAO,MAAMI,QAAQ,GAAIT,KAAD,IAAmB;EACzC;;EACA,OAAOG,KAAK,CAACH,KAAD,EAAQ,CAAR,EAAW,CAAX,CAAZ;AACD,CAHM"}
@@ -1,8 +1,8 @@
1
- import { NativeModules, Platform } from "react-native";
1
+ import { Platform } from "../Platform";
2
2
 
3
3
  if (Platform.OS !== "web" && global.SkiaApi == null) {
4
4
  // Initialize RN Skia
5
- const SkiaModule = NativeModules.RNSkia;
5
+ const SkiaModule = Platform.NativeModules.RNSkia;
6
6
 
7
7
  if (SkiaModule == null || typeof SkiaModule.install !== "function") {
8
8
  throw new Error("Native RNSkia Module cannot be found! Make sure you correctly " + "installed native dependencies and rebuilt your app.");
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","Platform","OS","global","SkiaApi","SkiaModule","RNSkia","install","Error","result"],"sources":["NativeSetup.ts"],"sourcesContent":["import { NativeModules, Platform } from \"react-native\";\n\nif (Platform.OS !== \"web\" && global.SkiaApi == null) {\n // Initialize RN Skia\n const SkiaModule = NativeModules.RNSkia;\n if (SkiaModule == null || typeof SkiaModule.install !== \"function\") {\n throw new Error(\n \"Native RNSkia Module cannot be found! Make sure you correctly \" +\n \"installed native dependencies and rebuilt your app.\"\n );\n }\n const result = SkiaModule.install();\n if (result !== true) {\n throw new Error(\n `Native Skia Module failed to correctly install JSI Bindings! Result: ${result}`\n );\n }\n}\n"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,QAAxB,QAAwC,cAAxC;;AAEA,IAAIA,QAAQ,CAACC,EAAT,KAAgB,KAAhB,IAAyBC,MAAM,CAACC,OAAP,IAAkB,IAA/C,EAAqD;EACnD;EACA,MAAMC,UAAU,GAAGL,aAAa,CAACM,MAAjC;;EACA,IAAID,UAAU,IAAI,IAAd,IAAsB,OAAOA,UAAU,CAACE,OAAlB,KAA8B,UAAxD,EAAoE;IAClE,MAAM,IAAIC,KAAJ,CACJ,mEACE,qDAFE,CAAN;EAID;;EACD,MAAMC,MAAM,GAAGJ,UAAU,CAACE,OAAX,EAAf;;EACA,IAAIE,MAAM,KAAK,IAAf,EAAqB;IACnB,MAAM,IAAID,KAAJ,CACH,wEAAuEC,MAAO,EAD3E,CAAN;EAGD;AACF"}
1
+ {"version":3,"names":["Platform","OS","global","SkiaApi","SkiaModule","NativeModules","RNSkia","install","Error","result"],"sources":["NativeSetup.ts"],"sourcesContent":["import { Platform } from \"../Platform\";\n\nif (Platform.OS !== \"web\" && global.SkiaApi == null) {\n // Initialize RN Skia\n const SkiaModule = Platform.NativeModules.RNSkia;\n if (SkiaModule == null || typeof SkiaModule.install !== \"function\") {\n throw new Error(\n \"Native RNSkia Module cannot be found! Make sure you correctly \" +\n \"installed native dependencies and rebuilt your app.\"\n );\n }\n const result = SkiaModule.install();\n if (result !== true) {\n throw new Error(\n `Native Skia Module failed to correctly install JSI Bindings! Result: ${result}`\n );\n }\n}\n"],"mappings":"AAAA,SAASA,QAAT,QAAyB,aAAzB;;AAEA,IAAIA,QAAQ,CAACC,EAAT,KAAgB,KAAhB,IAAyBC,MAAM,CAACC,OAAP,IAAkB,IAA/C,EAAqD;EACnD;EACA,MAAMC,UAAU,GAAGJ,QAAQ,CAACK,aAAT,CAAuBC,MAA1C;;EACA,IAAIF,UAAU,IAAI,IAAd,IAAsB,OAAOA,UAAU,CAACG,OAAlB,KAA8B,UAAxD,EAAoE;IAClE,MAAM,IAAIC,KAAJ,CACJ,mEACE,qDAFE,CAAN;EAID;;EACD,MAAMC,MAAM,GAAGL,UAAU,CAACG,OAAX,EAAf;;EACA,IAAIE,MAAM,KAAK,IAAf,EAAqB;IACnB,MAAM,IAAID,KAAJ,CACH,wEAAuEC,MAAO,EAD3E,CAAN;EAGD;AACF"}
@@ -1,11 +1,6 @@
1
1
  import { useEffect, useRef, useState } from "react";
2
- import { Image } from "react-native";
3
2
  import { Skia } from "../Skia";
4
- import { isRNModule } from "../types";
5
-
6
- const resolveAsset = source => {
7
- return isRNModule(source) ? Image.resolveAssetSource(source).uri : source.default;
8
- };
3
+ import { Platform } from "../../Platform";
9
4
 
10
5
  const factoryWrapper = (data2, factory, onError) => {
11
6
  const factoryResult = factory(data2);
@@ -24,7 +19,7 @@ const loadData = (source, factory, onError) => {
24
19
  } else if (source instanceof Uint8Array) {
25
20
  return new Promise(resolve => resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError)));
26
21
  } else {
27
- const uri = typeof source === "string" ? source : resolveAsset(source);
22
+ const uri = typeof source === "string" ? source : Platform.resolveAsset(source);
28
23
  return Skia.Data.fromURI(uri).then(d => factoryWrapper(d, factory, onError));
29
24
  }
30
25
  };
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","useState","Image","Skia","isRNModule","resolveAsset","source","resolveAssetSource","uri","default","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","undefined","Promise","resolve","Uint8Array","Data","fromBytes","fromURI","then","d","useLoading","loader","mounted","data","setData","dataRef","current","value","dispose","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { Image } from \"react-native\";\n\nimport { Skia } from \"../Skia\";\nimport { isRNModule } from \"../types\";\nimport type {\n SkData,\n DataModule,\n DataSourceParam,\n JsiDisposable,\n} from \"../types\";\n\nconst resolveAsset = (source: DataModule) => {\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : source.default;\n};\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri = typeof source === \"string\" ? source : resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T extends JsiDisposable>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n const dataRef = useRef<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n return () => {\n dataRef.current?.dispose();\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T extends JsiDisposable>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData<T>(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,OAA5C;AACA,SAASC,KAAT,QAAsB,cAAtB;AAEA,SAASC,IAAT,QAAqB,SAArB;AACA,SAASC,UAAT,QAA2B,UAA3B;;AAQA,MAAMC,YAAY,GAAIC,MAAD,IAAwB;EAC3C,OAAOF,UAAU,CAACE,MAAD,CAAV,GACHJ,KAAK,CAACK,kBAAN,CAAyBD,MAAzB,EAAiCE,GAD9B,GAEHF,MAAM,CAACG,OAFX;AAGD,CAJD;;AAMA,MAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;EACH,MAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;EACA,IAAIG,aAAa,KAAK,IAAtB,EAA4B;IAC1BD,OAAO,IAAIA,OAAO,CAAC,IAAIE,KAAJ,CAAU,qBAAV,CAAD,CAAlB;IACA,OAAO,IAAP;EACD,CAHD,MAGO;IACL,OAAOD,aAAP;EACD;AACF,CAZD;;AAcA,MAAME,QAAQ,GAAG,CACfV,MADe,EAEfM,OAFe,EAGfC,OAHe,KAIO;EACtB,IAAIP,MAAM,KAAK,IAAX,IAAmBA,MAAM,KAAKW,SAAlC,EAA6C;IAC3C,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAaA,OAAO,CAAC,IAAD,CAAhC,CAAP;EACD,CAFD,MAEO,IAAIb,MAAM,YAAYc,UAAtB,EAAkC;IACvC,OAAO,IAAIF,OAAJ,CAAaC,OAAD,IACjBA,OAAO,CAACT,cAAc,CAACP,IAAI,CAACkB,IAAL,C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AAvB,CAJR;;AAMP,MAAMuB,QAAQ,GAAIP,IAAD,IAAkBA,IAAnC;;AAEA,OAAO,MAAMQ,OAAO,GAAG,CACrB/B,MADqB,EAErBO,OAFqB,KAGlBsB,UAAU,CAAC7B,MAAD,EAAS8B,QAAT,EAAmBvB,OAAnB,CAHR"}
1
+ {"version":3,"names":["useEffect","useRef","useState","Skia","Platform","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Data","fromBytes","uri","resolveAsset","fromURI","then","d","useLoading","loader","mounted","data","setData","dataRef","current","value","dispose","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam, JsiDisposable } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri =\n typeof source === \"string\" ? source : Platform.resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T extends JsiDisposable>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n const dataRef = useRef<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n return () => {\n dataRef.current?.dispose();\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T extends JsiDisposable>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData<T>(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,OAA5C;AAEA,SAASC,IAAT,QAAqB,SAArB;AAEA,SAASC,QAAT,QAAyB,gBAAzB;;AAEA,MAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;EACH,MAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;EACA,IAAIG,aAAa,KAAK,IAAtB,EAA4B;IAC1BD,OAAO,IAAIA,OAAO,CAAC,IAAIE,KAAJ,CAAU,qBAAV,CAAD,CAAlB;IACA,OAAO,IAAP;EACD,CAHD,MAGO;IACL,OAAOD,aAAP;EACD;AACF,CAZD;;AAcA,MAAME,QAAQ,GAAG,CACfC,MADe,EAEfL,OAFe,EAGfC,OAHe,KAIO;EACtB,IAAII,MAAM,KAAK,IAAX,IAAmBA,MAAM,KAAKC,SAAlC,EAA6C;IAC3C,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAaA,OAAO,CAAC,IAAD,CAAhC,CAAP;EACD,CAFD,MAEO,IAAIH,MAAM,YAAYI,UAAtB,EAAkC;IACvC,OAAO,IAAIF,OAAJ,CAAaC,OAAD,IACjBA,OAAO,CAACV,cAAc,CAACF,IAAI,CAACc,IAAL,CAAUC,SAAV,CAAoBN,MAApB,CAAD,EAA8BL,OAA9B,EAAuCC,OAAvC,CAAf,CADF,CAAP;EAGD,CAJM,MAIA;IACL,MAAMW,GAAG,GACP,OAAOP,MAAP,KAAkB,QAAlB,GAA6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AU,CAACrB,MAAD,EAASsB,QAAT,EAAmB1B,OAAnB,CAHR"}
@@ -1,4 +1,4 @@
1
- import { findNodeHandle, Platform } from "react-native";
1
+ import { Platform } from "../../Platform";
2
2
  import { Skia } from "../Skia";
3
3
  import { useRawData } from "./Data";
4
4
  const imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);
@@ -30,7 +30,7 @@ export const makeImageFromView = function (viewRef) {
30
30
  }
31
31
  }
32
32
 
33
- const viewTag = findNodeHandle(viewRef.current);
33
+ const viewTag = Platform.findNodeHandle(viewRef.current);
34
34
 
35
35
  if (viewTag !== null && viewTag !== 0) {
36
36
  return Skia.Image.MakeImageFromViewTag(viewTag);
@@ -1 +1 @@
1
- {"version":3,"names":["findNodeHandle","Platform","Skia","useRawData","imgFactory","Image","MakeImageFromEncoded","bind","useImage","source","onError","makeImageFromView","viewRef","callback","OS","Promise","reject","Error","viewTag","current","MakeImageFromViewTag"],"sources":["Image.ts"],"sourcesContent":["import { findNodeHandle, Platform } from \"react-native\";\n\nimport { Skia } from \"../Skia\";\nimport type { DataSourceParam, SkImage } from \"../types\";\n\nimport { useRawData } from \"./Data\";\n\nconst imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);\n\n/**\n * Returns a Skia Image object\n * */\nexport const useImage = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, imgFactory, onError);\n\n/**\n * Creates an image from a given view reference. NOTE: This method has different implementations\n * on web/native. On web, the callback is called with the view ref and the callback is expected to\n * return a promise that resolves to a Skia Image object. On native, the view ref is used to\n * find the view tag and the Skia Image object is created from the view tag. This means that on web\n * you will need to implement the logic to create the image from the view ref yourself.\n * @param viewRef Ref to the view we're creating an image from\n * @returns A promise that resolves to a Skia Image object or rejects\n * with an error id the view tag is invalid.\n */\nexport const makeImageFromView = <\n T extends\n | number\n | React.Component<unknown, unknown>\n | React.ComponentClass<unknown>\n>(\n viewRef: React.RefObject<T>,\n callback:\n | null\n | ((viewRef: React.RefObject<T>) => Promise<SkImage | null>) = null\n) => {\n // In web implementation we just delegate the work to the provided callback\n if (Platform.OS === \"web\") {\n if (callback) {\n return callback(viewRef);\n } else {\n Promise.reject(\n new Error(\n \"Callback is required on web in the makeImageFromView function.\"\n )\n );\n }\n }\n const viewTag = findNodeHandle(viewRef.current);\n if (viewTag !== null && viewTag !== 0) {\n return Skia.Image.MakeImageFromViewTag(viewTag);\n }\n return Promise.reject(new Error(\"Invalid view tag\"));\n};\n"],"mappings":"AAAA,SAASA,cAAT,EAAyBC,QAAzB,QAAyC,cAAzC;AAEA,SAASC,IAAT,QAAqB,SAArB;AAGA,SAASC,UAAT,QAA2B,QAA3B;AAEA,MAAMC,UAAU,GAAGF,IAAI,CAACG,KAAL,CAAWC,oBAAX,CAAgCC,IAAhC,CAAqCL,IAAI,CAACG,KAA1C,CAAnB;AAEA;AACA;AACA;;AACA,OAAO,MAAMG,QAAQ,GAAG,CACtBC,MADsB,EAEtBC,OAFsB,KAGnBP,UAAU,CAACM,MAAD,EAASL,UAAT,EAAqBM,OAArB,CAHR;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,iBAAiB,GAAG,UAM/BC,OAN+B,EAU5B;EAAA,IAHHC,QAGG,uEAD8D,IAC9D;;EACH;EACA,IAAIZ,QAAQ,CAACa,EAAT,KAAgB,KAApB,EAA2B;IACzB,IAAID,QAAJ,EAAc;MACZ,OAAOA,QAAQ,CAACD,OAAD,CAAf;IACD,CAFD,MAEO;MACLG,OAAO,CAACC,MAAR,CACE,IAAIC,KAAJ,CACE,gEADF,CADF;IAKD;EACF;;EACD,MAAMC,OAAO,GAAGlB,cAAc,CAACY,OAAO,CAACO,OAAT,CAA9B;;EACA,IAAID,OAAO,KAAK,IAAZ,IAAoBA,OAAO,KAAK,CAApC,EAAuC;IACrC,OAAOhB,IAAI,CAACG,KAAL,CAAWe,oBAAX,CAAgCF,OAAhC,CAAP;EACD;;EACD,OAAOH,OAAO,CAACC,MAAR,CAAe,IAAIC,KAAJ,CAAU,kBAAV,CAAf,CAAP;AACD,CA5BM"}
1
+ {"version":3,"names":["Platform","Skia","useRawData","imgFactory","Image","MakeImageFromEncoded","bind","useImage","source","onError","makeImageFromView","viewRef","callback","OS","Promise","reject","Error","viewTag","findNodeHandle","current","MakeImageFromViewTag"],"sources":["Image.ts"],"sourcesContent":["import { Platform } from \"../../Platform\";\nimport { Skia } from \"../Skia\";\nimport type { DataSourceParam, SkImage } from \"../types\";\n\nimport { useRawData } from \"./Data\";\n\nconst imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);\n\n/**\n * Returns a Skia Image object\n * */\nexport const useImage = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, imgFactory, onError);\n\n/**\n * Creates an image from a given view reference. NOTE: This method has different implementations\n * on web/native. On web, the callback is called with the view ref and the callback is expected to\n * return a promise that resolves to a Skia Image object. On native, the view ref is used to\n * find the view tag and the Skia Image object is created from the view tag. This means that on web\n * you will need to implement the logic to create the image from the view ref yourself.\n * @param viewRef Ref to the view we're creating an image from\n * @returns A promise that resolves to a Skia Image object or rejects\n * with an error id the view tag is invalid.\n */\nexport const makeImageFromView = <\n T extends\n | number\n | React.Component<unknown, unknown>\n | React.ComponentClass<unknown>\n>(\n viewRef: React.RefObject<T>,\n callback:\n | null\n | ((viewRef: React.RefObject<T>) => Promise<SkImage | null>) = null\n) => {\n // In web implementation we just delegate the work to the provided callback\n if (Platform.OS === \"web\") {\n if (callback) {\n return callback(viewRef);\n } else {\n Promise.reject(\n new Error(\n \"Callback is required on web in the makeImageFromView function.\"\n )\n );\n }\n }\n const viewTag = Platform.findNodeHandle(viewRef.current);\n if (viewTag !== null && viewTag !== 0) {\n return Skia.Image.MakeImageFromViewTag(viewTag);\n }\n return Promise.reject(new Error(\"Invalid view tag\"));\n};\n"],"mappings":"AAAA,SAASA,QAAT,QAAyB,gBAAzB;AACA,SAASC,IAAT,QAAqB,SAArB;AAGA,SAASC,UAAT,QAA2B,QAA3B;AAEA,MAAMC,UAAU,GAAGF,IAAI,CAACG,KAAL,CAAWC,oBAAX,CAAgCC,IAAhC,CAAqCL,IAAI,CAACG,KAA1C,CAAnB;AAEA;AACA;AACA;;AACA,OAAO,MAAMG,QAAQ,GAAG,CACtBC,MADsB,EAEtBC,OAFsB,KAGnBP,UAAU,CAACM,MAAD,EAASL,UAAT,EAAqBM,OAArB,CAHR;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,iBAAiB,GAAG,UAM/BC,OAN+B,EAU5B;EAAA,IAHHC,QAGG,uEAD8D,IAC9D;;EACH;EACA,IAAIZ,QAAQ,CAACa,EAAT,KAAgB,KAApB,EAA2B;IACzB,IAAID,QAAJ,EAAc;MACZ,OAAOA,QAAQ,CAACD,OAAD,CAAf;IACD,CAFD,MAEO;MACLG,OAAO,CAACC,MAAR,CACE,IAAIC,KAAJ,CACE,gEADF,CADF;IAKD;EACF;;EACD,MAAMC,OAAO,GAAGjB,QAAQ,CAACkB,cAAT,CAAwBP,OAAO,CAACQ,OAAhC,CAAhB;;EACA,IAAIF,OAAO,KAAK,IAAZ,IAAoBA,OAAO,KAAK,CAApC,EAAuC;IACrC,OAAOhB,IAAI,CAACG,KAAL,CAAWgB,oBAAX,CAAgCH,OAAhC,CAAP;EACD;;EACD,OAAOH,OAAO,CAACC,MAAR,CAAe,IAAIC,KAAJ,CAAU,kBAAV,CAAf,CAAP;AACD,CA5BM"}
@@ -17,7 +17,7 @@ export declare abstract class SkiaBaseWebView<TProps extends SkiaBaseViewProps>
17
17
  protected width: number;
18
18
  protected height: number;
19
19
  private unsubscribeAll;
20
- private onLayout;
20
+ private onLayoutEvent;
21
21
  protected getSize(): {
22
22
  width: number;
23
23
  height: number;
@@ -58,5 +58,10 @@ export declare abstract class SkiaBaseWebView<TProps extends SkiaBaseViewProps>
58
58
  registerValues(_values: SkiaValue<unknown>[]): void;
59
59
  private handleTouchEvent;
60
60
  createTouchHandler(touchType: TouchType): (evt: PointerEvent) => void;
61
+ private onStart;
62
+ private onActive;
63
+ private onCancel;
64
+ private onEnd;
65
+ private onLayout;
61
66
  render(): JSX.Element;
62
67
  }
@@ -4,10 +4,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
4
4
 
5
5
  /* global HTMLCanvasElement */
6
6
  import React from "react";
7
- import { PixelRatio, View } from "react-native";
8
7
  import { JsiSkSurface } from "../skia/web/JsiSkSurface";
8
+ import { Platform } from "../Platform";
9
9
  import { TouchType } from "./types";
10
- const pd = PixelRatio.get();
10
+ const pd = Platform.PixelRatio;
11
11
  export class SkiaBaseWebView extends React.Component {
12
12
  constructor(props) {
13
13
  var _props$mode;
@@ -34,6 +34,16 @@ export class SkiaBaseWebView extends React.Component {
34
34
 
35
35
  _defineProperty(this, "height", 0);
36
36
 
37
+ _defineProperty(this, "onStart", this.createTouchHandler(TouchType.Start));
38
+
39
+ _defineProperty(this, "onActive", this.createTouchHandler(TouchType.Active));
40
+
41
+ _defineProperty(this, "onCancel", this.createTouchHandler(TouchType.Cancelled));
42
+
43
+ _defineProperty(this, "onEnd", this.createTouchHandler(TouchType.End));
44
+
45
+ _defineProperty(this, "onLayout", this.onLayoutEvent.bind(this));
46
+
37
47
  this._mode = (_props$mode = props.mode) !== null && _props$mode !== void 0 ? _props$mode : "default";
38
48
  }
39
49
 
@@ -43,22 +53,19 @@ export class SkiaBaseWebView extends React.Component {
43
53
  this._unsubscriptions = [];
44
54
  }
45
55
 
46
- onLayout(evt) {
56
+ onLayoutEvent(evt) {
47
57
  const {
48
58
  CanvasKit
49
- } = global;
50
- const {
51
- width,
52
- height
53
- } = evt.nativeEvent.layout;
54
- this.width = width;
55
- this.height = height; // Reset canvas / surface on layout change
56
-
57
- if (this._canvasRef.current) {
58
- const canvas = this._canvasRef.current;
59
- canvas.width = width * pd;
60
- canvas.height = height * pd;
61
- const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);
59
+ } = global; // Reset canvas / surface on layout change
60
+
61
+ const canvas = this._canvasRef.current;
62
+
63
+ if (canvas) {
64
+ this.width = canvas.clientWidth;
65
+ this.height = canvas.clientHeight;
66
+ canvas.width = this.width * pd;
67
+ canvas.height = this.height * pd;
68
+ const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);
62
69
 
63
70
  if (!surface) {
64
71
  throw new Error("Could not create surface");
@@ -92,12 +99,17 @@ export class SkiaBaseWebView extends React.Component {
92
99
  }
93
100
 
94
101
  componentWillUnmount() {
95
- var _this$_canvasRef$curr, _this$_canvasRef$curr2, _this$_canvasRef$curr3;
96
-
97
102
  this.unsubscribeAll();
98
- cancelAnimationFrame(this.requestId); // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context
103
+ cancelAnimationFrame(this.requestId); // eslint-disable-next-line max-len
104
+ // https://stackoverflow.com/questions/23598471/how-do-i-clean-up-and-unload-a-webgl-canvas-context-from-gpu-after-use
105
+ // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context
106
+ // We delete the context, only if the context has been intialized
99
107
 
100
- (_this$_canvasRef$curr = this._canvasRef.current) === null || _this$_canvasRef$curr === void 0 ? void 0 : (_this$_canvasRef$curr2 = _this$_canvasRef$curr.getContext("webgl2")) === null || _this$_canvasRef$curr2 === void 0 ? void 0 : (_this$_canvasRef$curr3 = _this$_canvasRef$curr2.getExtension("WEBGL_lose_context")) === null || _this$_canvasRef$curr3 === void 0 ? void 0 : _this$_canvasRef$curr3.loseContext();
108
+ if (this._surface) {
109
+ var _this$_canvasRef$curr, _this$_canvasRef$curr2, _this$_canvasRef$curr3;
110
+
111
+ (_this$_canvasRef$curr = this._canvasRef.current) === null || _this$_canvasRef$curr === void 0 ? void 0 : (_this$_canvasRef$curr2 = _this$_canvasRef$curr.getContext("webgl2")) === null || _this$_canvasRef$curr2 === void 0 ? void 0 : (_this$_canvasRef$curr3 = _this$_canvasRef$curr2.getExtension("WEBGL_lose_context")) === null || _this$_canvasRef$curr3 === void 0 ? void 0 : _this$_canvasRef$curr3.loseContext();
112
+ }
101
113
  }
102
114
  /**
103
115
  * Creates a snapshot from the canvas in the surface
@@ -204,20 +216,20 @@ export class SkiaBaseWebView extends React.Component {
204
216
  debug = false,
205
217
  ...viewProps
206
218
  } = this.props;
207
- return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
208
- onLayout: this.onLayout.bind(this)
219
+ return /*#__PURE__*/React.createElement(Platform.View, _extends({}, viewProps, {
220
+ onLayout: this.onLayout
209
221
  }), /*#__PURE__*/React.createElement("canvas", {
210
222
  ref: this._canvasRef,
211
223
  style: {
212
224
  display: "flex",
213
225
  flex: 1
214
226
  },
215
- onPointerDown: this.createTouchHandler(TouchType.Start),
216
- onPointerMove: this.createTouchHandler(TouchType.Active),
217
- onPointerUp: this.createTouchHandler(TouchType.End),
218
- onPointerCancel: this.createTouchHandler(TouchType.Cancelled),
219
- onPointerLeave: this.createTouchHandler(TouchType.End),
220
- onPointerOut: this.createTouchHandler(TouchType.End)
227
+ onPointerDown: this.onStart,
228
+ onPointerMove: this.onActive,
229
+ onPointerUp: this.onEnd,
230
+ onPointerCancel: this.onCancel,
231
+ onPointerLeave: this.onEnd,
232
+ onPointerOut: this.onEnd
221
233
  }));
222
234
  }
223
235