@shopify/react-native-skia 0.1.224 → 0.1.227

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +3 -3
  2. package/cpp/api/JsiSkMatrix.h +8 -2
  3. package/cpp/api/JsiSkParagraphStyle.h +3 -2
  4. package/cpp/api/JsiSkPictureRecorder.h +10 -3
  5. package/cpp/api/JsiSkStrutStyle.h +10 -3
  6. package/cpp/rnskia/dom/props/MatrixProp.h +8 -0
  7. package/cpp/rnskia/dom/props/TransformProp.h +76 -9
  8. package/lib/commonjs/animation/spring/runSpring.d.ts +3 -0
  9. package/lib/commonjs/animation/spring/runSpring.js +3 -0
  10. package/lib/commonjs/animation/spring/runSpring.js.map +1 -1
  11. package/lib/commonjs/animation/spring/useSpring.d.ts +3 -0
  12. package/lib/commonjs/animation/spring/useSpring.js +3 -0
  13. package/lib/commonjs/animation/spring/useSpring.js.map +1 -1
  14. package/lib/commonjs/animation/timing/runTiming.d.ts +3 -0
  15. package/lib/commonjs/animation/timing/runTiming.js +3 -0
  16. package/lib/commonjs/animation/timing/runTiming.js.map +1 -1
  17. package/lib/commonjs/animation/timing/useLoop.d.ts +3 -0
  18. package/lib/commonjs/animation/timing/useLoop.js +3 -0
  19. package/lib/commonjs/animation/timing/useLoop.js.map +1 -1
  20. package/lib/commonjs/animation/timing/useTiming.d.ts +3 -0
  21. package/lib/commonjs/animation/timing/useTiming.js +3 -0
  22. package/lib/commonjs/animation/timing/useTiming.js.map +1 -1
  23. package/lib/commonjs/dom/nodes/JsiSkDOM.js +2 -0
  24. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  25. package/lib/commonjs/dom/nodes/datatypes/Fitting.d.ts +5 -5
  26. package/lib/commonjs/dom/nodes/datatypes/Fitting.js.map +1 -1
  27. package/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +235 -75
  28. package/lib/commonjs/dom/nodes/datatypes/Gradient.js.map +1 -1
  29. package/lib/commonjs/dom/types/Common.d.ts +3 -3
  30. package/lib/commonjs/dom/types/Common.js.map +1 -1
  31. package/lib/commonjs/external/reanimated/interpolators.js +10 -4
  32. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  33. package/lib/commonjs/renderer/Canvas.js +34 -28
  34. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  35. package/lib/commonjs/renderer/components/Drawing.d.ts +5 -0
  36. package/lib/commonjs/renderer/components/Drawing.js +5 -0
  37. package/lib/commonjs/renderer/components/Drawing.js.map +1 -1
  38. package/lib/commonjs/renderer/components/shapes/FitBox.d.ts +5 -5
  39. package/lib/commonjs/skia/core/Matrix.d.ts +2 -2
  40. package/lib/commonjs/skia/core/Matrix.js.map +1 -1
  41. package/lib/commonjs/skia/core/Picture.d.ts +2 -2
  42. package/lib/commonjs/skia/core/Picture.js +12 -2
  43. package/lib/commonjs/skia/core/Picture.js.map +1 -1
  44. package/lib/commonjs/skia/core/Vector.d.ts +3 -3
  45. package/lib/commonjs/skia/core/Vector.js.map +1 -1
  46. package/lib/commonjs/skia/types/Canvas.d.ts +1 -1
  47. package/lib/commonjs/skia/types/Canvas.js.map +1 -1
  48. package/lib/commonjs/skia/types/Matrix.d.ts +4 -9
  49. package/lib/commonjs/skia/types/Matrix.js +5 -56
  50. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  51. package/lib/commonjs/skia/types/Matrix4.d.ts +39 -0
  52. package/lib/commonjs/skia/types/Matrix4.js +213 -0
  53. package/lib/commonjs/skia/types/Matrix4.js.map +1 -0
  54. package/lib/commonjs/skia/types/Path/Path.d.ts +1 -1
  55. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  56. package/lib/commonjs/skia/types/Picture/PictureRecorder.d.ts +1 -1
  57. package/lib/commonjs/skia/types/Picture/PictureRecorder.js.map +1 -1
  58. package/lib/commonjs/skia/types/Rect.d.ts +1 -0
  59. package/lib/commonjs/skia/types/Rect.js +18 -0
  60. package/lib/commonjs/skia/types/Rect.js.map +1 -1
  61. package/lib/commonjs/skia/types/index.d.ts +1 -0
  62. package/lib/commonjs/skia/types/index.js +13 -0
  63. package/lib/commonjs/skia/types/index.js.map +1 -1
  64. package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +1 -1
  65. package/lib/commonjs/skia/web/JsiSkCanvas.js +1 -1
  66. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  67. package/lib/commonjs/skia/web/JsiSkMatrix.d.ts +1 -1
  68. package/lib/commonjs/skia/web/JsiSkMatrix.js +1 -1
  69. package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
  70. package/lib/commonjs/skia/web/JsiSkPath.js +1 -1
  71. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  72. package/lib/commonjs/skia/web/JsiSkPictureRecorder.d.ts +1 -1
  73. package/lib/commonjs/skia/web/JsiSkPictureRecorder.js +1 -1
  74. package/lib/commonjs/skia/web/JsiSkPictureRecorder.js.map +1 -1
  75. package/lib/commonjs/values/api.d.ts +23 -2
  76. package/lib/commonjs/values/api.js +44 -1
  77. package/lib/commonjs/values/api.js.map +1 -1
  78. package/lib/commonjs/values/hooks/useClockValue.d.ts +3 -0
  79. package/lib/commonjs/values/hooks/useClockValue.js +3 -0
  80. package/lib/commonjs/values/hooks/useClockValue.js.map +1 -1
  81. package/lib/commonjs/values/hooks/useComputedValue.d.ts +3 -0
  82. package/lib/commonjs/values/hooks/useComputedValue.js +3 -0
  83. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
  84. package/lib/commonjs/values/hooks/useValue.d.ts +3 -0
  85. package/lib/commonjs/values/hooks/useValue.js +3 -0
  86. package/lib/commonjs/values/hooks/useValue.js.map +1 -1
  87. package/lib/commonjs/values/hooks/useValueEffect.d.ts +3 -0
  88. package/lib/commonjs/values/hooks/useValueEffect.js +3 -0
  89. package/lib/commonjs/values/hooks/useValueEffect.js.map +1 -1
  90. package/lib/commonjs/values/types.d.ts +4 -4
  91. package/lib/commonjs/values/types.js.map +1 -1
  92. package/lib/commonjs/views/SkiaView.d.ts +5 -0
  93. package/lib/commonjs/views/SkiaView.js +9 -0
  94. package/lib/commonjs/views/SkiaView.js.map +1 -1
  95. package/lib/module/animation/spring/runSpring.d.ts +3 -0
  96. package/lib/module/animation/spring/runSpring.js +3 -0
  97. package/lib/module/animation/spring/runSpring.js.map +1 -1
  98. package/lib/module/animation/spring/useSpring.d.ts +3 -0
  99. package/lib/module/animation/spring/useSpring.js +3 -0
  100. package/lib/module/animation/spring/useSpring.js.map +1 -1
  101. package/lib/module/animation/timing/runTiming.d.ts +3 -0
  102. package/lib/module/animation/timing/runTiming.js +3 -0
  103. package/lib/module/animation/timing/runTiming.js.map +1 -1
  104. package/lib/module/animation/timing/useLoop.d.ts +3 -0
  105. package/lib/module/animation/timing/useLoop.js +3 -0
  106. package/lib/module/animation/timing/useLoop.js.map +1 -1
  107. package/lib/module/animation/timing/useTiming.d.ts +3 -0
  108. package/lib/module/animation/timing/useTiming.js +3 -0
  109. package/lib/module/animation/timing/useTiming.js.map +1 -1
  110. package/lib/module/dom/nodes/JsiSkDOM.js +2 -0
  111. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  112. package/lib/module/dom/nodes/datatypes/Fitting.d.ts +5 -5
  113. package/lib/module/dom/nodes/datatypes/Fitting.js.map +1 -1
  114. package/lib/module/dom/nodes/datatypes/Gradient.d.ts +235 -75
  115. package/lib/module/dom/nodes/datatypes/Gradient.js.map +1 -1
  116. package/lib/module/dom/types/Common.d.ts +3 -3
  117. package/lib/module/dom/types/Common.js.map +1 -1
  118. package/lib/module/external/reanimated/interpolators.js +11 -5
  119. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  120. package/lib/module/renderer/Canvas.js +35 -29
  121. package/lib/module/renderer/Canvas.js.map +1 -1
  122. package/lib/module/renderer/components/Drawing.d.ts +5 -0
  123. package/lib/module/renderer/components/Drawing.js +6 -0
  124. package/lib/module/renderer/components/Drawing.js.map +1 -1
  125. package/lib/module/renderer/components/shapes/FitBox.d.ts +5 -5
  126. package/lib/module/skia/core/Matrix.d.ts +2 -2
  127. package/lib/module/skia/core/Matrix.js.map +1 -1
  128. package/lib/module/skia/core/Picture.d.ts +2 -2
  129. package/lib/module/skia/core/Picture.js +12 -3
  130. package/lib/module/skia/core/Picture.js.map +1 -1
  131. package/lib/module/skia/core/Vector.d.ts +3 -3
  132. package/lib/module/skia/core/Vector.js.map +1 -1
  133. package/lib/module/skia/types/Canvas.d.ts +1 -1
  134. package/lib/module/skia/types/Canvas.js.map +1 -1
  135. package/lib/module/skia/types/Matrix.d.ts +4 -9
  136. package/lib/module/skia/types/Matrix.js +3 -57
  137. package/lib/module/skia/types/Matrix.js.map +1 -1
  138. package/lib/module/skia/types/Matrix4.d.ts +39 -0
  139. package/lib/module/skia/types/Matrix4.js +200 -0
  140. package/lib/module/skia/types/Matrix4.js.map +1 -0
  141. package/lib/module/skia/types/Path/Path.d.ts +1 -1
  142. package/lib/module/skia/types/Path/Path.js.map +1 -1
  143. package/lib/module/skia/types/Picture/PictureRecorder.d.ts +1 -1
  144. package/lib/module/skia/types/Picture/PictureRecorder.js.map +1 -1
  145. package/lib/module/skia/types/Rect.d.ts +1 -0
  146. package/lib/module/skia/types/Rect.js +9 -0
  147. package/lib/module/skia/types/Rect.js.map +1 -1
  148. package/lib/module/skia/types/index.d.ts +1 -0
  149. package/lib/module/skia/types/index.js +1 -0
  150. package/lib/module/skia/types/index.js.map +1 -1
  151. package/lib/module/skia/web/JsiSkCanvas.d.ts +1 -1
  152. package/lib/module/skia/web/JsiSkCanvas.js +1 -1
  153. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  154. package/lib/module/skia/web/JsiSkMatrix.d.ts +1 -1
  155. package/lib/module/skia/web/JsiSkMatrix.js +1 -1
  156. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  157. package/lib/module/skia/web/JsiSkPath.js +1 -1
  158. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  159. package/lib/module/skia/web/JsiSkPictureRecorder.d.ts +1 -1
  160. package/lib/module/skia/web/JsiSkPictureRecorder.js +1 -1
  161. package/lib/module/skia/web/JsiSkPictureRecorder.js.map +1 -1
  162. package/lib/module/values/api.d.ts +23 -2
  163. package/lib/module/values/api.js +44 -1
  164. package/lib/module/values/api.js.map +1 -1
  165. package/lib/module/values/hooks/useClockValue.d.ts +3 -0
  166. package/lib/module/values/hooks/useClockValue.js +3 -0
  167. package/lib/module/values/hooks/useClockValue.js.map +1 -1
  168. package/lib/module/values/hooks/useComputedValue.d.ts +3 -0
  169. package/lib/module/values/hooks/useComputedValue.js +3 -0
  170. package/lib/module/values/hooks/useComputedValue.js.map +1 -1
  171. package/lib/module/values/hooks/useValue.d.ts +3 -0
  172. package/lib/module/values/hooks/useValue.js +3 -0
  173. package/lib/module/values/hooks/useValue.js.map +1 -1
  174. package/lib/module/values/hooks/useValueEffect.d.ts +3 -0
  175. package/lib/module/values/hooks/useValueEffect.js +3 -0
  176. package/lib/module/values/hooks/useValueEffect.js.map +1 -1
  177. package/lib/module/values/types.d.ts +4 -4
  178. package/lib/module/values/types.js.map +1 -1
  179. package/lib/module/views/SkiaView.d.ts +5 -0
  180. package/lib/module/views/SkiaView.js +10 -0
  181. package/lib/module/views/SkiaView.js.map +1 -1
  182. package/lib/typescript/src/animation/spring/runSpring.d.ts +3 -0
  183. package/lib/typescript/src/animation/spring/useSpring.d.ts +3 -0
  184. package/lib/typescript/src/animation/timing/runTiming.d.ts +3 -0
  185. package/lib/typescript/src/animation/timing/useLoop.d.ts +3 -0
  186. package/lib/typescript/src/animation/timing/useTiming.d.ts +3 -0
  187. package/lib/typescript/src/dom/nodes/datatypes/Fitting.d.ts +5 -5
  188. package/lib/typescript/src/dom/nodes/datatypes/Gradient.d.ts +235 -75
  189. package/lib/typescript/src/dom/types/Common.d.ts +3 -3
  190. package/lib/typescript/src/renderer/components/Drawing.d.ts +5 -0
  191. package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +5 -5
  192. package/lib/typescript/src/skia/core/Matrix.d.ts +2 -2
  193. package/lib/typescript/src/skia/core/Picture.d.ts +2 -2
  194. package/lib/typescript/src/skia/core/Vector.d.ts +3 -3
  195. package/lib/typescript/src/skia/types/Canvas.d.ts +1 -1
  196. package/lib/typescript/src/skia/types/Matrix.d.ts +4 -9
  197. package/lib/typescript/src/skia/types/Matrix4.d.ts +39 -0
  198. package/lib/typescript/src/skia/types/Path/Path.d.ts +1 -1
  199. package/lib/typescript/src/skia/types/Picture/PictureRecorder.d.ts +1 -1
  200. package/lib/typescript/src/skia/types/Rect.d.ts +1 -0
  201. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  202. package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +1 -1
  203. package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -1
  204. package/lib/typescript/src/skia/web/JsiSkPictureRecorder.d.ts +1 -1
  205. package/lib/typescript/src/values/api.d.ts +23 -2
  206. package/lib/typescript/src/values/hooks/useClockValue.d.ts +3 -0
  207. package/lib/typescript/src/values/hooks/useComputedValue.d.ts +3 -0
  208. package/lib/typescript/src/values/hooks/useValue.d.ts +3 -0
  209. package/lib/typescript/src/values/hooks/useValueEffect.d.ts +3 -0
  210. package/lib/typescript/src/values/types.d.ts +4 -4
  211. package/lib/typescript/src/views/SkiaView.d.ts +5 -0
  212. package/package.json +1 -1
  213. package/src/animation/spring/runSpring.ts +3 -0
  214. package/src/animation/spring/useSpring.ts +3 -0
  215. package/src/animation/timing/runTiming.ts +3 -0
  216. package/src/animation/timing/useLoop.ts +3 -0
  217. package/src/animation/timing/useTiming.ts +3 -0
  218. package/src/dom/nodes/JsiSkDOM.ts +4 -0
  219. package/src/dom/nodes/datatypes/Fitting.ts +10 -2
  220. package/src/dom/nodes/datatypes/Gradient.ts +2 -2
  221. package/src/dom/types/Common.ts +3 -3
  222. package/src/external/reanimated/interpolators.ts +14 -6
  223. package/src/renderer/Canvas.tsx +41 -30
  224. package/src/renderer/components/Drawing.tsx +5 -0
  225. package/src/skia/core/Matrix.ts +2 -2
  226. package/src/skia/core/Picture.ts +11 -3
  227. package/src/skia/core/Vector.ts +5 -2
  228. package/src/skia/types/Canvas.ts +1 -1
  229. package/src/skia/types/Matrix.ts +7 -74
  230. package/src/skia/types/Matrix4.ts +266 -0
  231. package/src/skia/types/Path/Path.ts +1 -1
  232. package/src/skia/types/Picture/PictureRecorder.ts +1 -1
  233. package/src/skia/types/Rect.ts +14 -0
  234. package/src/skia/types/index.ts +1 -0
  235. package/src/skia/web/JsiSkCanvas.ts +2 -2
  236. package/src/skia/web/JsiSkMatrix.ts +4 -2
  237. package/src/skia/web/JsiSkPath.ts +1 -1
  238. package/src/skia/web/JsiSkPictureRecorder.ts +6 -2
  239. package/src/values/api.ts +55 -2
  240. package/src/values/hooks/useClockValue.ts +3 -0
  241. package/src/values/hooks/useComputedValue.ts +3 -0
  242. package/src/values/hooks/useValue.ts +3 -0
  243. package/src/values/hooks/useValueEffect.ts +3 -0
  244. package/src/values/types.ts +6 -6
  245. package/src/views/SkiaView.tsx +11 -0
