@shopify/react-native-skia 2.5.5 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/cpp/api/CustomBlendModes.h +1 -0
  2. package/cpp/api/JsiSkApi.h +4 -0
  3. package/cpp/api/JsiSkCanvas.h +2 -2
  4. package/cpp/api/JsiSkContourMeasureIter.h +1 -1
  5. package/cpp/api/JsiSkPath.h +483 -355
  6. package/cpp/api/JsiSkPathBuilder.h +415 -0
  7. package/cpp/api/JsiSkPathBuilderFactory.h +53 -0
  8. package/cpp/api/JsiSkPathEffectFactory.h +2 -2
  9. package/cpp/api/JsiSkPathFactory.h +274 -3
  10. package/cpp/api/recorder/DataTypes.h +1 -1
  11. package/cpp/api/recorder/Drawings.h +6 -2
  12. package/cpp/rnskia/RNDawnContext.h +21 -0
  13. package/cpp/rnskia/RNDawnUtils.h +115 -113
  14. package/lib/commonjs/animation/functions/interpolatePaths.d.ts +1 -1
  15. package/lib/commonjs/animation/functions/interpolatePaths.js +5 -4
  16. package/lib/commonjs/animation/functions/interpolatePaths.js.map +1 -1
  17. package/lib/commonjs/external/reanimated/interpolators.d.ts +11 -2
  18. package/lib/commonjs/external/reanimated/interpolators.js +21 -4
  19. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  20. package/lib/commonjs/skia/types/Path/PathBuilder.d.ts +201 -0
  21. package/lib/commonjs/skia/types/Path/PathBuilder.js +6 -0
  22. package/lib/commonjs/skia/types/Path/PathBuilder.js.map +1 -0
  23. package/lib/commonjs/skia/types/Path/PathBuilderFactory.d.ts +13 -0
  24. package/lib/commonjs/skia/types/Path/PathBuilderFactory.js +6 -0
  25. package/lib/commonjs/skia/types/Path/PathBuilderFactory.js.map +1 -0
  26. package/lib/commonjs/skia/types/Path/PathFactory.d.ts +87 -1
  27. package/lib/commonjs/skia/types/Path/PathFactory.js.map +1 -1
  28. package/lib/commonjs/skia/types/Path/index.d.ts +2 -0
  29. package/lib/commonjs/skia/types/Path/index.js +22 -0
  30. package/lib/commonjs/skia/types/Path/index.js.map +1 -1
  31. package/lib/commonjs/skia/types/Skia.d.ts +2 -1
  32. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  33. package/lib/commonjs/skia/web/Host.js +1 -3
  34. package/lib/commonjs/skia/web/Host.js.map +1 -1
  35. package/lib/commonjs/skia/web/JsiSkCanvas.js +6 -2
  36. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  37. package/lib/commonjs/skia/web/JsiSkContourMeasure.js +4 -1
  38. package/lib/commonjs/skia/web/JsiSkContourMeasure.js.map +1 -1
  39. package/lib/commonjs/skia/web/JsiSkPath.d.ts +42 -30
  40. package/lib/commonjs/skia/web/JsiSkPath.js +302 -111
  41. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  42. package/lib/commonjs/skia/web/JsiSkPathBuilder.d.ts +45 -0
  43. package/lib/commonjs/skia/web/JsiSkPathBuilder.js +192 -0
  44. package/lib/commonjs/skia/web/JsiSkPathBuilder.js.map +1 -0
  45. package/lib/commonjs/skia/web/JsiSkPathBuilderFactory.d.ts +9 -0
  46. package/lib/commonjs/skia/web/JsiSkPathBuilderFactory.js +26 -0
  47. package/lib/commonjs/skia/web/JsiSkPathBuilderFactory.js.map +1 -0
  48. package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js +6 -2
  49. package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js.map +1 -1
  50. package/lib/commonjs/skia/web/JsiSkPathFactory.d.ts +13 -1
  51. package/lib/commonjs/skia/web/JsiSkPathFactory.js +140 -5
  52. package/lib/commonjs/skia/web/JsiSkPathFactory.js.map +1 -1
  53. package/lib/commonjs/skia/web/JsiSkia.js +8 -1
  54. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  55. package/lib/commonjs/sksg/Recorder/commands/Drawing.js +18 -6
  56. package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
  57. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +2 -2
  58. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js +2 -3
  59. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  60. package/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +2 -2
  61. package/lib/commonjs/specs/WebGPUViewNativeComponent.js +2 -3
  62. package/lib/commonjs/specs/WebGPUViewNativeComponent.js.map +1 -1
  63. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js +2 -0
  64. package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js.map +1 -1
  65. package/lib/module/animation/functions/interpolatePaths.d.ts +1 -1
  66. package/lib/module/animation/functions/interpolatePaths.js +5 -4
  67. package/lib/module/animation/functions/interpolatePaths.js.map +1 -1
  68. package/lib/module/external/reanimated/interpolators.d.ts +11 -2
  69. package/lib/module/external/reanimated/interpolators.js +21 -4
  70. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  71. package/lib/module/skia/types/Path/PathBuilder.d.ts +201 -0
  72. package/lib/module/skia/types/Path/PathBuilder.js +2 -0
  73. package/lib/module/skia/types/Path/PathBuilder.js.map +1 -0
  74. package/lib/module/skia/types/Path/PathBuilderFactory.d.ts +13 -0
  75. package/lib/module/skia/types/Path/PathBuilderFactory.js +2 -0
  76. package/lib/module/skia/types/Path/PathBuilderFactory.js.map +1 -0
  77. package/lib/module/skia/types/Path/PathFactory.d.ts +87 -1
  78. package/lib/module/skia/types/Path/PathFactory.js.map +1 -1
  79. package/lib/module/skia/types/Path/index.d.ts +2 -0
  80. package/lib/module/skia/types/Path/index.js +2 -0
  81. package/lib/module/skia/types/Path/index.js.map +1 -1
  82. package/lib/module/skia/types/Skia.d.ts +2 -1
  83. package/lib/module/skia/types/Skia.js.map +1 -1
  84. package/lib/module/skia/web/Host.js +1 -3
  85. package/lib/module/skia/web/Host.js.map +1 -1
  86. package/lib/module/skia/web/JsiSkCanvas.js +6 -2
  87. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  88. package/lib/module/skia/web/JsiSkContourMeasure.js +4 -1
  89. package/lib/module/skia/web/JsiSkContourMeasure.js.map +1 -1
  90. package/lib/module/skia/web/JsiSkPath.d.ts +42 -30
  91. package/lib/module/skia/web/JsiSkPath.js +300 -110
  92. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  93. package/lib/module/skia/web/JsiSkPathBuilder.d.ts +45 -0
  94. package/lib/module/skia/web/JsiSkPathBuilder.js +186 -0
  95. package/lib/module/skia/web/JsiSkPathBuilder.js.map +1 -0
  96. package/lib/module/skia/web/JsiSkPathBuilderFactory.d.ts +9 -0
  97. package/lib/module/skia/web/JsiSkPathBuilderFactory.js +19 -0
  98. package/lib/module/skia/web/JsiSkPathBuilderFactory.js.map +1 -0
  99. package/lib/module/skia/web/JsiSkPathEffectFactory.js +6 -2
  100. package/lib/module/skia/web/JsiSkPathEffectFactory.js.map +1 -1
  101. package/lib/module/skia/web/JsiSkPathFactory.d.ts +13 -1
  102. package/lib/module/skia/web/JsiSkPathFactory.js +141 -6
  103. package/lib/module/skia/web/JsiSkPathFactory.js.map +1 -1
  104. package/lib/module/skia/web/JsiSkia.js +8 -1
  105. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  106. package/lib/module/sksg/Recorder/commands/Drawing.js +18 -6
  107. package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
  108. package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +2 -2
  109. package/lib/module/specs/SkiaPictureViewNativeComponent.js +1 -1
  110. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  111. package/lib/module/specs/WebGPUViewNativeComponent.d.ts +2 -2
  112. package/lib/module/specs/WebGPUViewNativeComponent.js +1 -1
  113. package/lib/module/specs/WebGPUViewNativeComponent.js.map +1 -1
  114. package/lib/module/specs/WebGPUViewNativeComponent.web.js +2 -0
  115. package/lib/module/specs/WebGPUViewNativeComponent.web.js.map +1 -1
  116. package/lib/typescript/lib/commonjs/animation/functions/interpolatePaths.d.ts +1 -1
  117. package/lib/typescript/lib/commonjs/external/reanimated/interpolators.d.ts +1 -1
  118. package/lib/typescript/lib/commonjs/skia/types/Path/PathBuilder.d.ts +1 -0
  119. package/lib/typescript/lib/commonjs/skia/types/Path/PathBuilderFactory.d.ts +1 -0
  120. package/lib/typescript/lib/commonjs/skia/web/JsiSkPath.d.ts +33 -25
  121. package/lib/typescript/lib/commonjs/skia/web/JsiSkPathBuilder.d.ts +46 -0
  122. package/lib/typescript/lib/commonjs/skia/web/JsiSkPathBuilderFactory.d.ts +7 -0
  123. package/lib/typescript/lib/commonjs/skia/web/JsiSkPathFactory.d.ts +12 -0
  124. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +2 -0
  125. package/lib/typescript/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +2 -1
  126. package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +2 -1
  127. package/lib/typescript/lib/module/animation/functions/interpolatePaths.d.ts +1 -1
  128. package/lib/typescript/lib/module/external/reanimated/interpolators.d.ts +1 -1
  129. package/lib/typescript/lib/module/mock/index.d.ts +1 -1
  130. package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -0
  131. package/lib/typescript/lib/module/skia/types/Path/PathBuilder.d.ts +1 -0
  132. package/lib/typescript/lib/module/skia/types/Path/PathBuilderFactory.d.ts +1 -0
  133. package/lib/typescript/lib/module/skia/types/Path/index.d.ts +2 -0
  134. package/lib/typescript/lib/module/skia/web/JsiSkPath.d.ts +38 -25
  135. package/lib/typescript/lib/module/skia/web/JsiSkPathBuilder.d.ts +45 -0
  136. package/lib/typescript/lib/module/skia/web/JsiSkPathBuilderFactory.d.ts +6 -0
  137. package/lib/typescript/lib/module/skia/web/JsiSkPathFactory.d.ts +12 -0
  138. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +2 -0
  139. package/lib/typescript/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -1
  140. package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.d.ts +1 -1
  141. package/lib/typescript/src/animation/functions/interpolatePaths.d.ts +1 -1
  142. package/lib/typescript/src/external/reanimated/interpolators.d.ts +11 -2
  143. package/lib/typescript/src/skia/types/Path/PathBuilder.d.ts +201 -0
  144. package/lib/typescript/src/skia/types/Path/PathBuilderFactory.d.ts +13 -0
  145. package/lib/typescript/src/skia/types/Path/PathFactory.d.ts +87 -1
  146. package/lib/typescript/src/skia/types/Path/index.d.ts +2 -0
  147. package/lib/typescript/src/skia/types/Skia.d.ts +2 -1
  148. package/lib/typescript/src/skia/web/JsiSkPath.d.ts +42 -30
  149. package/lib/typescript/src/skia/web/JsiSkPathBuilder.d.ts +45 -0
  150. package/lib/typescript/src/skia/web/JsiSkPathBuilderFactory.d.ts +9 -0
  151. package/lib/typescript/src/skia/web/JsiSkPathFactory.d.ts +13 -1
  152. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +2 -2
  153. package/lib/typescript/src/specs/WebGPUViewNativeComponent.d.ts +2 -2
  154. package/package.json +3 -2
  155. package/scripts/install-libs.js +16 -6
  156. package/src/animation/functions/interpolatePaths.ts +5 -6
  157. package/src/external/reanimated/interpolators.ts +25 -5
  158. package/src/skia/types/Path/PathBuilder.ts +303 -0
  159. package/src/skia/types/Path/PathBuilderFactory.ts +15 -0
  160. package/src/skia/types/Path/PathFactory.ts +108 -1
  161. package/src/skia/types/Path/index.ts +2 -0
  162. package/src/skia/types/Skia.ts +2 -1
  163. package/src/skia/web/Host.ts +7 -1
  164. package/src/skia/web/JsiSkCanvas.ts +6 -6
  165. package/src/skia/web/JsiSkContourMeasure.ts +4 -4
  166. package/src/skia/web/JsiSkPath.ts +451 -168
  167. package/src/skia/web/JsiSkPathBuilder.ts +293 -0
  168. package/src/skia/web/JsiSkPathBuilderFactory.ts +32 -0
  169. package/src/skia/web/JsiSkPathEffectFactory.ts +6 -2
  170. package/src/skia/web/JsiSkPathFactory.ts +231 -8
  171. package/src/skia/web/JsiSkia.ts +11 -8
  172. package/src/sksg/Recorder/commands/Drawing.ts +20 -7
  173. package/src/specs/SkiaPictureViewNativeComponent.ts +1 -2
  174. package/src/specs/WebGPUViewNativeComponent.ts +2 -2
  175. package/src/specs/WebGPUViewNativeComponent.web.ts +2 -0
