@shopify/react-native-skia 0.1.230 → 0.1.232

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. package/android/CMakeLists.txt +1 -0
  2. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +2 -2
  3. package/cpp/api/JsiSkAnimatedImage.h +1 -1
  4. package/cpp/api/JsiSkDataFactory.h +6 -6
  5. package/cpp/api/JsiSkImage.h +4 -4
  6. package/cpp/api/JsiSkPath.h +1 -1
  7. package/cpp/api/JsiSkRRect.h +30 -3
  8. package/cpp/api/third_party/base64.cpp +153 -0
  9. package/cpp/api/third_party/base64.h +50 -0
  10. package/cpp/jsi/JsiPromises.h +1 -1
  11. package/cpp/rnskia/dom/props/FontProp.h +2 -4
  12. package/cpp/rnskia/dom/props/RRectProp.h +50 -0
  13. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +1 -1
  14. package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +2 -1
  15. package/lib/commonjs/dom/nodes/datatypes/Rect.d.ts +1 -1
  16. package/lib/commonjs/dom/nodes/drawings/RRectNode.d.ts +3 -3
  17. package/lib/commonjs/dom/nodes/drawings/RRectNode.js.map +1 -1
  18. package/lib/commonjs/dom/nodes/drawings/Text.js +1 -11
  19. package/lib/commonjs/dom/nodes/drawings/Text.js.map +1 -1
  20. package/lib/commonjs/dom/types/Common.d.ts +2 -2
  21. package/lib/commonjs/dom/types/Common.js.map +1 -1
  22. package/lib/commonjs/dom/types/Drawings.d.ts +1 -1
  23. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  24. package/lib/commonjs/headless/index.d.ts +3 -1
  25. package/lib/commonjs/headless/index.js +12 -6
  26. package/lib/commonjs/headless/index.js.map +1 -1
  27. package/lib/commonjs/skia/types/Canvas.d.ts +4 -4
  28. package/lib/commonjs/skia/types/Canvas.js.map +1 -1
  29. package/lib/commonjs/skia/types/Matrix4.d.ts +5 -0
  30. package/lib/commonjs/skia/types/Matrix4.js +8 -3
  31. package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
  32. package/lib/commonjs/skia/types/Paragraph/Paragraph.d.ts +2 -2
  33. package/lib/commonjs/skia/types/Paragraph/Paragraph.js.map +1 -1
  34. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.d.ts +6 -6
  35. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js +25 -25
  36. package/lib/commonjs/skia/types/Paragraph/ParagraphStyle.js.map +1 -1
  37. package/lib/commonjs/skia/types/Path/Path.d.ts +2 -2
  38. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  39. package/lib/commonjs/skia/types/RRect.d.ts +9 -0
  40. package/lib/commonjs/skia/types/RRect.js.map +1 -1
  41. package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +4 -4
  42. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  43. package/lib/commonjs/skia/web/JsiSkParagraphStyle.js +1 -1
  44. package/lib/commonjs/skia/web/JsiSkParagraphStyle.js.map +1 -1
  45. package/lib/commonjs/skia/web/JsiSkPath.d.ts +2 -2
  46. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  47. package/lib/commonjs/skia/web/JsiSkRRect.d.ts +2 -2
  48. package/lib/commonjs/skia/web/JsiSkRRect.js +4 -0
  49. package/lib/commonjs/skia/web/JsiSkRRect.js.map +1 -1
  50. package/lib/commonjs/web/LoadSkiaWeb.js +4 -1
  51. package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -1
  52. package/lib/module/dom/nodes/JsiSkDOM.d.ts +2 -1
  53. package/lib/module/dom/nodes/datatypes/Rect.d.ts +1 -1
  54. package/lib/module/dom/nodes/drawings/RRectNode.d.ts +3 -3
  55. package/lib/module/dom/nodes/drawings/RRectNode.js.map +1 -1
  56. package/lib/module/dom/nodes/drawings/Text.js +1 -11
  57. package/lib/module/dom/nodes/drawings/Text.js.map +1 -1
  58. package/lib/module/dom/types/Common.d.ts +2 -2
  59. package/lib/module/dom/types/Common.js.map +1 -1
  60. package/lib/module/dom/types/Drawings.d.ts +1 -1
  61. package/lib/module/dom/types/Drawings.js.map +1 -1
  62. package/lib/module/headless/index.d.ts +3 -1
  63. package/lib/module/headless/index.js +5 -3
  64. package/lib/module/headless/index.js.map +1 -1
  65. package/lib/module/skia/types/Canvas.d.ts +4 -4
  66. package/lib/module/skia/types/Canvas.js.map +1 -1
  67. package/lib/module/skia/types/Matrix4.d.ts +5 -0
  68. package/lib/module/skia/types/Matrix4.js +6 -4
  69. package/lib/module/skia/types/Matrix4.js.map +1 -1
  70. package/lib/module/skia/types/Paragraph/Paragraph.d.ts +2 -2
  71. package/lib/module/skia/types/Paragraph/Paragraph.js.map +1 -1
  72. package/lib/module/skia/types/Paragraph/ParagraphStyle.d.ts +6 -6
  73. package/lib/module/skia/types/Paragraph/ParagraphStyle.js +21 -21
  74. package/lib/module/skia/types/Paragraph/ParagraphStyle.js.map +1 -1
  75. package/lib/module/skia/types/Path/Path.d.ts +2 -2
  76. package/lib/module/skia/types/Path/Path.js.map +1 -1
  77. package/lib/module/skia/types/RRect.d.ts +9 -0
  78. package/lib/module/skia/types/RRect.js.map +1 -1
  79. package/lib/module/skia/web/JsiSkCanvas.d.ts +4 -4
  80. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  81. package/lib/module/skia/web/JsiSkParagraphStyle.js +2 -2
  82. package/lib/module/skia/web/JsiSkParagraphStyle.js.map +1 -1
  83. package/lib/module/skia/web/JsiSkPath.d.ts +2 -2
  84. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  85. package/lib/module/skia/web/JsiSkRRect.d.ts +2 -2
  86. package/lib/module/skia/web/JsiSkRRect.js +4 -0
  87. package/lib/module/skia/web/JsiSkRRect.js.map +1 -1
  88. package/lib/module/web/LoadSkiaWeb.js +5 -1
  89. package/lib/module/web/LoadSkiaWeb.js.map +1 -1
  90. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -1
  91. package/lib/typescript/src/dom/nodes/datatypes/Rect.d.ts +1 -1
  92. package/lib/typescript/src/dom/nodes/drawings/RRectNode.d.ts +3 -3
  93. package/lib/typescript/src/dom/types/Common.d.ts +2 -2
  94. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -1
  95. package/lib/typescript/src/headless/index.d.ts +3 -1
  96. package/lib/typescript/src/skia/types/Canvas.d.ts +4 -4
  97. package/lib/typescript/src/skia/types/Matrix4.d.ts +5 -0
  98. package/lib/typescript/src/skia/types/Paragraph/Paragraph.d.ts +2 -2
  99. package/lib/typescript/src/skia/types/Paragraph/ParagraphStyle.d.ts +6 -6
  100. package/lib/typescript/src/skia/types/Path/Path.d.ts +2 -2
  101. package/lib/typescript/src/skia/types/RRect.d.ts +9 -0
  102. package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +4 -4
  103. package/lib/typescript/src/skia/web/JsiSkPath.d.ts +2 -2
  104. package/lib/typescript/src/skia/web/JsiSkRRect.d.ts +2 -2
  105. package/libs/android/arm64-v8a/libskia.a +0 -0
  106. package/libs/android/armeabi-v7a/libskia.a +0 -0
  107. package/libs/android/x86/libskia.a +0 -0
  108. package/libs/android/x86_64/libskia.a +0 -0
  109. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  110. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  111. package/libs/ios/libskottie.xcframework/Info.plist +5 -5
  112. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  113. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  114. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  115. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  116. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  117. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  118. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  119. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  120. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  121. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  122. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  123. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  124. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  125. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  126. package/package.json +1 -1
  127. package/src/dom/nodes/drawings/RRectNode.ts +2 -2
  128. package/src/dom/nodes/drawings/Text.ts +1 -14
  129. package/src/dom/types/Common.ts +2 -1
  130. package/src/dom/types/Drawings.ts +1 -1
  131. package/src/headless/index.ts +7 -3
  132. package/src/skia/types/Canvas.ts +4 -4
  133. package/src/skia/types/Matrix4.ts +8 -6
  134. package/src/skia/types/Paragraph/Paragraph.ts +2 -2
  135. package/src/skia/types/Paragraph/ParagraphStyle.ts +6 -6
  136. package/src/skia/types/Path/Path.ts +2 -2
  137. package/src/skia/types/RRect.ts +11 -0
  138. package/src/skia/web/JsiSkCanvas.ts +4 -4
  139. package/src/skia/web/JsiSkParagraphStyle.ts +2 -2
  140. package/src/skia/web/JsiSkPath.ts +2 -2
  141. package/src/skia/web/JsiSkRRect.ts +23 -2
  142. package/src/web/LoadSkiaWeb.tsx +4 -1