@@ -1,4 +1,10 @@
1
1
  import React from "react";
2
+
3
+ /**
4
+ * @deprecated If you are looking to use the Skia imperative API, you can use:
5
+ * The picture API: https://shopify.github.io/react-native-skia/docs/shapes/pictures/
6
+ * The offscreen API: https://shopify.github.io/react-native-skia/docs/animations/textures
7
+ */
2
8
  export const Drawing = props => {
3
9
  return /*#__PURE__*/React.createElement("skDrawing", props);
4
10
  };
@@ -1 +1 @@
1
- {"version":3,"names":["React","Drawing","props"],"sources":["Drawing.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { CustomDrawingNodeProps } from \"../../dom/types\";\n\nexport const Drawing = (props: CustomDrawingNodeProps) => {\n return <skDrawing {...props} />;\n};\n"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAIA,OAAO,MAAMC,OAAO,GAAIC,KAAD,IAAmC;EACxD,oBAAO,iCAAeA,KAAf,CAAP;AACD,CAFM"}
1
+ {"version":3,"names":["React","Drawing","props"],"sources":["Drawing.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { CustomDrawingNodeProps } from \"../../dom/types\";\n\n/**\n * @deprecated If you are looking to use the Skia imperative API, you can use:\n * The picture API: https://shopify.github.io/react-native-skia/docs/shapes/pictures/\n * The offscreen API: https://shopify.github.io/react-native-skia/docs/animations/textures\n */\nexport const Drawing = (props: CustomDrawingNodeProps) => {\n return <skDrawing {...props} />;\n};\n"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;;AAIA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,GAAIC,KAAD,IAAmC;EACxD,oBAAO,iCAAeA,KAAf,CAAP;AACD,CAFM"}
@@ -8,14 +8,14 @@ interface FitProps {
8
8
  dst: SkRect;
9
9
  children: ReactNode | ReactNode[];
10
10
  }
11
- export declare const fitbox: (fit: Fit, src: SkRect, dst: SkRect) => readonly [{
12
- readonly translateX: number;
11
+ export declare const fitbox: (fit: Fit, src: SkRect, dst: SkRect) => [{
12
+ translateX: number;
13
13
  }, {
14
- readonly translateY: number;
14
+ translateY: number;
15
15
  }, {
16
- readonly scaleX: number;
16
+ scaleX: number;
17
17
  }, {
18
- readonly scaleY: number;
18
+ scaleY: number;
19
19
  }];
20
20
  export declare const FitBox: ({ fit, src, dst, children }: FitProps) => React.JSX.Element;
21
21
  export {};
@@ -1,2 +1,2 @@
1
- import type { Transforms2d } from "../types";
2
- export declare const processTransform2d: (transforms: Transforms2d) => import("../types").SkMatrix;
1
+ import type { Transforms3d } from "../types";
2
+ export declare const processTransform2d: (transforms: Transforms3d) => import("../types").SkMatrix;
@@ -1 +1 @@
1
- {"version":3,"names":["Skia","processTransform","processTransform2d","transforms","Matrix"],"sources":["Matrix.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { Transforms2d } from \"../types\";\nimport { processTransform } from \"../types\";\n\nexport const processTransform2d = (transforms: Transforms2d) =>\n processTransform(Skia.Matrix(), transforms);\n"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AAEA,SAASC,gBAAT,QAAiC,UAAjC;AAEA,OAAO,MAAMC,kBAAkB,GAAIC,UAAD,IAChCF,gBAAgB,CAACD,IAAI,CAACI,MAAL,EAAD,EAAgBD,UAAhB,CADX"}
1
+ {"version":3,"names":["Skia","processTransform","processTransform2d","transforms","Matrix"],"sources":["Matrix.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { Transforms3d } from \"../types\";\nimport { processTransform } from \"../types\";\n\nexport const processTransform2d = (transforms: Transforms3d) =>\n processTransform(Skia.Matrix(), transforms);\n"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AAEA,SAASC,gBAAT,QAAiC,UAAjC;AAEA,OAAO,MAAMC,kBAAkB,GAAIC,UAAD,IAChCF,gBAAgB,CAACD,IAAI,CAACI,MAAL,EAAD,EAAgBD,UAAhB,CADX"}
@@ -1,8 +1,8 @@
1
- import type { SkCanvas, SkRect } from "../types";
1
+ import { type SkCanvas, type SkRect, type SkSize } from "../types";
2
2
  /**
3
3
  * Memoizes and returns an SkPicture that can be drawn to another canvas.
4
4
  * @param rect Picture bounds
5
5
  * @param cb Callback for drawing to the canvas
6
6
  * @returns SkPicture
7
7
  */
8
- export declare const createPicture: (rect: SkRect, cb: (canvas: SkCanvas) => void) => import("../types").SkPicture;
8
+ export declare const createPicture: (cb: (canvas: SkCanvas) => void, rect?: SkRect | SkSize) => import("../types").SkPicture;
@@ -1,14 +1,23 @@
1
1
  import { Skia } from "../Skia";
2
-
2
+ import { isRect } from "../types";
3
3
  /**
4
4
  * Memoizes and returns an SkPicture that can be drawn to another canvas.
5
5
  * @param rect Picture bounds
6
6
  * @param cb Callback for drawing to the canvas
7
7
  * @returns SkPicture
8
8
  */
9
- export const createPicture = (rect, cb) => {
9
+
10
+ export const createPicture = (cb, rect) => {
11
+ "worklet";
12
+
10
13
  const recorder = Skia.PictureRecorder();
11
- const canvas = recorder.beginRecording(rect);
14
+ let bounds;
15
+
16
+ if (rect) {
17
+ bounds = isRect(rect) ? rect : Skia.XYWHRect(0, 0, rect.width, rect.height);
18
+ }
19
+
20
+ const canvas = recorder.beginRecording(bounds);
12
21
  cb(canvas);
13
22
  return recorder.finishRecordingAsPicture();
14
23
  };
@@ -1 +1 @@
1
- {"version":3,"names":["Skia","createPicture","rect","cb","recorder","PictureRecorder","canvas","beginRecording","finishRecordingAsPicture"],"sources":["Picture.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { SkCanvas, SkRect } from \"../types\";\n\n/**\n * Memoizes and returns an SkPicture that can be drawn to another canvas.\n * @param rect Picture bounds\n * @param cb Callback for drawing to the canvas\n * @returns SkPicture\n */\nexport const createPicture = (rect: SkRect, cb: (canvas: SkCanvas) => void) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(rect);\n cb(canvas);\n return recorder.finishRecordingAsPicture();\n};\n"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAG,CAACC,IAAD,EAAeC,EAAf,KAAkD;EAC7E,MAAMC,QAAQ,GAAGJ,IAAI,CAACK,eAAL,EAAjB;EACA,MAAMC,MAAM,GAAGF,QAAQ,CAACG,cAAT,CAAwBL,IAAxB,CAAf;EACAC,EAAE,CAACG,MAAD,CAAF;EACA,OAAOF,QAAQ,CAACI,wBAAT,EAAP;AACD,CALM"}
1
+ {"version":3,"names":["Skia","isRect","createPicture","cb","rect","recorder","PictureRecorder","bounds","XYWHRect","width","height","canvas","beginRecording","finishRecordingAsPicture"],"sources":["Picture.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport { isRect, type SkCanvas, type SkRect, type SkSize } from \"../types\";\n\n/**\n * Memoizes and returns an SkPicture that can be drawn to another canvas.\n * @param rect Picture bounds\n * @param cb Callback for drawing to the canvas\n * @returns SkPicture\n */\nexport const createPicture = (\n cb: (canvas: SkCanvas) => void,\n rect?: SkRect | SkSize\n) => {\n \"worklet\";\n const recorder = Skia.PictureRecorder();\n let bounds: undefined | SkRect;\n if (rect) {\n bounds = isRect(rect) ? rect : Skia.XYWHRect(0, 0, rect.width, rect.height);\n }\n const canvas = recorder.beginRecording(bounds);\n cb(canvas);\n return recorder.finishRecordingAsPicture();\n};\n"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AACA,SAASC,MAAT,QAAgE,UAAhE;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,aAAa,GAAG,CAC3BC,EAD2B,EAE3BC,IAF2B,KAGxB;EACH;;EACA,MAAMC,QAAQ,GAAGL,IAAI,CAACM,eAAL,EAAjB;EACA,IAAIC,MAAJ;;EACA,IAAIH,IAAJ,EAAU;IACRG,MAAM,GAAGN,MAAM,CAACG,IAAD,CAAN,GAAeA,IAAf,GAAsBJ,IAAI,CAACQ,QAAL,CAAc,CAAd,EAAiB,CAAjB,EAAoBJ,IAAI,CAACK,KAAzB,EAAgCL,IAAI,CAACM,MAArC,CAA/B;EACD;;EACD,MAAMC,MAAM,GAAGN,QAAQ,CAACO,cAAT,CAAwBL,MAAxB,CAAf;EACAJ,EAAE,CAACQ,MAAD,CAAF;EACA,OAAON,QAAQ,CAACQ,wBAAT,EAAP;AACD,CAbM"}
@@ -5,8 +5,8 @@ export declare const neg: (a: Vector) => import("../types").SkPoint;
5
5
  export declare const add: (a: Vector, b: Vector) => import("../types").SkPoint;
6
6
  export declare const sub: (a: Vector, b: Vector) => import("../types").SkPoint;
7
7
  export declare const dist: (a: Vector, b: Vector) => number;
8
- export declare const translate: ({ x, y }: Vector) => readonly [{
9
- readonly translateX: number;
8
+ export declare const translate: ({ x, y, }: Vector) => [{
9
+ translateX: number;
10
10
  }, {
11
- readonly translateY: number;
11
+ translateY: number;
12
12
  }];
@@ -1 +1 @@
1
- {"version":3,"names":["Skia","vec","x","y","Point","point","neg","a","add","b","sub","dist","Math","hypot","translate","translateX","translateY"],"sources":["Vector.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { Vector } from \"../types\";\n\nexport const vec = (x = 0, y?: number) => {\n \"worklet\";\n return Skia.Point(x, y ?? x);\n};\nexport const point = vec;\nexport const neg = (a: Vector) => {\n \"worklet\";\n return vec(-a.x, -a.y);\n};\nexport const add = (a: Vector, b: Vector) => {\n \"worklet\";\n return vec(a.x + b.x, a.y + b.y);\n};\nexport const sub = (a: Vector, b: Vector) => {\n \"worklet\";\n return vec(a.x - b.x, a.y - b.y);\n};\nexport const dist = (a: Vector, b: Vector) => {\n \"worklet\";\n return Math.hypot(a.x - b.x, a.y - b.y);\n};\nexport const translate = ({ x, y }: Vector) => {\n \"worklet\";\n return [{ translateX: x }, { translateY: y }] as const;\n};\n"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AAGA,OAAO,MAAMC,GAAG,GAAG,YAAuB;EACxC;;EADwC,IAAtBC,CAAsB,uEAAlB,CAAkB;EAAA,IAAfC,CAAe;EAExC,OAAOH,IAAI,CAACI,KAAL,CAAWF,CAAX,EAAcC,CAAd,aAAcA,CAAd,cAAcA,CAAd,GAAmBD,CAAnB,CAAP;AACD,CAHM;AAIP,OAAO,MAAMG,KAAK,GAAGJ,GAAd;AACP,OAAO,MAAMK,GAAG,GAAIC,CAAD,IAAe;EAChC;;EACA,OAAON,GAAG,CAAC,CAACM,CAAC,CAACL,CAAJ,EAAO,CAACK,CAAC,CAACJ,CAAV,CAAV;AACD,CAHM;AAIP,OAAO,MAAMK,GAAG,GAAG,CAACD,CAAD,EAAYE,CAAZ,KAA0B;EAC3C;;EACA,OAAOR,GAAG,CAACM,CAAC,CAACL,CAAF,GAAMO,CAAC,CAACP,CAAT,EAAYK,CAAC,CAACJ,CAAF,GAAMM,CAAC,CAACN,CAApB,CAAV;AACD,CAHM;AAIP,OAAO,MAAMO,GAAG,GAAG,CAACH,CAAD,EAAYE,CAAZ,KAA0B;EAC3C;;EACA,OAAOR,GAAG,CAACM,CAAC,CAACL,CAAF,GAAMO,CAAC,CAACP,CAAT,EAAYK,CAAC,CAACJ,CAAF,GAAMM,CAAC,CAACN,CAApB,CAAV;AACD,CAHM;AAIP,OAAO,MAAMQ,IAAI,GAAG,CAACJ,CAAD,EAAYE,CAAZ,KAA0B;EAC5C;;EACA,OAAOG,IAAI,CAACC,KAAL,CAAWN,CAAC,CAACL,CAAF,GAAMO,CAAC,CAACP,CAAnB,EAAsBK,CAAC,CAACJ,CAAF,GAAMM,CAAC,CAACN,CAA9B,CAAP;AACD,CAHM;AAIP,OAAO,MAAMW,SAAS,GAAG,QAAsB;EAC7C;;EAD6C,IAArB;IAAEZ,CAAF;IAAKC;EAAL,CAAqB;EAE7C,OAAO,CAAC;IAAEY,UAAU,EAAEb;EAAd,CAAD,EAAoB;IAAEc,UAAU,EAAEb;EAAd,CAApB,CAAP;AACD,CAHM"}
1
+ {"version":3,"names":["Skia","vec","x","y","Point","point","neg","a","add","b","sub","dist","Math","hypot","translate","translateX","translateY"],"sources":["Vector.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { Vector } from \"../types\";\n\nexport const vec = (x = 0, y?: number) => {\n \"worklet\";\n return Skia.Point(x, y ?? x);\n};\nexport const point = vec;\nexport const neg = (a: Vector) => {\n \"worklet\";\n return vec(-a.x, -a.y);\n};\nexport const add = (a: Vector, b: Vector) => {\n \"worklet\";\n return vec(a.x + b.x, a.y + b.y);\n};\nexport const sub = (a: Vector, b: Vector) => {\n \"worklet\";\n return vec(a.x - b.x, a.y - b.y);\n};\nexport const dist = (a: Vector, b: Vector) => {\n \"worklet\";\n return Math.hypot(a.x - b.x, a.y - b.y);\n};\nexport const translate = ({\n x,\n y,\n}: Vector): [{ translateX: number }, { translateY: number }] => {\n \"worklet\";\n return [{ translateX: x }, { translateY: y }];\n};\n"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AAGA,OAAO,MAAMC,GAAG,GAAG,YAAuB;EACxC;;EADwC,IAAtBC,CAAsB,uE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aces current matrix with m premultiplied with the existing matrix.
373
373
  * @param m
374
374
  */
375
- concat(m: SkMatrix): void;
375
+ concat(m: SkMatrix | number[]): void;
376
376
  /**
377
377
  * Draws the given picture using the current clip, current matrix, and the provided paint.
378
378
  * @param skp
@@ -1 +1 @@
1
- {"version":3,"names":["ClipOp","SaveLayerFlag"],"sources":["Canvas.ts"],"sourcesContent":["import type { SkPaint } from \"./Paint\";\nimport type { SkRect } from \"./Rect\";\nimport type { SkFont } from \"./Font\";\nimport type { SkPath } from \"./Path\";\nimport type { SkImage, MipmapMode, FilterMode, ImageInfo } from \"./Image\";\nimport type { SkSVG } from \"./SVG\";\nimport type { SkColor } from \"./Color\";\nimport type { SkRRect } from \"./RRect\";\nimport type { BlendMode } from \"./Paint/BlendMode\";\nimport type { SkPoint, PointMode } from \"./Point\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { SkImageFilter } from \"./ImageFilter\";\nimport type { SkVertices } from \"./Vertices\";\nimport type { SkTextBlob } from \"./TextBlob\";\nimport type { SkPicture } from \"./Picture\";\n\nexport enum ClipOp {\n Difference,\n Intersect,\n}\n\nexport enum SaveLayerFlag {\n SaveLayerInitWithPrevious = 1 << 2,\n SaveLayerF16ColorType = 1 << 4,\n}\n\nexport interface SkCanvas {\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix, and optionally-provided paint.\n * @param img\n * @param left\n * @param top\n * @param paint\n */\n drawImage: (image: SkImage, x: number, y: number, paint?: SkPaint) => void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * @param img\n * @param src\n * @param dest\n * @param paint\n * @param fastSample - if false, will filter strictly within src.\n */\n drawImageRect(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n paint: SkPaint,\n fastSample?: boolean\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param left\n * @param top\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageCubic(\n img: SkImage,\n left: number,\n top: number,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the provided sampling options if necessary.\n * @param img\n * @param left\n * @param top\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageOptions(\n img: SkImage,\n left: number,\n top: number,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the provided image stretched proportionally to fit into dst rectangle.\n * The center rectangle divides the image into nine sections: four sides, four corners, and\n * the center.\n * @param img\n * @param center\n * @param dest\n * @param filter - what technique to use when sampling the image\n * @param paint\n */\n drawImageNine(\n img: SkImage,\n center: SkRect,\n dest: SkRect,\n filter: FilterMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param src\n * @param dest\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageRectCubic(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the provided sampling options if necessary.\n * @param img\n * @param src\n * @param dest\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageRectOptions(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /** Fills clip with SkPaint paint. SkPaint components, SkShader,\n SkColorFilter, SkImageFilter, and SkBlendMode affect drawing;\n SkMaskFilter and SkPathEffect in paint are ignored.\n\n @param paint graphics state used to fill SkCanvas\n\n example: https://fiddle.skia.org/c/@Canvas_drawPaint\n */\n drawPaint: (paint: SkPaint) => void;\n\n /** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint stroke width describes the line thickness;\n SkPaint::Cap draws the end rounded or square;\n SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.\n\n @param x0 start of line segment on x-axis\n @param y0 start of line segment on y-axis\n @param x1 end of line segment on x-axis\n @param y1 end of line segment on y-axis\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawLine\n */\n drawLine: (\n x0: number,\n y0: number,\n x1: number,\n y1: number,\n paint: SkPaint\n ) => void;\n /** Draws SkRect rect using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint::Style determines if rectangle is stroked or filled;\n if stroked, SkPaint stroke width describes the line thickness, and\n SkPaint::Join draws the corners rounded or square.\n\n @param rect rectangle to draw\n @param paint stroke or fill, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawRect\n */\n drawRect: (rect: SkRect, paint: SkPaint) => void;\n\n /**\n * Draws a circle at (cx, cy) with the given radius.\n * @param cx\n * @param cy\n * @param radius\n * @param paint\n */\n drawCircle(cx: number, cy: number, radius: number, paint: SkPaint): void;\n\n /**\n * Draws the given vertices (a triangle mesh) using the current clip, current matrix, and the\n * provided paint.\n * If paint contains an Shader and vertices does not contain texCoords, the shader\n * is mapped using the vertices' positions.\n * If vertices colors are defined in vertices, and Paint paint contains Shader,\n * BlendMode mode combines vertices colors with Shader.\n * @param verts\n * @param mode\n * @param paint\n */\n drawVertices(verts: SkVertices, mode: BlendMode, paint: SkPaint): void;\n\n /**\n * Draws a cubic patch defined by 12 control points [top, right, bottom, left] with optional\n * colors and shader-coordinates [4] specifed for each corner [top-left, top-right, bottom-right, bottom-left]\n * @param cubics 12 points : 4 connected cubics specifying the boundary of the patch\n * @param colors optional colors interpolated across the patch\n * @param texs optional shader coordinates interpolated across the patch\n * @param mode Specifies how shader and colors blend (if both are specified)\n * @param paint\n */\n drawPatch(\n cubics: readonly SkPoint[],\n colors?: readonly SkColor[] | null,\n texs?: readonly SkPoint[] | null,\n mode?: BlendMode | null,\n paint?: SkPaint\n ): void;\n\n /**\n * Restores state to a previous stack value.\n * @param saveCount\n */\n restoreToCount(saveCount: number): void;\n\n /**\n * Draws the given points using the current clip, current matrix, and the provided paint.\n *\n * See Canvas.h for more on the mode and its interaction with paint.\n * @param mode\n * @param points\n * @param paint\n */\n drawPoints(mode: PointMode, points: SkPoint[], paint: SkPaint): void;\n\n /** Draws arc using clip, SkMatrix, and SkPaint paint.\n\n Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus\n sweepAngle. startAngle and sweepAngle are in degrees.\n\n startAngle of zero places start point at the right middle edge of oval.\n A positive sweepAngle places arc end point clockwise from start point;\n a negative sweepAngle places arc end point counterclockwise from start point.\n sweepAngle may exceed 360 degrees, a full circle.\n If useCenter is true, draw a wedge that includes lines from oval\n center to arc end points. If useCenter is false, draw arc between end points.\n\n If SkRect oval is empty or sweepAngle is zero, nothing is drawn.\n\n @param oval SkRect bounds of oval containing arc to draw\n @param startAngle angle in degrees where arc begins\n @param sweepAngle sweep angle in degrees; positive is clockwise\n @param useCenter if true, include the center of the oval\n @param paint SkPaint stroke or fill, blend, color, and so on, used to draw\n */\n drawArc: (\n oval: SkRect,\n startAngle: number,\n sweepAngle: number,\n useCenter: boolean,\n paint: SkPaint\n ) => void;\n\n /**\n * Draws the given rectangle with rounded corners using the current clip, current matrix,\n * and the provided paint.\n * @param rrect\n * @param paint\n */\n drawRRect(rrect: SkRRect, paint: SkPaint): void;\n\n /**\n * Draws RRect outer and inner using clip, Matrix, and Paint paint.\n * outer must contain inner or the drawing is undefined.\n * @param outer\n * @param inner\n * @param paint\n */\n drawDRRect(outer: SkRRect, inner: SkRRect, paint: SkPaint): void;\n\n /**\n * Draws an oval bounded by the given rectangle using the current clip, current matrix,\n * and the provided paint.\n * @param oval\n * @param paint\n */\n drawOval(oval: SkRect, paint: SkPaint): void;\n\n /** Draws SkPath path using clip, SkMatrix, and SkPaint paint.\n SkPath contains an array of path contour, each of which may be open or closed.\n\n In paint: SkPaint::Style determines if SkRRect is stroked or filled:\n if filled, SkPath::FillType determines whether path contour describes inside or\n outside of fill; if stroked, SkPaint stroke width describes the line thickness,\n SkPaint::Cap describes line ends, and SkPaint::Join describes how\n corners are drawn.\n\n @param path SkPath to draw\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawPath\n */\n drawPath: (path: SkPath, paint: SkPaint) => void;\n\n /**\n * Draw the given text at the location (x, y) using the provided paint and font. The text will\n * be drawn as is; no shaping, left-to-right, etc.\n * @param str\n * @param x\n * @param y\n * @param paint\n * @param font\n */\n drawText(\n str: string,\n x: number,\n y: number,\n paint: SkPaint,\n font: SkFont\n ): void;\n\n /**\n * Draws the given TextBlob at (x, y) using the current clip, current matrix, and the\n * provided paint. Reminder that the fonts used to draw TextBlob are part of the blob.\n * @param blob\n * @param x\n * @param y\n * @param paint\n */\n drawTextBlob(blob: SkTextBlob, x: number, y: number, paint: SkPaint): void;\n\n /**\n * Draws a run of glyphs, at corresponding positions, in a given font.\n * @param glyphs the array of glyph IDs (Uint16TypedArray)\n * @param positions the array of x,y floats to position each glyph\n * @param x x-coordinate of the origin of the entire run\n * @param y y-coordinate of the origin of the entire run\n * @param font the font that contains the glyphs\n * @param paint\n */\n drawGlyphs(\n glyphs: number[],\n positions: SkPoint[],\n x: number,\n y: number,\n font: SkFont,\n paint: SkPaint\n ): void;\n\n /**\n * Renders the SVG Dom object to the canvas. If width/height are omitted,\n * the SVG will be rendered to fit the canvas.\n */\n drawSvg: (svgDom: SkSVG, width?: number, height?: number) => void;\n /** Saves SkMatrix and clip.\n Calling restore() discards changes to SkMatrix and clip,\n restoring the SkMatrix and clip to their state when save() was called.\n\n SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(),\n and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().\n\n Saved SkCanvas state is put on a stack; multiple calls to save() should be balance\n by an equal number of calls to restore().\n\n Call restoreToCount() with result to restore this and subsequent saves.\n\n @return depth of saved stack\n\n example: https://fiddle.skia.org/c/@Canvas_save\n */\n save: () => number;\n\n /**\n * Saves Matrix and clip, and allocates a SkBitmap for subsequent drawing.\n * Calling restore() discards changes to Matrix and clip, and draws the SkBitmap.\n * It returns the height of the stack.\n * See Canvas.h for more.\n * @param paint\n * @param bounds\n * @param backdrop\n * @param flags\n */\n saveLayer(\n paint?: SkPaint,\n bounds?: SkRect | null,\n backdrop?: SkImageFilter | null,\n flags?: SaveLayerFlag\n ): number;\n\n /** Removes changes to SkMatrix and clip since SkCanvas state was\n last saved. The state is removed from the stack.\n\n Does nothing if the stack is empty.\n\n example: https://fiddle.skia.org/c/@AutoCanvasRestore_restore\n\n example: https://fiddle.skia.org/c/@Canvas_restore\n */\n restore: () => void;\n\n /**\n * Rotates the current matrix by the number of degrees.\n * @param rot - angle of rotation in degrees.\n * @param rx\n * @param ry\n */\n rotate(rotationInDegrees: number, rx: number, ry: number): void;\n\n /**\n * Scales the current matrix by sx on the x-axis and sy on the y-axis.\n * @param sx\n * @param sy\n */\n scale(sx: number, sy: number): void;\n\n /**\n * Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx\n * skews the drawing right as y-axis values increase; a positive value of sy skews\n * the drawing down as x-axis values increase.\n * @param sx\n * @param sy\n */\n skew(sx: number, sy: number): void;\n\n /**\n * Translates Matrix by dx along the x-axis and dy along the y-axis.\n * @param dx\n * @param dy\n */\n translate(dx: number, dy: number): void;\n\n /**\n * Fills clip with the given color.\n * @param color\n * @param blendMode - defaults to SrcOver.\n */\n drawColor(color: SkColor, blendMode?: BlendMode): void;\n\n /**\n * Fills the current clip with the given color using Src BlendMode.\n * This has the effect of replacing all pixels contained by clip with color.\n * @param color\n */\n clear(color: SkColor): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and path,\n * with an aliased or anti-aliased clip edge.\n * @param path\n * @param op\n * @param doAntiAlias\n */\n clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rect,\n * with an aliased or anti-aliased clip edge.\n * @param rect\n * @param op\n * @param doAntiAlias\n */\n clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rrect,\n * with an aliased or anti-aliased clip edge.\n * @param rrect\n * @param op\n * @param doAntiAlias\n */\n clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces current matrix with m premultiplied with the existing matrix.\n * @param m\n */\n concat(m: SkMatrix): void;\n\n /**\n * Draws the given picture using the current clip, current matrix, and the provided paint.\n * @param skp\n */\n drawPicture(skp: SkPicture): void;\n\n /** Read Image pixels\n *\n * @param srcX - x-axis upper left corner of the rectangle to read from\n * @param srcY - y-axis upper left corner of the rectangle to read from\n * @param imageInfo - describes the pixel format and dimensions of the data to read into\n * @return Float32Array or Uint8Array with data or null if the read failed.\n */\n readPixels(\n srcX: number,\n srcY: number,\n imageInfo: ImageInfo\n ): Float32Array | Uint8Array | null;\n}\n"],"mappings":"AAgBA,WAAYA,MAAZ;;WAAYA,M;EAAAA,M,CAAAA,M;EAAAA,M,CAAAA,M;GAAAA,M,KAAAA,M;;AAKZ,WAAYC,aAAZ;;WAAYA,a;EAAAA,a,CAAAA,a;EAAAA,a,CAAAA,a;GAAAA,a,KAAAA,a"}
1
+ {"version":3,"names":["ClipOp","SaveLayerFlag"],"sources":["Canvas.ts"],"sourcesContent":["import type { SkPaint } from \"./Paint\";\nimport type { SkRect } from \"./Rect\";\nimport type { SkFont } from \"./Font\";\nimport type { SkPath } from \"./Path\";\nimport type { SkImage, MipmapMode, FilterMode, ImageInfo } from \"./Image\";\nimport type { SkSVG } from \"./SVG\";\nimport type { SkColor } from \"./Color\";\nimport type { SkRRect } from \"./RRect\";\nimport type { BlendMode } from \"./Paint/BlendMode\";\nimport type { SkPoint, PointMode } from \"./Point\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { SkImageFilter } from \"./ImageFilter\";\nimport type { SkVertices } from \"./Vertices\";\nimport type { SkTextBlob } from \"./TextBlob\";\nimport type { SkPicture } from \"./Picture\";\n\nexport enum ClipOp {\n Difference,\n Intersect,\n}\n\nexport enum SaveLayerFlag {\n SaveLayerInitWithPrevious = 1 << 2,\n SaveLayerF16ColorType = 1 << 4,\n}\n\nexport interface SkCanvas {\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix, and optionally-provided paint.\n * @param img\n * @param left\n * @param top\n * @param paint\n */\n drawImage: (image: SkImage, x: number, y: number, paint?: SkPaint) => void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * @param img\n * @param src\n * @param dest\n * @param paint\n * @param fastSample - if false, will filter strictly within src.\n */\n drawImageRect(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n paint: SkPaint,\n fastSample?: boolean\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param left\n * @param top\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageCubic(\n img: SkImage,\n left: number,\n top: number,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the given image with its top-left corner at (left, top) using the current clip,\n * the current matrix. It will use the provided sampling options if necessary.\n * @param img\n * @param left\n * @param top\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageOptions(\n img: SkImage,\n left: number,\n top: number,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws the provided image stretched proportionally to fit into dst rectangle.\n * The center rectangle divides the image into nine sections: four sides, four corners, and\n * the center.\n * @param img\n * @param center\n * @param dest\n * @param filter - what technique to use when sampling the image\n * @param paint\n */\n drawImageNine(\n img: SkImage,\n center: SkRect,\n dest: SkRect,\n filter: FilterMode,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the cubic sampling options B and C if necessary.\n * @param img\n * @param src\n * @param dest\n * @param B - See CubicResampler in SkSamplingOptions.h for more information\n * @param C - See CubicResampler in SkSamplingOptions.h for more information\n * @param paint\n */\n drawImageRectCubic(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n B: number,\n C: number,\n paint?: SkPaint | null\n ): void;\n\n /**\n * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.\n * It will use the provided sampling options if necessary.\n * @param img\n * @param src\n * @param dest\n * @param fm - The filter mode.\n * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps\n * calculated with makeCopyWithDefaultMipmaps;\n * @param paint\n */\n drawImageRectOptions(\n img: SkImage,\n src: SkRect,\n dest: SkRect,\n fm: FilterMode,\n mm: MipmapMode,\n paint?: SkPaint | null\n ): void;\n\n /** Fills clip with SkPaint paint. SkPaint components, SkShader,\n SkColorFilter, SkImageFilter, and SkBlendMode affect drawing;\n SkMaskFilter and SkPathEffect in paint are ignored.\n\n @param paint graphics state used to fill SkCanvas\n\n example: https://fiddle.skia.org/c/@Canvas_drawPaint\n */\n drawPaint: (paint: SkPaint) => void;\n\n /** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint stroke width describes the line thickness;\n SkPaint::Cap draws the end rounded or square;\n SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.\n\n @param x0 start of line segment on x-axis\n @param y0 start of line segment on y-axis\n @param x1 end of line segment on x-axis\n @param y1 end of line segment on y-axis\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawLine\n */\n drawLine: (\n x0: number,\n y0: number,\n x1: number,\n y1: number,\n paint: SkPaint\n ) => void;\n /** Draws SkRect rect using clip, SkMatrix, and SkPaint paint.\n In paint: SkPaint::Style determines if rectangle is stroked or filled;\n if stroked, SkPaint stroke width describes the line thickness, and\n SkPaint::Join draws the corners rounded or square.\n\n @param rect rectangle to draw\n @param paint stroke or fill, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawRect\n */\n drawRect: (rect: SkRect, paint: SkPaint) => void;\n\n /**\n * Draws a circle at (cx, cy) with the given radius.\n * @param cx\n * @param cy\n * @param radius\n * @param paint\n */\n drawCircle(cx: number, cy: number, radius: number, paint: SkPaint): void;\n\n /**\n * Draws the given vertices (a triangle mesh) using the current clip, current matrix, and the\n * provided paint.\n * If paint contains an Shader and vertices does not contain texCoords, the shader\n * is mapped using the vertices' positions.\n * If vertices colors are defined in vertices, and Paint paint contains Shader,\n * BlendMode mode combines vertices colors with Shader.\n * @param verts\n * @param mode\n * @param paint\n */\n drawVertices(verts: SkVertices, mode: BlendMode, paint: SkPaint): void;\n\n /**\n * Draws a cubic patch defined by 12 control points [top, right, bottom, left] with optional\n * colors and shader-coordinates [4] specifed for each corner [top-left, top-right, bottom-right, bottom-left]\n * @param cubics 12 points : 4 connected cubics specifying the boundary of the patch\n * @param colors optional colors interpolated across the patch\n * @param texs optional shader coordinates interpolated across the patch\n * @param mode Specifies how shader and colors blend (if both are specified)\n * @param paint\n */\n drawPatch(\n cubics: readonly SkPoint[],\n colors?: readonly SkColor[] | null,\n texs?: readonly SkPoint[] | null,\n mode?: BlendMode | null,\n paint?: SkPaint\n ): void;\n\n /**\n * Restores state to a previous stack value.\n * @param saveCount\n */\n restoreToCount(saveCount: number): void;\n\n /**\n * Draws the given points using the current clip, current matrix, and the provided paint.\n *\n * See Canvas.h for more on the mode and its interaction with paint.\n * @param mode\n * @param points\n * @param paint\n */\n drawPoints(mode: PointMode, points: SkPoint[], paint: SkPaint): void;\n\n /** Draws arc using clip, SkMatrix, and SkPaint paint.\n\n Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus\n sweepAngle. startAngle and sweepAngle are in degrees.\n\n startAngle of zero places start point at the right middle edge of oval.\n A positive sweepAngle places arc end point clockwise from start point;\n a negative sweepAngle places arc end point counterclockwise from start point.\n sweepAngle may exceed 360 degrees, a full circle.\n If useCenter is true, draw a wedge that includes lines from oval\n center to arc end points. If useCenter is false, draw arc between end points.\n\n If SkRect oval is empty or sweepAngle is zero, nothing is drawn.\n\n @param oval SkRect bounds of oval containing arc to draw\n @param startAngle angle in degrees where arc begins\n @param sweepAngle sweep angle in degrees; positive is clockwise\n @param useCenter if true, include the center of the oval\n @param paint SkPaint stroke or fill, blend, color, and so on, used to draw\n */\n drawArc: (\n oval: SkRect,\n startAngle: number,\n sweepAngle: number,\n useCenter: boolean,\n paint: SkPaint\n ) => void;\n\n /**\n * Draws the given rectangle with rounded corners using the current clip, current matrix,\n * and the provided paint.\n * @param rrect\n * @param paint\n */\n drawRRect(rrect: SkRRect, paint: SkPaint): void;\n\n /**\n * Draws RRect outer and inner using clip, Matrix, and Paint paint.\n * outer must contain inner or the drawing is undefined.\n * @param outer\n * @param inner\n * @param paint\n */\n drawDRRect(outer: SkRRect, inner: SkRRect, paint: SkPaint): void;\n\n /**\n * Draws an oval bounded by the given rectangle using the current clip, current matrix,\n * and the provided paint.\n * @param oval\n * @param paint\n */\n drawOval(oval: SkRect, paint: SkPaint): void;\n\n /** Draws SkPath path using clip, SkMatrix, and SkPaint paint.\n SkPath contains an array of path contour, each of which may be open or closed.\n\n In paint: SkPaint::Style determines if SkRRect is stroked or filled:\n if filled, SkPath::FillType determines whether path contour describes inside or\n outside of fill; if stroked, SkPaint stroke width describes the line thickness,\n SkPaint::Cap describes line ends, and SkPaint::Join describes how\n corners are drawn.\n\n @param path SkPath to draw\n @param paint stroke, blend, color, and so on, used to draw\n\n example: https://fiddle.skia.org/c/@Canvas_drawPath\n */\n drawPath: (path: SkPath, paint: SkPaint) => void;\n\n /**\n * Draw the given text at the location (x, y) using the provided paint and font. The text will\n * be drawn as is; no shaping, left-to-right, etc.\n * @param str\n * @param x\n * @param y\n * @param paint\n * @param font\n */\n drawText(\n str: string,\n x: number,\n y: number,\n paint: SkPaint,\n font: SkFont\n ): void;\n\n /**\n * Draws the given TextBlob at (x, y) using the current clip, current matrix, and the\n * provided paint. Reminder that the fonts used to draw TextBlob are part of the blob.\n * @param blob\n * @param x\n * @param y\n * @param paint\n */\n drawTextBlob(blob: SkTextBlob, x: number, y: number, paint: SkPaint): void;\n\n /**\n * Draws a run of glyphs, at corresponding positions, in a given font.\n * @param glyphs the array of glyph IDs (Uint16TypedArray)\n * @param positions the array of x,y floats to position each glyph\n * @param x x-coordinate of the origin of the entire run\n * @param y y-coordinate of the origin of the entire run\n * @param font the font that contains the glyphs\n * @param paint\n */\n drawGlyphs(\n glyphs: number[],\n positions: SkPoint[],\n x: number,\n y: number,\n font: SkFont,\n paint: SkPaint\n ): void;\n\n /**\n * Renders the SVG Dom object to the canvas. If width/height are omitted,\n * the SVG will be rendered to fit the canvas.\n */\n drawSvg: (svgDom: SkSVG, width?: number, height?: number) => void;\n /** Saves SkMatrix and clip.\n Calling restore() discards changes to SkMatrix and clip,\n restoring the SkMatrix and clip to their state when save() was called.\n\n SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(),\n and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().\n\n Saved SkCanvas state is put on a stack; multiple calls to save() should be balance\n by an equal number of calls to restore().\n\n Call restoreToCount() with result to restore this and subsequent saves.\n\n @return depth of saved stack\n\n example: https://fiddle.skia.org/c/@Canvas_save\n */\n save: () => number;\n\n /**\n * Saves Matrix and clip, and allocates a SkBitmap for subsequent drawing.\n * Calling restore() discards changes to Matrix and clip, and draws the SkBitmap.\n * It returns the height of the stack.\n * See Canvas.h for more.\n * @param paint\n * @param bounds\n * @param backdrop\n * @param flags\n */\n saveLayer(\n paint?: SkPaint,\n bounds?: SkRect | null,\n backdrop?: SkImageFilter | null,\n flags?: SaveLayerFlag\n ): number;\n\n /** Removes changes to SkMatrix and clip since SkCanvas state was\n last saved. The state is removed from the stack.\n\n Does nothing if the stack is empty.\n\n example: https://fiddle.skia.org/c/@AutoCanvasRestore_restore\n\n example: https://fiddle.skia.org/c/@Canvas_restore\n */\n restore: () => void;\n\n /**\n * Rotates the current matrix by the number of degrees.\n * @param rot - angle of rotation in degrees.\n * @param rx\n * @param ry\n */\n rotate(rotationInDegrees: number, rx: number, ry: number): void;\n\n /**\n * Scales the current matrix by sx on the x-axis and sy on the y-axis.\n * @param sx\n * @param sy\n */\n scale(sx: number, sy: number): void;\n\n /**\n * Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx\n * skews the drawing right as y-axis values increase; a positive value of sy skews\n * the drawing down as x-axis values increase.\n * @param sx\n * @param sy\n */\n skew(sx: number, sy: number): void;\n\n /**\n * Translates Matrix by dx along the x-axis and dy along the y-axis.\n * @param dx\n * @param dy\n */\n translate(dx: number, dy: number): void;\n\n /**\n * Fills clip with the given color.\n * @param color\n * @param blendMode - defaults to SrcOver.\n */\n drawColor(color: SkColor, blendMode?: BlendMode): void;\n\n /**\n * Fills the current clip with the given color using Src BlendMode.\n * This has the effect of replacing all pixels contained by clip with color.\n * @param color\n */\n clear(color: SkColor): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and path,\n * with an aliased or anti-aliased clip edge.\n * @param path\n * @param op\n * @param doAntiAlias\n */\n clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rect,\n * with an aliased or anti-aliased clip edge.\n * @param rect\n * @param op\n * @param doAntiAlias\n */\n clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces clip with the intersection or difference of the current clip and rrect,\n * with an aliased or anti-aliased clip edge.\n * @param rrect\n * @param op\n * @param doAntiAlias\n */\n clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean): void;\n\n /**\n * Replaces current matrix with m premultiplied with the existing matrix.\n * @param m\n */\n concat(m: SkMatrix | number[]): void;\n\n /**\n * Draws the given picture using the current clip, current matrix, and the provided paint.\n * @param skp\n */\n drawPicture(skp: SkPicture): void;\n\n /** Read Image pixels\n *\n * @param srcX - x-axis upper left corner of the rectangle to read from\n * @param srcY - y-axis upper left corner of the rectangle to read from\n * @param imageInfo - describes the pixel format and dimensions of the data to read into\n * @return Float32Array or Uint8Array with data or null if the read failed.\n */\n readPixels(\n srcX: number,\n srcY: number,\n imageInfo: ImageInfo\n ): Float32Array | Uint8Array | null;\n}\n"],"mappings":"AAgBA,WAAYA,MAAZ;;WAAYA,M;EAAAA,M,CAAAA,M;EAAAA,M,CAAAA,M;GAAAA,M,KAAAA,M;;AAKZ,WAAYC,aAAZ;;WAAYA,a;EAAAA,a,CAAAA,a;EAAAA,a,CAAAA,a;GAAAA,a,KAAAA,a"}
@@ -1,5 +1,6 @@
1
1
  import type { SkJSIInstance } from "./JsiInstance";
2
2
  import type { SkCanvas } from "./Canvas";
3
+ import type { Transforms3d } from "./Matrix4";
3
4
  export declare enum MatrixIndex {
4
5
  ScaleX = 0,
5
6
  SkewX = 1,
@@ -13,7 +14,7 @@ export declare enum MatrixIndex {
13
14
  }
14
15
  export declare const isMatrix: (obj: unknown) => obj is SkMatrix;
15
16
  export interface SkMatrix extends SkJSIInstance<"Matrix"> {
16
- concat: (matrix: SkMatrix) => SkMatrix;
17
+ concat: (matrix: SkMatrix | number[]) => SkMatrix;
17
18
  translate: (x: number, y: number) => SkMatrix;
18
19
  scale: (x: number, y?: number) => SkMatrix;
19
20
  skew: (x: number, y: number) => SkMatrix;
@@ -25,14 +26,8 @@ export interface SkMatrix extends SkJSIInstance<"Matrix"> {
25
26
  identity: () => SkMatrix;
26
27
  get: () => number[];
27
28
  }
28
- type Transform2dName = "translateX" | "translateY" | "scale" | "skewX" | "skewY" | "scaleX" | "scaleY" | "rotateZ" | "rotate";
29
- type Transformations = {
30
- readonly [Name in Transform2dName]: number;
31
- };
32
- export type Transforms2d = readonly (Pick<Transformations, "translateX"> | Pick<Transformations, "translateY"> | Pick<Transformations, "scale"> | Pick<Transformations, "scaleX"> | Pick<Transformations, "scaleY"> | Pick<Transformations, "skewX"> | Pick<Transformations, "skewY"> | Pick<Transformations, "rotate">)[];
33
29
  export interface TransformProp {
34
- transform?: Transforms2d;
30
+ transform?: Transforms3d;
35
31
  }
36
- export declare const processTransform: <T extends SkMatrix | SkCanvas>(m: T, transforms: Transforms2d) => T;
32
+ export declare const processTransform: <T extends SkMatrix | SkCanvas>(m: T, transforms: Transforms3d) => T;
37
33
  export declare const toDegrees: (rad: number) => number;
38
- export {};
@@ -1,3 +1,4 @@
1
+ import { processTransform3d } from "./Matrix4";
1
2
  export let MatrixIndex;
2
3
 
3
4
  (function (MatrixIndex) {
@@ -14,65 +15,10 @@ export let MatrixIndex;
14
15
 
15
16
  export const isMatrix = obj => obj !== null && obj.__typename__ === "Matrix";
16
17
  export const processTransform = (m, transforms) => {
17
- for (const transform of transforms) {
18
- const key = Object.keys(transform)[0];
19
- const value = transform[key];
20
-
21
- if (key === "translateX") {
22
- m.translate(value, 0);
23
- continue;
24
- }
25
-
26
- if (key === "translateY") {
27
- m.translate(0, value);
28
- continue;
29
- }
30
-
31
- if (key === "scale") {
32
- m.scale(value, value);
33
- continue;
34
- }
35
-
36
- if (key === "scaleX") {
37
- m.scale(value, 1);
38
- continue;
39
- }
40
-
41
- if (key === "scaleY") {
42
- m.scale(1, value);
43
- continue;
44
- }
45
-
46
- if (key === "skewX") {
47
- m.skew(value, 0);
48
- continue;
49
- }
50
-
51
- if (key === "skewY") {
52
- m.skew(0, value);
53
- continue;
54
- }
55
-
56
- if (key === "rotate" || key === "rotateZ") {
57
- if (isMatrix(m)) {
58
- m.rotate(value);
59
- } else {
60
- m.rotate(toDegrees(value), 0, 0);
61
- }
62
-
63
- continue;
64
- }
65
-
66
- exhaustiveCheck(key);
67
- }
68
-
18
+ const m3 = processTransform3d(transforms);
19
+ m.concat(m3);
69
20
  return m;
70
21
  };
71
-
72
- const exhaustiveCheck = a => {
73
- throw new Error(`Unknown transformation: ${a}`);
74
- };
75
-
76
22
  export const toDegrees = rad => {
77
23
  return rad * 180 / Math.PI;
78
24
  };
@@ -1 +1 @@
1
- {"version":3,"names":["MatrixIndex","isMatrix","obj","__typename__","processTransform","m","transforms","transform","key","Object","keys","value","translate","scale","skew","rotate","toDegrees","exhaustiveCheck","a","Error","rad","Math","PI"],"sources":["Matrix.ts"],"sourcesContent":["import type { SkJSIInstance } from \"./JsiInstance\";\nimport type { SkCanvas } from \"./Canvas\";\nexport enum MatrixIndex {\n ScaleX = 0,\n SkewX = 1,\n TransX = 2,\n SkewY = 3,\n ScaleY = 4,\n TransY = 5,\n Persp0 = 6,\n Persp1 = 7,\n Persp2 = 8,\n}\n\nexport const isMatrix = (obj: unknown): obj is SkMatrix =>\n obj !== null && (obj as SkJSIInstance<string>).__typename__ === \"Matrix\";\n\nexport interface SkMatrix extends SkJSIInstance<\"Matrix\"> {\n concat: (matrix: SkMatrix) => SkMatrix;\n translate: (x: number, y: number) => SkMatrix;\n scale: (x: number, y?: number) => SkMatrix;\n skew: (x: number, y: number) => SkMatrix;\n rotate: (theta: number) => SkMatrix;\n postTranslate: (x: number, y: number) => SkMatrix;\n postScale: (x: number, y?: number) => SkMatrix;\n postSkew: (x: number, y: number) => SkMatrix;\n postRotate: (theta: number) => SkMatrix;\n identity: () => SkMatrix;\n get: () => number[];\n}\n\ntype Transform2dName =\n | \"translateX\"\n | \"translateY\"\n | \"scale\"\n | \"skewX\"\n | \"skewY\"\n | \"scaleX\"\n | \"scaleY\"\n | \"rotateZ\"\n | \"rotate\";\n\ntype Transformations = {\n readonly [Name in Transform2dName]: number;\n};\n\nexport type Transforms2d = readonly (\n | Pick<Transformations, \"translateX\">\n | Pick<Transformations, \"translateY\">\n | Pick<Transformations, \"scale\">\n | Pick<Transformations, \"scaleX\">\n | Pick<Transformations, \"scaleY\">\n | Pick<Transformations, \"skewX\">\n | Pick<Transformations, \"skewY\">\n | Pick<Transformations, \"rotate\">\n)[];\n\nexport interface TransformProp {\n transform?: Transforms2d;\n}\n\nexport const processTransform = <T extends SkMatrix | SkCanvas>(\n m: T,\n transforms: Transforms2d\n) => {\n for (const transform of transforms) {\n const key = Object.keys(transform)[0] as Transform2dName;\n const value = (transform as Pick<Transformations, typeof key>)[key];\n if (key === \"translateX\") {\n m.translate(value, 0);\n continue;\n }\n if (key === \"translateY\") {\n m.translate(0, value);\n continue;\n }\n if (key === \"scale\") {\n m.scale(value, value);\n continue;\n }\n if (key === \"scaleX\") {\n m.scale(value, 1);\n continue;\n }\n if (key === \"scaleY\") {\n m.scale(1, value);\n continue;\n }\n if (key === \"skewX\") {\n m.skew(value, 0);\n continue;\n }\n if (key === \"skewY\") {\n m.skew(0, value);\n continue;\n }\n if (key === \"rotate\" || key === \"rotateZ\") {\n if (isMatrix(m)) {\n m.rotate(value);\n } else {\n m.rotate(toDegrees(value), 0, 0);\n }\n continue;\n }\n exhaustiveCheck(key);\n }\n return m;\n};\n\nconst exhaustiveCheck = (a: never): never => {\n throw new Error(`Unknown transformation: ${a}`);\n};\n\nexport const toDegrees = (rad: number) => {\n return (rad * 180) / Math.PI;\n};\n"],"mappings":"AAEA,WAAYA,WAAZ;;WAAYA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;GAAAA,W,KAAAA,W;;AAYZ,OAAO,MAAMC,QAAQ,GAAIC,GAAD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SAAS,CAACL,KAAD,CAAlB,EAA2B,CAA3B,EAA8B,CAA9B;MACD;;MACD;IACD;;IACDM,eAAe,CAACT,GAAD,CAAf;EACD;;EACD,OAAOH,CAAP;AACD,CA9CM;;AAgDP,MAAMY,eAAe,GAAIC,CAAD,IAAqB;EAC3C,MAAM,IAAIC,KAAJ,CAAW,2BAA0BD,CAAE,EAAvC,CAAN;AACD,CAFD;;AAIA,OAAO,MAAMF,SAAS,GAAII,GAAD,IAAiB;EACxC,OAAQA,GAAG,GAAG,GAAP,GAAcC,IAAI,CAACC,EAA1B;AACD,CAFM"}
1
+ {"version":3,"names":["processTransform3d","MatrixIndex","isMatrix","obj","__typename__","processTransform","m","transforms","m3","concat","toDegrees","rad","Math","PI"],"sources":["Matrix.ts"],"sourcesContent":["import type { SkJSIInstance } from \"./JsiInstance\";\nimport type { SkCanvas } from \"./Canvas\";\nimport type { Transforms3d } from \"./Matrix4\";\nimport { processTransform3d } from \"./Matrix4\";\nexport enum MatrixIndex {\n ScaleX = 0,\n SkewX = 1,\n TransX = 2,\n SkewY = 3,\n ScaleY = 4,\n TransY = 5,\n Persp0 = 6,\n Persp1 = 7,\n Persp2 = 8,\n}\n\nexport const isMatrix = (obj: unknown): obj is SkMatrix =>\n obj !== null && (obj as SkJSIInstance<string>).__typename__ === \"Matrix\";\n\nexport interface SkMatrix extends SkJSIInstance<\"Matrix\"> {\n concat: (matrix: SkMatrix | number[]) => SkMatrix;\n translate: (x: number, y: number) => SkMatrix;\n scale: (x: number, y?: number) => SkMatrix;\n skew: (x: number, y: number) => SkMatrix;\n rotate: (theta: number) => SkMatrix;\n postTranslate: (x: number, y: number) => SkMatrix;\n postScale: (x: number, y?: number) => SkMatrix;\n postSkew: (x: number, y: number) => SkMatrix;\n postRotate: (theta: number) => SkMatrix;\n identity: () => SkMatrix;\n get: () => number[];\n}\n\nexport interface TransformProp {\n transform?: Transforms3d;\n}\n\nexport const processTransform = <T extends SkMatrix | SkCanvas>(\n m: T,\n transforms: Transforms3d\n) => {\n const m3 = processTransform3d(transforms);\n m.concat(m3);\n return m;\n};\n\nexport const toDegrees = (rad: number) => {\n return (rad * 180) / Math.PI;\n};\n"],"mappings":"AAGA,SAASA,kBAAT,QAAmC,WAAnC;AACA,WAAYC,WAAZ;;WAAYA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;GAAAA,W,KAAAA,W;;AAYZ,OAAO,MAAMC,QAAQ,GAAIC,GAAD,IACtBA,GAAG,KAAK,IAAR,IAAiBA,GAAD,CAA+BC,YAA/B,KAAgD,QAD3D;AAqBP,OAAO,MAAMC,gBAAgB,GAAG,CAC9BC,CAD8B,EAE9BC,UAF8B,KAG3B;EACH,MAAMC,EAAE,GAAGR,kBAAkB,CAACO,UAAD,CAA7B;EACAD,CAAC,CAACG,MAAF,CAASD,EAAT;EACA,OAAOF,CAAP;AACD,CAPM;AASP,OAAO,MAAMI,SAAS,GAAIC,GAAD,IAAiB;EACxC,OAAQA,GAAG,GAAG,GAAP,GAAcC,IAAI,CAACC,EAA1B;AACD,CAFM"}
@@ -0,0 +1,39 @@
1
+ type Vec2 = readonly [number, number];
2
+ type Vec3 = readonly [number, number, number];
3
+ export type Matrix4 = readonly [
4
+ number,
5
+ number,
6
+ number,
7
+ number,
8
+ number,
9
+ number,
10
+ number,
11
+ number,
12
+ number,
13
+ number,
14
+ number,
15
+ number,
16
+ number,
17
+ number,
18
+ number,
19
+ number
20
+ ];
21
+ type Transform3dName = "translateX" | "translateY" | "translateZ" | "translate" | "scale" | "scaleX" | "scaleY" | "skewX" | "skewY" | "rotateZ" | "rotate" | "perspective" | "rotateX" | "rotateY" | "matrix";
22
+ type Transformations = {
23
+ [Name in Transform3dName]: Name extends "matrix" ? Matrix4 : Name extends "translate" ? Vec3 | Vec2 : number;
24
+ };
25
+ type Transform3d = Pick<Transformations, "translateX"> | Pick<Transformations, "translateY"> | Pick<Transformations, "translateZ"> | Pick<Transformations, "translate"> | Pick<Transformations, "scale"> | Pick<Transformations, "scaleX"> | Pick<Transformations, "scaleY"> | Pick<Transformations, "skewX"> | Pick<Transformations, "skewY"> | Pick<Transformations, "perspective"> | Pick<Transformations, "rotateX"> | Pick<Transformations, "rotateY"> | Pick<Transformations, "rotateZ"> | Pick<Transformations, "rotate"> | Pick<Transformations, "matrix">;
26
+ export type Transforms3d = Transform3d[];
27
+ /**
28
+ * @worklet
29
+ */
30
+ export declare const Matrix4: () => Matrix4;
31
+ /**
32
+ * @worklet
33
+ */
34
+ export declare const mapPoint3d: (m: Matrix4, v: Vec3) => readonly [number, number, number];
35
+ /**
36
+ * @worklet
37
+ */
38
+ export declare const processTransform3d: (transforms: Transforms3d) => number[];
39
+ export {};
@@ -0,0 +1,200 @@
1
+ const exhaustiveCheck = a => {
2
+ "worklet";
3
+
4
+ throw new Error(`Unexhaustive handling for ${a}`);
5
+ };
6
+ /**
7
+ * @worklet
8
+ */
9
+
10
+
11
+ export const Matrix4 = () => {
12
+ "worklet";
13
+
14
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
15
+ };
16
+
17
+ const translate = (x, y, z) => {
18
+ "worklet";
19
+
20
+ return [1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1];
21
+ };
22
+
23
+ const scale = (sx, sy, sz) => {
24
+ "worklet";
25
+
26
+ return [sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1];
27
+ };
28
+
29
+ const perspective = p => {
30
+ "worklet";
31
+
32
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -1 / p, 1];
33
+ };
34
+
35
+ const normalizeVec = vec => {
36
+ "worklet";
37
+
38
+ const [x, y, z] = vec;
39
+ const length = Math.sqrt(x * x + y * y + z * z); // Check for zero length to avoid division by zero
40
+
41
+ if (length === 0) {
42
+ return [0, 0, 0];
43
+ }
44
+
45
+ return [x / length, y / length, z / length];
46
+ };
47
+
48
+ const rotatedUnitSinCos = (axisVec, sinAngle, cosAngle) => {
49
+ "worklet";
50
+
51
+ const x = axisVec[0];
52
+ const y = axisVec[1];
53
+ const z = axisVec[2];
54
+ const c = cosAngle;
55
+ const s = sinAngle;
56
+ const t = 1 - c;
57
+ return [t * x * x + c, t * x * y - s * z, t * x * z + s * y, 0, t * x * y + s * z, t * y * y + c, t * y * z - s * x, 0, t * x * z - s * y, t * y * z + s * x, t * z * z + c, 0, 0, 0, 0, 1];
58
+ };
59
+
60
+ const rotate = (axis, value) => {
61
+ "worklet";
62
+
63
+ return rotatedUnitSinCos(normalizeVec(axis), Math.sin(value), Math.cos(value));
64
+ };
65
+
66
+ const matrixVecMul4 = (m, v) => {
67
+ "worklet";
68
+
69
+ const [vx, vy, vz, vw] = v;
70
+ return [vx * m[0] + vy * m[4] + vz * m[8] + vw * m[12], vx * m[1] + vy * m[5] + vz * m[9] + vw * m[13], vx * m[2] + vy * m[6] + vz * m[10] + vw * m[14], vx * m[3] + vy * m[7] + vz * m[11] + vw * m[15]];
71
+ };
72
+ /**
73
+ * @worklet
74
+ */
75
+
76
+
77
+ export const mapPoint3d = (m, v) => {
78
+ "worklet";
79
+
80
+ const r = matrixVecMul4(m, [...v, 1]);
81
+ return [r[0] / r[3], r[1] / r[3], r[2] / r[3]];
82
+ };
83
+
84
+ const multiply4 = (a, b) => {
85
+ "worklet";
86
+
87
+ const result = new Array(16).fill(0);
88
+
89
+ for (let i = 0; i < 4; i++) {
90
+ for (let j = 0; j < 4; j++) {
91
+ result[i * 4 + j] = a[i * 4] * b[j] + a[i * 4 + 1] * b[j + 4] + a[i * 4 + 2] * b[j + 8] + a[i * 4 + 3] * b[j + 12];
92
+ }
93
+ }
94
+
95
+ return result;
96
+ };
97
+
98
+ const skewY = angle => {
99
+ "worklet";
100
+
101
+ return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
102
+ };
103
+
104
+ const skewX = angle => {
105
+ "worklet";
106
+
107
+ return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
108
+ };
109
+
110
+ const toMatrix3 = m => {
111
+ "worklet";
112
+
113
+ return [m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]];
114
+ };
115
+ /**
116
+ * @worklet
117
+ */
118
+
119
+
120
+ export const processTransform3d = transforms => {
121
+ "worklet";
122
+
123
+ return toMatrix3(transforms.reduce((acc, val) => {
124
+ const key = Object.keys(val)[0];
125
+ const transform = val;
126
+
127
+ if (key === "translateX") {
128
+ const value = transform[key];
129
+ return multiply4(acc, translate(value, 0, 0));
130
+ }
131
+
132
+ if (key === "translate") {
133
+ const [x, y, z = 0] = transform[key];
134
+ return multiply4(acc, translate(x, y, z));
135
+ }
136
+
137
+ if (key === "translateY") {
138
+ const value = transform[key];
139
+ return multiply4(acc, translate(0, value, 0));
140
+ }
141
+
142
+ if (key === "translateZ") {
143
+ const value = transform[key];
144
+ return multiply4(acc, translate(0, 0, value));
145
+ }
146
+
147
+ if (key === "scale") {
148
+ const value = transform[key];
149
+ return multiply4(acc, scale(value, value, 1));
150
+ }
151
+
152
+ if (key === "scaleX") {
153
+ const value = transform[key];
154
+ return multiply4(acc, scale(value, 1, 1));
155
+ }
156
+
157
+ if (key === "scaleY") {
158
+ const value = transform[key];
159
+ return multiply4(acc, scale(1, value, 1));
160
+ }
161
+
162
+ if (key === "skewX") {
163
+ const value = transform[key];
164
+ return multiply4(acc, skewX(value));
165
+ }
166
+
167
+ if (key === "skewY") {
168
+ const value = transform[key];
169
+ return multiply4(acc, skewY(value));
170
+ }
171
+
172
+ if (key === "rotateX") {
173
+ const value = transform[key];
174
+ return multiply4(acc, rotate([1, 0, 0], value));
175
+ }
176
+
177
+ if (key === "rotateY") {
178
+ const value = transform[key];
179
+ return multiply4(acc, rotate([0, 1, 0], value));
180
+ }
181
+
182
+ if (key === "perspective") {
183
+ const value = transform[key];
184
+ return multiply4(acc, perspective(value));
185
+ }
186
+
187
+ if (key === "rotate" || key === "rotateZ") {
188
+ const value = transform[key];
189
+ return multiply4(acc, rotate([0, 0, 1], value));
190
+ }
191
+
192
+ if (key === "matrix") {
193
+ const value = transform[key];
194
+ return multiply4(acc, value);
195
+ }
196
+
197
+ return exhaustiveCheck(key);
198
+ }, Matrix4()));
199
+ };
200
+ //# sourceMappingURL=Matrix4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["exhaustiveCheck","a","Error","Matrix4","translate","x","y","z","scale","sx","sy","sz","perspective","p","normalizeVec","vec","length","Math","sqrt","rotatedUnitSinCos","axisVec","sinAngle","cosAngle","c","s","t","rotate","axis","value","sin","cos","matrixVecMul4","m","v","vx","vy","vz","vw","mapPoint3d","r","multiply4","b","result","Array","fill","i","j","skewY","angle","tan","skewX","toMatrix3","processTransform3d","transforms","reduce","acc","val","key","Object","keys","transform"],"sources":["Matrix4.ts"],"sourcesContent":["type Vec2 = readonly [number, number];\ntype Vec3 = readonly [number, number, number];\ntype Vec4 = readonly [number, number, number, number];\n\nexport type Matrix4 = readonly [\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number\n];\n\ntype Transform3dName =\n | \"translateX\"\n | \"translateY\"\n | \"translateZ\"\n | \"translate\"\n | \"scale\"\n | \"scaleX\"\n | \"scaleY\"\n | \"skewX\"\n | \"skewY\"\n | \"rotateZ\"\n | \"rotate\"\n | \"perspective\"\n | \"rotateX\"\n | \"rotateY\"\n | \"matrix\";\n\ntype Transformations = {\n [Name in Transform3dName]: Name extends \"matrix\"\n ? Matrix4\n : Name extends \"translate\"\n ? Vec3 | Vec2\n : number;\n};\n\ntype Transform3d =\n | Pick<Transformations, \"translateX\">\n | Pick<Transformations, \"translateY\">\n | Pick<Transformations, \"translateZ\">\n | Pick<Transformations, \"translate\">\n | Pick<Transformations, \"scale\">\n | Pick<Transformations, \"scaleX\">\n | Pick<Transformations, \"scaleY\">\n | Pick<Transformations, \"skewX\">\n | Pick<Transformations, \"skewY\">\n | Pick<Transformations, \"perspective\">\n | Pick<Transformations, \"rotateX\">\n | Pick<Transformations, \"rotateY\">\n | Pick<Transformations, \"rotateZ\">\n | Pick<Transformations, \"rotate\">\n | Pick<Transformations, \"matrix\">;\n\nexport type Transforms3d = Transform3d[];\n\nconst exhaustiveCheck = (a: never): never => {\n \"worklet\";\n throw new Error(`Unexhaustive handling for ${a}`);\n};\n\n/**\n * @worklet\n */\nexport const Matrix4 = (): Matrix4 => {\n \"worklet\";\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n};\n\nconst translate = (x: number, y: number, z: number): Matrix4 => {\n \"worklet\";\n return [1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1];\n};\n\nconst scale = (sx: number, sy: number, sz: number): Matrix4 => {\n \"worklet\";\n return [sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1];\n};\n\nconst perspective = (p: number): Matrix4 => {\n \"worklet\";\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -1 / p, 1];\n};\n\nconst normalizeVec = (vec: Vec3): Vec3 => {\n \"worklet\";\n const [x, y, z] = vec;\n const length = Math.sqrt(x * x + y * y + z * z);\n // Check for zero length to avoid division by zero\n if (length === 0) {\n return [0, 0, 0];\n }\n return [x / length, y / length, z / length];\n};\n\nconst rotatedUnitSinCos = (\n axisVec: Vec3,\n sinAngle: number,\n cosAngle: number\n): Matrix4 => {\n \"worklet\";\n const x = axisVec[0];\n const y = axisVec[1];\n const z = axisVec[2];\n const c = cosAngle;\n const s = sinAngle;\n const t = 1 - c;\n return [\n t * x * x + c,\n t * x * y - s * z,\n t * x * z + s * y,\n 0,\n t * x * y + s * z,\n t * y * y + c,\n t * y * z - s * x,\n 0,\n t * x * z - s * y,\n t * y * z + s * x,\n t * z * z + c,\n 0,\n 0,\n 0,\n 0,\n 1,\n ];\n};\n\nconst rotate = (axis: Vec3, value: number) => {\n \"worklet\";\n return rotatedUnitSinCos(\n normalizeVec(axis),\n Math.sin(value),\n Math.cos(value)\n );\n};\n\nconst matrixVecMul4 = (m: Matrix4, v: Vec4) => {\n \"worklet\";\n const [vx, vy, vz, vw] = v;\n return [\n vx * m[0] + vy * m[4] + vz * m[8] + vw * m[12],\n vx * m[1] + vy * m[5] + vz * m[9] + vw * m[13],\n vx * m[2] + vy * m[6] + vz * m[10] + vw * m[14],\n vx * m[3] + vy * m[7] + vz * m[11] + vw * m[15],\n ];\n};\n\n/**\n * @worklet\n */\nexport const mapPoint3d = (m: Matrix4, v: Vec3) => {\n \"worklet\";\n const r = matrixVecMul4(m, [...v, 1]);\n return [r[0] / r[3], r[1] / r[3], r[2] / r[3]] as const;\n};\n\nconst multiply4 = (a: Matrix4, b: Matrix4): Matrix4 => {\n \"worklet\";\n const result = new Array(16).fill(0);\n for (let i = 0; i < 4; i++) {\n for (let j = 0; j < 4; j++) {\n result[i * 4 + j] =\n a[i * 4] * b[j] +\n a[i * 4 + 1] * b[j + 4] +\n a[i * 4 + 2] * b[j + 8] +\n a[i * 4 + 3] * b[j + 12];\n }\n }\n return result as unknown as Matrix4;\n};\n\nconst skewY = (angle: number): Matrix4 => {\n \"worklet\";\n return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n};\n\nconst skewX = (angle: number): Matrix4 => {\n \"worklet\";\n return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n};\n\nconst toMatrix3 = (m: Matrix4) => {\n \"worklet\";\n return [m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]];\n};\n\n/**\n * @worklet\n */\nexport const processTransform3d = (transforms: Transforms3d) => {\n \"worklet\";\n return toMatrix3(\n transforms.reduce((acc, val) => {\n const key = Object.keys(val)[0] as Transform3dName;\n const transform = val as Pick<Transformations, typeof key>;\n if (key === \"translateX\") {\n const value = transform[key];\n return multiply4(acc, translate(value, 0, 0));\n }\n if (key === \"translate\") {\n const [x, y, z = 0] = transform[key];\n return multiply4(acc, translate(x, y, z));\n }\n if (key === \"translateY\") {\n const value = transform[key];\n return multiply4(acc, translate(0, value, 0));\n }\n if (key === \"translateZ\") {\n const value = transform[key];\n return multiply4(acc, translate(0, 0, value));\n }\n if (key === \"scale\") {\n const value = transform[key];\n return multiply4(acc, scale(value, value, 1));\n }\n if (key === \"scaleX\") {\n const value = transform[key];\n return multiply4(acc, scale(value, 1, 1));\n }\n if (key === \"scaleY\") {\n const value = transform[key];\n return multiply4(acc, scale(1, value, 1));\n }\n if (key === \"skewX\") {\n const value = transform[key];\n return multiply4(acc, skewX(value));\n }\n if (key === \"skewY\") {\n const value = transform[key];\n return multiply4(acc, skewY(value));\n }\n if (key === \"rotateX\") {\n const value = transform[key];\n return multiply4(acc, rotate([1, 0, 0], value));\n }\n if (key === \"rotateY\") {\n const value = transform[key];\n return multiply4(acc, rotate([0, 1, 0], value));\n }\n if (key === \"perspective\") {\n const value = transform[key];\n return multiply4(acc, perspective(value));\n }\n if (key === \"rotate\" || key === \"rotateZ\") {\n const value = transform[key];\n return multiply4(acc, rotate([0, 0, 1], value));\n }\n if (key === \"matrix\") {\n const value = transform[key];\n return multiply4(acc, value);\n }\n return exhaustiveCheck(key);\n }, Matrix4())\n );\n};\n"],"mappings":"AAmEA,MAAMA,eAAe,GAAIC,CAAD,IAAqB;EAC3C;;EACA,MAAM,IAAIC,KAAJ,CAAW,6BAA4BD,CAAE,EAAzC,CAAN;AACD,CAHD;AAKA;AACA;AACA;;;AACA,OAAO,MAAME,OAAO,GAAG,MAAe;EACpC;;EACA,OAAO,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,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AZ,EAA2B;MACzB,MAAM7B,KAAK,GAAGgC,SAAS,CAACH,GAAD,CAAvB;MACA,OAAOjB,SAAS,CAACe,GAAD,EAAM3C,WAAW,CAACgB,KAAD,CAAjB,CAAhB;IACD;;IACD,IAAI6B,GAAG,KAAK,QAAR,IAAoBA,GAAG,KAAK,SAAhC,EAA2C;MACzC,MAAM7B,KAAK,GAAGgC,SAAS,CAACH,GAAD,CAAvB;MACA,OAAOjB,SAAS,CAACe,GAAD,EAAM7B,MAAM,CAAC,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAD,EAAYE,KAAZ,CAAZ,CAAhB;IACD;;IACD,IAAI6B,GAAG,KAAK,QAAZ,EAAsB;MACpB,MAAM7B,KAAK,GAAGgC,SAAS,CAACH,GAAD,CAAvB;MACA,OAAOjB,SAAS,CAACe,GAAD,EAAM3B,KAAN,CAAhB;IACD;;IACD,OAAO5B,eAAe,CAACyD,GAAD,CAAtB;EACD,CA5DD,EA4DGtD,OAAO,EA5DV,CADc,CAAhB;AA+DD,CAjEM"}
@@ -440,7 +440,7 @@ export interface SkPath extends SkJSIInstance<"Path"> {
440
440
  /**
441
441
  * Transforms the path by the specified matrix.
442
442
  */
443
- transform(m3: SkMatrix): SkPath;
443
+ transform(m3: SkMatrix | number[]): SkPath;
444
444
  /**
445
445
  * Interpolates between Path with point array of equal size.
446
446
  * Copy verb array and weights to result, and set result path to a weighted