@@ -1,6 +1,9 @@
1
1
  import type { SkFont } from "../Font";
2
+ import type { SkRect } from "../Rect";
3
+ import type { SkPoint } from "../Point";
4
+ import type { InputRRect } from "../RRect";
2
5
 
3
- import type { SkPath, PathOp, PathCommand } from "./Path";
6
+ import type { SkPath, PathOp, PathCommand, StrokeOpts } from "./Path";
4
7
 
5
8
  export interface PathFactory {
6
9
  Make(): SkPath;
@@ -31,4 +34,108 @@ export interface PathFactory {
31
34
  * Converts the text to a path with the given font at location x / y.
32
35
  */
33
36
  MakeFromText(text: string, x: number, y: number, font: SkFont): SkPath | null;
37
+
38
+ // Static shape factories
39
+
40
+ /**
41
+ * Creates a path containing a rectangle.
42
+ * @param rect - the rectangle
43
+ * @param isCCW - if true, draws counter-clockwise
44
+ */
45
+ Rect(rect: SkRect, isCCW?: boolean): SkPath;
46
+
47
+ /**
48
+ * Creates a path containing an oval (ellipse).
49
+ * @param rect - bounds of the oval
50
+ * @param isCCW - if true, draws counter-clockwise
51
+ * @param startIndex - index of initial point
52
+ */
53
+ Oval(rect: SkRect, isCCW?: boolean, startIndex?: number): SkPath;
54
+
55
+ /**
56
+ * Creates a path containing a circle.
57
+ * @param x - center x
58
+ * @param y - center y
59
+ * @param r - radius
60
+ */
61
+ Circle(x: number, y: number, r: number): SkPath;
62
+
63
+ /**
64
+ * Creates a path containing a rounded rectangle.
65
+ * @param rrect - the rounded rectangle
66
+ * @param isCCW - if true, draws counter-clockwise
67
+ */
68
+ RRect(rrect: InputRRect, isCCW?: boolean): SkPath;
69
+
70
+ /**
71
+ * Creates a path containing a line segment.
72
+ * @param p1 - start point
73
+ * @param p2 - end point
74
+ */
75
+ Line(p1: SkPoint, p2: SkPoint): SkPath;
76
+
77
+ /**
78
+ * Creates a path containing a polygon from the given points.
79
+ * @param points - array of points
80
+ * @param close - if true, close the polygon
81
+ */
82
+ Polygon(points: SkPoint[], close: boolean): SkPath;
83
+
84
+ // Static path operations
85
+
86
+ /**
87
+ * Creates a new stroked path from the input path.
88
+ * @param path - source path to stroke
89
+ * @param opts - stroke options (width, cap, join, miter_limit, precision)
90
+ * @returns stroked path or null if operation fails
91
+ */
92
+ Stroke(path: SkPath, opts?: StrokeOpts): SkPath | null;
93
+
94
+ /**
95
+ * Creates a trimmed path from the input path.
96
+ * @param path - source path
97
+ * @param start - start of trim (0-1)
98
+ * @param end - end of trim (0-1)
99
+ * @param isComplement - if true, returns the complement
100
+ * @returns trimmed path or null if operation fails
101
+ */
102
+ Trim(
103
+ path: SkPath,
104
+ start: number,
105
+ end: number,
106
+ isComplement: boolean
107
+ ): SkPath | null;
108
+
109
+ /**
110
+ * Simplifies the path to non-overlapping contours.
111
+ * @param path - source path
112
+ * @returns simplified path or null if operation fails
113
+ */
114
+ Simplify(path: SkPath): SkPath | null;
115
+
116
+ /**
117
+ * Creates a dashed version of the path.
118
+ * @param path - source path
119
+ * @param on - length of dash
120
+ * @param off - length of gap
121
+ * @param phase - offset into dash pattern
122
+ * @returns dashed path or null if operation fails
123
+ */
124
+ Dash(path: SkPath, on: number, off: number, phase: number): SkPath | null;
125
+
126
+ /**
127
+ * Creates a path with Winding fill type.
128
+ * @param path - source path
129
+ * @returns path with winding fill or null if operation fails
130
+ */
131
+ AsWinding(path: SkPath): SkPath | null;
132
+
133
+ /**
134
+ * Interpolates between two paths.
135
+ * @param start - starting path
136
+ * @param end - ending path
137
+ * @param weight - interpolation weight (0 = start, 1 = end)
138
+ * @returns interpolated path or null if paths are not interpolatable
139
+ */
140
+ Interpolate(start: SkPath, end: SkPath, weight: number): SkPath | null;
34
141
  }
@@ -1,2 +1,4 @@
1
1
  export * from "./Path";
2
+ export * from "./PathBuilder";
3
+ export * from "./PathBuilderFactory";
2
4
  export * from "./PathFactory";
@@ -1,5 +1,5 @@
1
1
  import type { ImageFilterFactory } from "./ImageFilter";
2
- import type { PathFactory } from "./Path";
2
+ import type { PathFactory, PathBuilderFactory } from "./Path";
3
3
  import type { ColorFilterFactory } from "./ColorFilter";
4
4
  import type { SkFont, FontMgrFactory } from "./Font";
5
5
  import type { SkTypeface, TypefaceFactory } from "./Typeface";
@@ -67,6 +67,7 @@ export interface Skia {
67
67
  PictureRecorder: () => SkPictureRecorder;
68
68
  Picture: PictureFactory;
69
69
  Path: PathFactory;
70
+ PathBuilder: PathBuilderFactory;
70
71
  Matrix: (matrix?: readonly number[]) => SkMatrix;
71
72
  ColorFilter: ColorFilterFactory;
72
73
  Font: (typeface?: SkTypeface, size?: number) => SkFont;
@@ -64,7 +64,13 @@ export const getEnum = (
64
64
  if (typeof e !== "function") {
65
65
  throw new Error(`${name} is not an number`);
66
66
  }
67
- const result = Object.values(e).find(({ value }) => value === v);
67
+ const result = Object.values(e).find(
68
+ (entry) =>
69
+ entry !== null &&
70
+ typeof entry === "object" &&
71
+ "value" in entry &&
72
+ entry.value === v
73
+ );
68
74
  if (!result) {
69
75
  throw new Error(
70
76
  `Enum ${name} does not have value ${v} on React Native Web`
@@ -272,7 +272,9 @@ export class JsiSkCanvas
272
272
  }
273
273
 
274
274
  drawPath(path: SkPath, paint: SkPaint) {
275
- this.ref.drawPath(JsiSkPath.fromValue(path), JsiSkPaint.fromValue(paint));
275
+ const p = JsiSkPath.pathFromValue(path);
276
+ this.ref.drawPath(p, JsiSkPaint.fromValue(paint));
277
+ p.delete();
276
278
  }
277
279
 
278
280
  drawText(str: string, x: number, y: number, paint: SkPaint, font: SkFont) {
@@ -369,11 +371,9 @@ export class JsiSkCanvas
369
371
  }
370
372
 
371
373
  clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean) {
372
- this.ref.clipPath(
373
- JsiSkPath.fromValue(path),
374
- getEnum(this.CanvasKit, "PathOp", op),
375
- doAntiAlias
376
- );
374
+ const p = JsiSkPath.pathFromValue(path);
375
+ this.ref.clipPath(p, getEnum(this.CanvasKit, "PathOp", op), doAntiAlias);
376
+ p.delete();
377
377
  }
378
378
 
379
379
  clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean) {
@@ -23,10 +23,10 @@ export class JsiSkContourMeasure
23
23
  }
24
24
 
25
25
  getSegment(startD: number, stopD: number, startWithMoveTo: boolean) {
26
- return new JsiSkPath(
27
- this.CanvasKit,
28
- this.ref.getSegment(startD, stopD, startWithMoveTo)
29
- );
26
+ const segment = this.ref.getSegment(startD, stopD, startWithMoveTo);
27
+ const builder = new this.CanvasKit.PathBuilder(segment);
28
+ segment.delete();
29
+ return new JsiSkPath(this.CanvasKit, builder);
30
30
  }
31
31
 
32
32
  isClosed() {