@@ -1,5 +1,5 @@
1
1
  import type { CanvasKit, Path } from "canvaskit-wasm";
2
- import type { FillType, PathCommand, PathOp, SkMatrix, SkPath, SkPoint, SkRect, SkRRect, StrokeOpts } from "../types";
2
+ import type { FillType, PathCommand, PathOp, SkMatrix, SkPath, SkPoint, SkRect, InputRRect, StrokeOpts } from "../types";
3
3
  import { HostObject } from "./Host";
4
4
  import { JsiSkPoint } from "./JsiSkPoint";
5
5
  import { JsiSkRect } from "./JsiSkRect";
@@ -41,7 +41,7 @@ export declare class JsiSkPath extends HostObject<Path, "Path"> implements SkPat
41
41
  getFillType(): number;
42
42
  quadTo(x1: number, y1: number, x2: number, y2: number): this;
43
43
  addRect(rect: SkRect, isCCW?: boolean): this;
44
- addRRect(rrect: SkRRect, isCCW?: boolean): this;
44
+ addRRect(rrect: InputRRect, isCCW?: boolean): this;
45
45
  getPoint(index: number): JsiSkPoint;
46
46
  isEmpty(): boolean;
47
47
  isVolatile(): boolean;
@@ -1,10 +1,10 @@
1
1
  import type { CanvasKit, RRect } from "canvaskit-wasm";
2
- import type { SkRect, SkRRect } from "../types";
2
+ import type { InputRRect, SkRect, SkRRect } from "../types";
3
3
  import { BaseHostObject } from "./Host";
4
4
  import { JsiSkRect } from "./JsiSkRect";
5
5
  export declare class JsiSkRRect extends BaseHostObject<RRect, "RRect"> implements SkRRect {
6
6
  dispose: () => void;
7
- static fromValue(CanvasKit: CanvasKit, rect: SkRRect): Float32Array;
7
+ static fromValue(CanvasKit: CanvasKit, rect: InputRRect): Float32Array;
8
8
  constructor(CanvasKit: CanvasKit, rect: SkRect, rx: number, ry: number);
9
9
  get rx(): number;
10
10
  get ry(): number;
Binary file
Binary file
Binary file
Binary file
@@ -6,32 +6,32 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64_arm64e_x86_64-simulator</string>
9
+ <string>ios-arm64_arm64e</string>
10
10
  <key>LibraryPath</key>
11
11
  <string>libskottie.a</string>
12
12
  <key>SupportedArchitectures</key>
13
13
  <array>
14
14
  <string>arm64</string>
15
15
  <string>arm64e</string>
16
- <string>x86_64</string>
17
16
  </array>
18
17
  <key>SupportedPlatform</key>
19
18
  <string>ios</string>
20
- <key>SupportedPlatformVariant</key>
21
- <string>simulator</string>
22
19
  </dict>
23
20
  <dict>
24
21
  <key>LibraryIdentifier</key>
25
- <string>ios-arm64_arm64e</string>
22
+ <string>ios-arm64_arm64e_x86_64-simulator</string>
26
23
  <key>LibraryPath</key>
27
24
  <string>libskottie.a</string>
28
25
  <key>SupportedArchitectures</key>
29
26
  <array>
30
27
  <string>arm64</string>
31
28
  <string>arm64e</string>
29
+ <string>x86_64</string>
32
30
  </array>
33
31
  <key>SupportedPlatform</key>
34
32
  <string>ios</string>
33
+ <key>SupportedPlatformVariant</key>
34
+ <string>simulator</string>
35
35
  </dict>
36
36
  </array>
37
37
  <key>CFBundlePackageType</key>
@@ -6,32 +6,32 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64_arm64e_x86_64-simulator</string>
9
+ <string>ios-arm64_arm64e</string>
10
10
  <key>LibraryPath</key>
11
11
  <string>libskshaper.a</string>
12
12
  <key>SupportedArchitectures</key>
13
13
  <array>
14
14
  <string>arm64</string>
15
15
  <string>arm64e</string>
16
- <string>x86_64</string>
17
16
  </array>
18
17
  <key>SupportedPlatform</key>
19
18
  <string>ios</string>
20
- <key>SupportedPlatformVariant</key>
21
- <string>simulator</string>
22
19
  </dict>
23
20
  <dict>
24
21
  <key>LibraryIdentifier</key>
25
- <string>ios-arm64_arm64e</string>
22
+ <string>ios-arm64_arm64e_x86_64-simulator</string>
26
23
  <key>LibraryPath</key>
27
24
  <string>libskshaper.a</string>
28
25
  <key>SupportedArchitectures</key>
29
26
  <array>
30
27
  <string>arm64</string>
31
28
  <string>arm64e</string>
29
+ <string>x86_64</string>
32
30
  </array>
33
31
  <key>SupportedPlatform</key>
34
32
  <string>ios</string>
33
+ <key>SupportedPlatformVariant</key>
34
+ <string>simulator</string>
35
35
  </dict>
36
36
  </array>
37
37
  <key>CFBundlePackageType</key>
@@ -6,32 +6,32 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64_arm64e_x86_64-simulator</string>
9
+ <string>ios-arm64_arm64e</string>
10
10
  <key>LibraryPath</key>
11
11
  <string>libsvg.a</string>
12
12
  <key>SupportedArchitectures</key>
13
13
  <array>
14
14
  <string>arm64</string>
15
15
  <string>arm64e</string>
16
- <string>x86_64</string>
17
16
  </array>
18
17
  <key>SupportedPlatform</key>
19
18
  <string>ios</string>
20
- <key>SupportedPlatformVariant</key>
21
- <string>simulator</string>
22
19
  </dict>
23
20
  <dict>
24
21
  <key>LibraryIdentifier</key>
25
- <string>ios-arm64_arm64e</string>
22
+ <string>ios-arm64_arm64e_x86_64-simulator</string>
26
23
  <key>LibraryPath</key>
27
24
  <string>libsvg.a</string>
28
25
  <key>SupportedArchitectures</key>
29
26
  <array>
30
27
  <string>arm64</string>
31
28
  <string>arm64e</string>
29
+ <string>x86_64</string>
32
30
  </array>
33
31
  <key>SupportedPlatform</key>
34
32
  <string>ios</string>
33
+ <key>SupportedPlatformVariant</key>
34
+ <string>simulator</string>
35
35
  </dict>
36
36
  </array>
37
37
  <key>CFBundlePackageType</key>
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "0.1.230",
10
+ "version": "0.1.232",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -1,11 +1,11 @@
1
- import type { SkRRect } from "../../../skia/types";
1
+ import type { InputRRect, SkRRect } from "../../../skia/types";
2
2
  import type { DrawingContext, RoundedRectProps } from "../../types";
3
3
  import { NodeType } from "../../types";
4
4
  import { processRRect } from "../datatypes";
5
5
  import { JsiDrawingNode } from "../DrawingNode";
6
6
  import type { NodeContext } from "../Node";
7
7
 
8
- export class RRectNode extends JsiDrawingNode<RoundedRectProps, SkRRect> {
8
+ export class RRectNode extends JsiDrawingNode<RoundedRectProps, InputRRect> {
9
9
  rect?: SkRRect;
10
10
 
11
11
  constructor(ctx: NodeContext, props: RoundedRectProps) {
@@ -23,21 +23,8 @@ export class TextNode extends JsiDrawingNode<TextProps, SkFont | null> {
23
23
 
24
24
  protected deriveProps() {
25
25
  const { font } = this.props;
26
- if (font === null) {
27
- return null;
28
- } else if (font === undefined) {
29
- console.warn(
30
- "<Text />: the font property is mandatory on React Native Web"
31
- );
26
+ if (!font) {
32
27
  return null;
33
- // return this.Skia.Font(
34
- // this.Skia.FontMgr.System().matchFamilyStyle("System", {
35
- // width: 5,
36
- // weight: 400,
37
- // slant: 0,
38
- // }),
39
- // 14
40
- // );
41
28
  }
42
29
  return font;
43
30
  }
@@ -4,6 +4,7 @@ import type {
4
4
  BlendMode,
5
5
  Color,
6
6
  InputMatrix,
7
+ InputRRect,
7
8
  PaintStyle,
8
9
  SkPaint,
9
10
  SkPath,
@@ -48,7 +49,7 @@ export interface RRectCtor extends RectCtor {
48
49
  }
49
50
 
50
51
  export type RectDef = RectCtor | { rect: SkRect };
51
- export type RRectDef = RRectCtor | { rect: SkRRect };
52
+ export type RRectDef = RRectCtor | { rect: InputRRect };
52
53
 
53
54
  export interface PointCircleDef {
54
55
  c?: Vector;
@@ -109,7 +109,7 @@ export interface DiffRectProps extends DrawingNodeProps {
109
109
  }
110
110
 
111
111
  export interface TextProps extends DrawingNodeProps {
112
- font?: SkFont | null;
112
+ font: SkFont | null;
113
113
  text: string;
114
114
  x: number;
115
115
  y: number;
@@ -6,13 +6,14 @@ import type { ReactNode } from "react";
6
6
  import { JsiSkApi } from "../skia/web";
7
7
  import { SkiaRoot } from "../renderer/Reconciler";
8
8
  import { JsiDrawingContext } from "../dom/types";
9
+ import type { SkSurface } from "../skia";
9
10
 
10
11
  export * from "../renderer/components";
11
12
 
12
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
14
  let Skia: any;
14
15
 
15
- export const draw = (element: ReactNode, width: number, height: number) => {
16
+ export const makeOffscreenSurface = (width: number, height: number) => {
16
17
  if (!Skia) {
17
18
  Skia = JsiSkApi(CanvasKit);
18
19
  }
@@ -20,12 +21,15 @@ export const draw = (element: ReactNode, width: number, height: number) => {
20
21
  if (surface === null) {
21
22
  throw new Error("Couldn't create surface!");
22
23
  }
24
+ return surface;
25
+ };
26
+
27
+ export const drawOffscreen = (surface: SkSurface, element: ReactNode) => {
23
28
  const root = new SkiaRoot(Skia);
24
29
  root.render(element);
25
30
  const canvas = surface.getCanvas();
26
31
  const ctx = new JsiDrawingContext(Skia, canvas);
27
32
  root.dom.render(ctx);
28
33
  surface.flush();
29
- const image = surface.makeImageSnapshot();
30
- return image;
34
+ return surface.makeImageSnapshot();
31
35
  };
@@ -5,7 +5,7 @@ import type { SkPath } from "./Path";
5
5
  import type { SkImage, MipmapMode, FilterMode, ImageInfo } from "./Image";
6
6
  import type { SkSVG } from "./SVG";
7
7
  import type { SkColor } from "./Color";
8
- import type { SkRRect } from "./RRect";
8
+ import type { InputRRect } from "./RRect";
9
9
  import type { BlendMode } from "./Paint/BlendMode";
10
10
  import type { SkPoint, PointMode } from "./Point";
11
11
  import type { InputMatrix } from "./Matrix";
@@ -278,7 +278,7 @@ export interface SkCanvas {
278
278
  * @param rrect
279
279
  * @param paint
280
280
  */
281
- drawRRect(rrect: SkRRect, paint: SkPaint): void;
281
+ drawRRect(rrect: InputRRect, paint: SkPaint): void;
282
282
 
283
283
  /**
284
284
  * Draws RRect outer and inner using clip, Matrix, and Paint paint.
@@ -287,7 +287,7 @@ export interface SkCanvas {
287
287
  * @param inner
288
288
  * @param paint
289
289
  */
290
- drawDRRect(outer: SkRRect, inner: SkRRect, paint: SkPaint): void;
290
+ drawDRRect(outer: InputRRect, inner: InputRRect, paint: SkPaint): void;
291
291
 
292
292
  /**
293
293
  * Draws an oval bounded by the given rectangle using the current clip, current matrix,
@@ -479,7 +479,7 @@ export interface SkCanvas {
479
479
  * @param op
480
480
  * @param doAntiAlias
481
481
  */
482
- clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean): void;
482
+ clipRRect(rrect: InputRRect, op: ClipOp, doAntiAlias: boolean): void;
483
483
 
484
484
  /**
485
485
  * Replaces current matrix with m premultiplied with the existing matrix.
@@ -150,14 +150,16 @@ const rotatedUnitSinCos = (
150
150
  ];
151
151
  };
152
152
 
153
- const matrixVecMul4 = (m: Matrix4, v: Vec4) => {
153
+ /**
154
+ * @worklet
155
+ */
156
+ export const matrixVecMul4 = (m: Matrix4, v: Vec4): Vec4 => {
154
157
  "worklet";
155
- const [vx, vy, vz, vw] = v;
156
158
  return [
157
- vx * m[0] + vy * m[4] + vz * m[8] + vw * m[12],
158
- vx * m[1] + vy * m[5] + vz * m[9] + vw * m[13],
159
- vx * m[2] + vy * m[6] + vz * m[10] + vw * m[14],
160
- vx * m[3] + vy * m[7] + vz * m[11] + vw * m[15],
159
+ m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3] * v[3],
160
+ m[4] * v[0] + m[5] * v[1] + m[6] * v[2] + m[7] * v[3],
161
+ m[8] * v[0] + m[9] * v[1] + m[10] * v[2] + m[11] * v[3],
162
+ m[12] * v[0] + m[13] * v[1] + m[14] * v[2] + m[15] * v[3],
161
163
  ];
162
164
  };
163
165
 
@@ -2,11 +2,11 @@ import type { SkCanvas } from "../Canvas";
2
2
  import type { SkJSIInstance } from "../JsiInstance";
3
3
  import type { SkRect } from "../Rect";
4
4
 
5
- import type { SkTextDirection } from "./ParagraphStyle";
5
+ import type { TextDirection } from "./ParagraphStyle";
6
6
 
7
7
  export interface SkRectWithDirection {
8
8
  rect: SkRect;
9
- direction: SkTextDirection;
9
+ direction: TextDirection;
10
10
  }
11
11
 
12
12
  export interface SkParagraph extends SkJSIInstance<"Paragraph"> {
@@ -1,10 +1,10 @@
1
1
  import type { SkTextFontStyle, SkTextStyle } from "./TextStyle";
2
2
 
3
- export enum SkTextDirection {
3
+ export enum TextDirection {
4
4
  RTL = 0,
5
5
  LTR = 1,
6
6
  }
7
- export enum SkTextAlign {
7
+ export enum TextAlign {
8
8
  Left = 0,
9
9
  Right,
10
10
  Center,
@@ -24,7 +24,7 @@ export interface SkStrutStyle {
24
24
  forceStrutHeight?: boolean;
25
25
  }
26
26
 
27
- export enum SkTextHeightBehavior {
27
+ export enum TextHeightBehavior {
28
28
  All = 0x0,
29
29
  DisableFirstAscent = 0x1,
30
30
  DisableLastDescent = 0x2,
@@ -38,8 +38,8 @@ export interface SkParagraphStyle {
38
38
  maxLines?: number;
39
39
  replaceTabCharacters?: boolean;
40
40
  strutStyle?: SkStrutStyle;
41
- textAlign?: SkTextAlign;
42
- textDirection?: SkTextDirection;
43
- textHeightBehavior?: SkTextHeightBehavior;
41
+ textAlign?: TextAlign;
42
+ textDirection?: TextDirection;
43
+ textHeightBehavior?: TextHeightBehavior;
44
44
  textStyle?: SkTextStyle;
45
45
  }
@@ -1,6 +1,6 @@
1
1
  import type { SkRect } from "../Rect";
2
2
  import type { SkPoint } from "../Point";
3
- import type { SkRRect } from "../RRect";
3
+ import type { InputRRect } from "../RRect";
4
4
  import type { StrokeJoin, StrokeCap } from "../Paint";
5
5
  import type { InputMatrix, SkMatrix } from "../Matrix";
6
6
  import type { SkJSIInstance } from "../JsiInstance";
@@ -439,7 +439,7 @@ export interface SkPath extends SkJSIInstance<"Path"> {
439
439
  * @param rrect
440
440
  * @param isCCW
441
441
  */
442
- addRRect(rrect: SkRRect, isCCW?: boolean): SkPath;
442
+ addRRect(rrect: InputRRect, isCCW?: boolean): SkPath;
443
443
 
444
444
  /** Appends src to SkPath, transformed by matrix. Transformed curves may have
445
445
  different verbs, SkPoint, and conic weights.
@@ -1,3 +1,4 @@
1
+ import type { SkPoint } from "./Point";
1
2
  import type { SkRect } from "./Rect";
2
3
 
3
4
  export interface SkRRect {
@@ -6,6 +7,16 @@ export interface SkRRect {
6
7
  readonly ry: number;
7
8
  }
8
9
 
10
+ export interface NonUniformRRect {
11
+ readonly rect: SkRect;
12
+ readonly topLeft: SkPoint;
13
+ readonly topRight: SkPoint;
14
+ readonly bottomRight: SkPoint;
15
+ readonly bottomLeft: SkPoint;
16
+ }
17
+
18
+ export type InputRRect = SkRRect | NonUniformRRect;
19
+
9
20
  // We have an issue to check property existence on JSI backed instances
10
21
  export const isRRect = (def: SkRect | SkRRect): def is SkRRect =>
11
22
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -19,7 +19,7 @@ import type {
19
19
  SkPicture,
20
20
  SkPoint,
21
21
  SkRect,
22
- SkRRect,
22
+ InputRRect,
23
23
  SkSVG,
24
24
  SkTextBlob,
25
25
  SkVertices,
@@ -235,14 +235,14 @@ export class JsiSkCanvas
235
235
  );
236
236
  }
237
237
 
238
- drawRRect(rrect: SkRRect, paint: SkPaint) {
238
+ drawRRect(rrect: InputRRect, paint: SkPaint) {
239
239
  this.ref.drawRRect(
240
240
  JsiSkRRect.fromValue(this.CanvasKit, rrect),
241
241
  JsiSkPaint.fromValue(paint)
242
242
  );
243
243
  }
244
244
 
245
- drawDRRect(outer: SkRRect, inner: SkRRect, paint: SkPaint) {
245
+ drawDRRect(outer: InputRRect, inner: InputRRect, paint: SkPaint) {
246
246
  this.ref.drawDRRect(
247
247
  JsiSkRRect.fromValue(this.CanvasKit, outer),
248
248
  JsiSkRRect.fromValue(this.CanvasKit, inner),
@@ -367,7 +367,7 @@ export class JsiSkCanvas
367
367
  );
368
368
  }
369
369
 
370
- clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean) {
370
+ clipRRect(rrect: InputRRect, op: ClipOp, doAntiAlias: boolean) {
371
371
  this.ref.clipRRect(
372
372
  JsiSkRRect.fromValue(this.CanvasKit, rrect),
373
373
  getEnum(this.CanvasKit.PathOp, op),
@@ -1,6 +1,6 @@
1
1
  import type { CanvasKit, ParagraphStyle } from "canvaskit-wasm";
2
2
 
3
- import { SkTextDirection, type SkParagraphStyle } from "../types";
3
+ import { TextDirection, type SkParagraphStyle } from "../types";
4
4
 
5
5
  export class JsiSkParagraphStyle {
6
6
  static toParagraphStyle(
@@ -23,7 +23,7 @@ export class JsiSkParagraphStyle {
23
23
  : undefined ?? ps.textAlign;
24
24
  ps.textDirection =
25
25
  value.textDirection !== undefined
26
- ? { value: value.textDirection === SkTextDirection.LTR ? 1 : 0 }
26
+ ? { value: value.textDirection === TextDirection.LTR ? 1 : 0 }
27
27
  : ps.textDirection;
28
28
  ps.textHeightBehavior =
29
29
  value.textHeightBehavior !== undefined
@@ -9,7 +9,7 @@ import type {
9
9
  SkPath,
10
10
  SkPoint,
11
11
  SkRect,
12
- SkRRect,
12
+ InputRRect,
13
13
  StrokeOpts,
14
14
  } from "../types";
15
15
 
@@ -285,7 +285,7 @@ export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
285
285
  return this;
286
286
  }
287
287
 
288
- addRRect(rrect: SkRRect, isCCW?: boolean) {
288
+ addRRect(rrect: InputRRect, isCCW?: boolean) {
289
289
  this.ref.addRRect(JsiSkRRect.fromValue(this.CanvasKit, rrect), isCCW);
290
290
  return this;
291
291
  }
@@ -1,6 +1,6 @@
1
1
  import type { CanvasKit, RRect } from "canvaskit-wasm";
2
2
 
3
- import type { SkRect, SkRRect } from "../types";
3
+ import type { InputRRect, SkRect, SkRRect } from "../types";
4
4
 
5
5
  import { BaseHostObject } from "./Host";
6
6
  import { JsiSkRect } from "./JsiSkRect";
@@ -13,10 +13,31 @@ export class JsiSkRRect
13
13
  // Float32Array
14
14
  };
15
15
 
16
- static fromValue(CanvasKit: CanvasKit, rect: SkRRect) {
16
+ static fromValue(CanvasKit: CanvasKit, rect: InputRRect) {
17
17
  if (rect instanceof JsiSkRect) {
18
18
  return rect.ref;
19
19
  }
20
+ if (
21
+ "topLeft" in rect &&
22
+ "topRight" in rect &&
23
+ "bottomRight" in rect &&
24
+ "bottomLeft" in rect
25
+ ) {
26
+ return Float32Array.of(
27
+ rect.rect.x,
28
+ rect.rect.y,
29
+ rect.rect.x + rect.rect.width,
30
+ rect.rect.y + rect.rect.height,
31
+ rect.topLeft.x,
32
+ rect.topLeft.y,
33
+ rect.topRight.x,
34
+ rect.topRight.y,
35
+ rect.bottomRight.x,
36
+ rect.bottomRight.y,
37
+ rect.bottomLeft.x,
38
+ rect.bottomLeft.y
39
+ );
40
+ }
20
41
  return CanvasKit.RRectXY(
21
42
  JsiSkRect.fromValue(CanvasKit, rect.rect),
22
43
  rect.rx,
@@ -10,11 +10,14 @@ declare global {
10
10
  var CanvasKit: CanvasKitType;
11
11
  }
12
12
 
13
+ let ckSharedPromise: Promise<CanvasKitType>;
14
+
13
15
  export const LoadSkiaWeb = async (opts?: CanvasKitInitOptions) => {
14
16
  if (global.CanvasKit !== undefined) {
15
17
  return;
16
18
  }
17
- const CanvasKit = await CanvasKitInit(opts);
19
+ ckSharedPromise = ckSharedPromise ?? CanvasKitInit(opts);
20
+ const CanvasKit = await ckSharedPromise;
18
21
  // The CanvasKit API is stored on the global object and used
19
22
  // to create the JsiSKApi in the Skia.web.ts file.
20
23
  global.CanvasKit = CanvasKit;