@shopify/react-native-skia 1.10.2 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. package/cpp/api/JsiSkApi.h +3 -0
  2. package/cpp/api/recorder/ColorFilters.h +133 -0
  3. package/cpp/api/recorder/Command.h +58 -0
  4. package/cpp/api/recorder/Convertor.h +1213 -0
  5. package/cpp/api/recorder/DataTypes.h +232 -0
  6. package/cpp/api/recorder/DrawingCtx.h +187 -0
  7. package/cpp/api/recorder/Drawings.h +950 -0
  8. package/cpp/api/recorder/ImageFilters.h +292 -0
  9. package/cpp/api/recorder/ImageFit.h +108 -0
  10. package/cpp/api/recorder/JsiRecorder.h +314 -0
  11. package/cpp/api/recorder/Paint.h +191 -0
  12. package/cpp/api/recorder/PathEffects.h +194 -0
  13. package/cpp/api/recorder/RNRecorder.h +637 -0
  14. package/cpp/api/recorder/Shaders.h +406 -0
  15. package/cpp/rnskia/dom/nodes/JsiAtlasNode.h +3 -2
  16. package/cpp/rnskia/dom/nodes/JsiImageNode.h +3 -2
  17. package/jestSetup.js +8 -0
  18. package/jestSetup.mjs +8 -0
  19. package/lib/commonjs/renderer/components/image/Image.d.ts +1 -1
  20. package/lib/commonjs/renderer/components/image/Image.js +8 -2
  21. package/lib/commonjs/renderer/components/image/Image.js.map +1 -1
  22. package/lib/commonjs/skia/types/Recorder.d.ts +52 -0
  23. package/lib/commonjs/skia/types/Recorder.js +6 -0
  24. package/lib/commonjs/skia/types/Recorder.js.map +1 -0
  25. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  26. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  27. package/lib/commonjs/skia/types/index.d.ts +1 -0
  28. package/lib/commonjs/skia/types/index.js +11 -0
  29. package/lib/commonjs/skia/types/index.js.map +1 -1
  30. package/lib/commonjs/skia/web/JsiSkia.js +3 -0
  31. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  32. package/lib/commonjs/sksg/Container.d.ts +6 -1
  33. package/lib/commonjs/sksg/Container.js +59 -2
  34. package/lib/commonjs/sksg/Container.js.map +1 -1
  35. package/lib/commonjs/sksg/Recorder/DrawingContext.js +1 -0
  36. package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
  37. package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
  38. package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js +189 -0
  39. package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js.map +1 -0
  40. package/lib/commonjs/sksg/Recorder/Recorder.d.ts +2 -2
  41. package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
  42. package/lib/commonjs/sksg/Recorder/Visitor.d.ts +2 -2
  43. package/lib/commonjs/sksg/Recorder/Visitor.js +2 -2
  44. package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
  45. package/lib/module/renderer/components/image/Image.d.ts +1 -1
  46. package/lib/module/renderer/components/image/Image.js +8 -2
  47. package/lib/module/renderer/components/image/Image.js.map +1 -1
  48. package/lib/module/skia/types/Recorder.d.ts +52 -0
  49. package/lib/module/skia/types/Recorder.js +2 -0
  50. package/lib/module/skia/types/Recorder.js.map +1 -0
  51. package/lib/module/skia/types/Skia.d.ts +2 -0
  52. package/lib/module/skia/types/Skia.js.map +1 -1
  53. package/lib/module/skia/types/index.d.ts +1 -0
  54. package/lib/module/skia/types/index.js +1 -0
  55. package/lib/module/skia/types/index.js.map +1 -1
  56. package/lib/module/skia/web/JsiSkia.js +3 -0
  57. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  58. package/lib/module/sksg/Container.d.ts +6 -1
  59. package/lib/module/sksg/Container.js +59 -2
  60. package/lib/module/sksg/Container.js.map +1 -1
  61. package/lib/module/sksg/Recorder/DrawingContext.js +1 -0
  62. package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
  63. package/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
  64. package/lib/module/sksg/Recorder/ReanimatedRecorder.js +182 -0
  65. package/lib/module/sksg/Recorder/ReanimatedRecorder.js.map +1 -0
  66. package/lib/module/sksg/Recorder/Recorder.d.ts +2 -2
  67. package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
  68. package/lib/module/sksg/Recorder/Visitor.d.ts +2 -2
  69. package/lib/module/sksg/Recorder/Visitor.js +2 -2
  70. package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
  71. package/lib/typescript/lib/commonjs/renderer/components/image/Image.d.ts +4 -1
  72. package/lib/typescript/lib/commonjs/skia/types/Recorder.d.ts +1 -0
  73. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -0
  74. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +5 -1
  75. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +6 -0
  76. package/lib/typescript/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +47 -0
  77. package/lib/typescript/lib/module/mock/index.d.ts +4 -1
  78. package/lib/typescript/lib/module/renderer/components/image/Image.d.ts +4 -1
  79. package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -0
  80. package/lib/typescript/lib/module/skia/types/Recorder.d.ts +1 -0
  81. package/lib/typescript/lib/module/skia/types/index.d.ts +1 -0
  82. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -0
  83. package/lib/typescript/lib/module/sksg/Container.d.ts +5 -1
  84. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +6 -0
  85. package/lib/typescript/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +46 -0
  86. package/lib/typescript/src/renderer/components/image/Image.d.ts +1 -1
  87. package/lib/typescript/src/skia/types/Recorder.d.ts +52 -0
  88. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  89. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  90. package/lib/typescript/src/sksg/Container.d.ts +6 -1
  91. package/lib/typescript/src/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
  92. package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +2 -2
  93. package/lib/typescript/src/sksg/Recorder/Visitor.d.ts +2 -2
  94. package/package.json +3 -2
  95. package/src/renderer/components/image/Image.tsx +2 -2
  96. package/src/skia/types/Recorder.ts +91 -0
  97. package/src/skia/types/Skia.ts +2 -0
  98. package/src/skia/types/index.ts +1 -0
  99. package/src/skia/web/JsiSkia.ts +3 -0
  100. package/src/sksg/Container.ts +63 -4
  101. package/src/sksg/Recorder/DrawingContext.ts +1 -0
  102. package/src/sksg/Recorder/ReanimatedRecorder.ts +271 -0
  103. package/src/sksg/Recorder/Recorder.ts +2 -2
  104. package/src/sksg/Recorder/Visitor.ts +17 -12
@@ -0,0 +1,271 @@
1
+ import type { SharedValue } from "react-native-reanimated";
2
+
3
+ import type { BaseRecorder, JsiRecorder, Skia } from "../../skia/types";
4
+ import type {
5
+ PaintProps,
6
+ NodeType,
7
+ BlurMaskFilterProps,
8
+ CTMProps,
9
+ BoxProps,
10
+ BoxShadowProps,
11
+ ImageProps,
12
+ CircleProps,
13
+ PointsProps,
14
+ PathProps,
15
+ RectProps,
16
+ RoundedRectProps,
17
+ OvalProps,
18
+ LineProps,
19
+ PatchProps,
20
+ VerticesProps,
21
+ DiffRectProps,
22
+ TextProps,
23
+ TextPathProps,
24
+ TextBlobProps,
25
+ GlyphsProps,
26
+ PictureProps,
27
+ ImageSVGProps,
28
+ ParagraphProps,
29
+ AtlasProps,
30
+ } from "../../dom/types";
31
+ import type { AnimatedProps } from "../../renderer";
32
+ import { isSharedValue } from "../utils";
33
+
34
+ export class ReanimatedRecorder implements BaseRecorder {
35
+ private values = new Set<SharedValue<unknown>>();
36
+ private recorder: JsiRecorder;
37
+
38
+ constructor(Skia: Skia) {
39
+ this.recorder = Skia.Recorder();
40
+ }
41
+
42
+ private processAnimationValues(props?: Record<string, unknown>) {
43
+ if (!props) {
44
+ return;
45
+ }
46
+ Object.values(props).forEach((value) => {
47
+ if (isSharedValue(value) && !this.values.has(value)) {
48
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
49
+ // @ts-expect-error
50
+ value.name = `variable${this.values.size}`;
51
+ this.values.add(value as SharedValue<unknown>);
52
+ }
53
+ });
54
+ }
55
+
56
+ getRecorder() {
57
+ return this.recorder;
58
+ }
59
+
60
+ getSharedValues() {
61
+ return Array.from(this.values);
62
+ }
63
+
64
+ saveGroup(): void {
65
+ this.recorder.saveGroup();
66
+ }
67
+
68
+ restoreGroup(): void {
69
+ this.recorder.restoreGroup();
70
+ }
71
+
72
+ savePaint(props: AnimatedProps<PaintProps>): void {
73
+ this.processAnimationValues(props);
74
+ this.recorder.savePaint(props);
75
+ }
76
+
77
+ restorePaint(): void {
78
+ this.recorder.restorePaint();
79
+ }
80
+
81
+ restorePaintDeclaration(): void {
82
+ this.recorder.restorePaintDeclaration();
83
+ }
84
+
85
+ materializePaint(): void {
86
+ this.recorder.materializePaint();
87
+ }
88
+
89
+ pushPathEffect(
90
+ pathEffectType: NodeType,
91
+ props: AnimatedProps<unknown>
92
+ ): void {
93
+ this.processAnimationValues(props);
94
+ this.recorder.pushPathEffect(pathEffectType, props);
95
+ }
96
+
97
+ pushImageFilter(
98
+ imageFilterType: NodeType,
99
+ props: AnimatedProps<unknown>
100
+ ): void {
101
+ this.processAnimationValues(props);
102
+ this.recorder.pushImageFilter(imageFilterType, props);
103
+ }
104
+
105
+ pushColorFilter(
106
+ colorFilterType: NodeType,
107
+ props: AnimatedProps<unknown>
108
+ ): void {
109
+ this.processAnimationValues(props);
110
+ this.recorder.pushColorFilter(colorFilterType, props);
111
+ }
112
+
113
+ pushShader(shaderType: NodeType, props: AnimatedProps<unknown>): void {
114
+ this.processAnimationValues(props);
115
+ this.recorder.pushShader(shaderType, props);
116
+ }
117
+
118
+ pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>): void {
119
+ this.processAnimationValues(props);
120
+ this.recorder.pushBlurMaskFilter(props);
121
+ }
122
+
123
+ composePathEffect(): void {
124
+ this.recorder.composePathEffect();
125
+ }
126
+
127
+ composeColorFilter(): void {
128
+ this.recorder.composeColorFilter();
129
+ }
130
+
131
+ composeImageFilter(): void {
132
+ this.recorder.composeImageFilter();
133
+ }
134
+
135
+ saveCTM(props: AnimatedProps<CTMProps>): void {
136
+ this.processAnimationValues(props);
137
+ this.recorder.saveCTM(props);
138
+ }
139
+
140
+ restoreCTM(): void {
141
+ this.recorder.restoreCTM();
142
+ }
143
+
144
+ drawPaint(): void {
145
+ this.recorder.drawPaint();
146
+ }
147
+
148
+ saveLayer(): void {
149
+ this.recorder.saveLayer();
150
+ }
151
+
152
+ saveBackdropFilter(): void {
153
+ this.recorder.saveBackdropFilter();
154
+ }
155
+
156
+ drawBox(
157
+ boxProps: AnimatedProps<BoxProps>,
158
+ shadows: {
159
+ props: BoxShadowProps;
160
+ }[]
161
+ ): void {
162
+ this.processAnimationValues(boxProps);
163
+ shadows.forEach((shadow) => {
164
+ this.processAnimationValues(
165
+ shadow.props as AnimatedProps<BoxShadowProps>
166
+ );
167
+ });
168
+ this.recorder.drawBox(
169
+ boxProps,
170
+ // TODO: Fix this type BaseRecorder.drawBox()
171
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
172
+ // @ts-expect-error
173
+ shadows.map((s) => s.props)
174
+ );
175
+ }
176
+
177
+ drawImage(props: AnimatedProps<ImageProps>): void {
178
+ this.processAnimationValues(props);
179
+ this.recorder.drawImage(props);
180
+ }
181
+
182
+ drawCircle(props: AnimatedProps<CircleProps>): void {
183
+ this.processAnimationValues(props);
184
+ this.recorder.drawCircle(props);
185
+ }
186
+
187
+ drawPoints(props: AnimatedProps<PointsProps>): void {
188
+ this.processAnimationValues(props);
189
+ this.recorder.drawPoints(props);
190
+ }
191
+
192
+ drawPath(props: AnimatedProps<PathProps>): void {
193
+ this.processAnimationValues(props);
194
+ this.recorder.drawPath(props);
195
+ }
196
+
197
+ drawRect(props: AnimatedProps<RectProps>): void {
198
+ this.processAnimationValues(props);
199
+ this.recorder.drawRect(props);
200
+ }
201
+
202
+ drawRRect(props: AnimatedProps<RoundedRectProps>): void {
203
+ this.processAnimationValues(props);
204
+ this.recorder.drawRRect(props);
205
+ }
206
+
207
+ drawOval(props: AnimatedProps<OvalProps>): void {
208
+ this.processAnimationValues(props);
209
+ this.recorder.drawOval(props);
210
+ }
211
+
212
+ drawLine(props: AnimatedProps<LineProps>): void {
213
+ this.processAnimationValues(props);
214
+ this.recorder.drawLine(props);
215
+ }
216
+
217
+ drawPatch(props: AnimatedProps<PatchProps>): void {
218
+ this.processAnimationValues(props);
219
+ this.recorder.drawPatch(props);
220
+ }
221
+
222
+ drawVertices(props: AnimatedProps<VerticesProps>): void {
223
+ this.processAnimationValues(props);
224
+ this.recorder.drawVertices(props);
225
+ }
226
+
227
+ drawDiffRect(props: AnimatedProps<DiffRectProps>): void {
228
+ this.processAnimationValues(props);
229
+ this.recorder.drawDiffRect(props);
230
+ }
231
+
232
+ drawText(props: AnimatedProps<TextProps>): void {
233
+ this.processAnimationValues(props);
234
+ this.recorder.drawText(props);
235
+ }
236
+
237
+ drawTextPath(props: AnimatedProps<TextPathProps>): void {
238
+ this.processAnimationValues(props);
239
+ this.recorder.drawTextPath(props);
240
+ }
241
+
242
+ drawTextBlob(props: AnimatedProps<TextBlobProps>): void {
243
+ this.processAnimationValues(props);
244
+ this.recorder.drawTextBlob(props);
245
+ }
246
+
247
+ drawGlyphs(props: AnimatedProps<GlyphsProps>): void {
248
+ this.processAnimationValues(props);
249
+ this.recorder.drawGlyphs(props);
250
+ }
251
+
252
+ drawPicture(props: AnimatedProps<PictureProps>): void {
253
+ this.processAnimationValues(props);
254
+ this.recorder.drawPicture(props);
255
+ }
256
+
257
+ drawImageSVG(props: AnimatedProps<ImageSVGProps>): void {
258
+ this.processAnimationValues(props);
259
+ this.recorder.drawImageSVG(props);
260
+ }
261
+
262
+ drawParagraph(props: AnimatedProps<ParagraphProps>): void {
263
+ this.processAnimationValues(props);
264
+ this.recorder.drawParagraph(props);
265
+ }
266
+
267
+ drawAtlas(props: AnimatedProps<AtlasProps>): void {
268
+ this.processAnimationValues(props);
269
+ this.recorder.drawAtlas(props);
270
+ }
271
+ }
@@ -30,7 +30,7 @@ import type {
30
30
  import type { AnimatedProps } from "../../renderer";
31
31
  import { isSharedValue } from "../utils";
32
32
  import { isColorFilter, isImageFilter, isPathEffect, isShader } from "../Node";
33
- import type { SkPaint } from "../../skia/types";
33
+ import type { SkPaint, BaseRecorder } from "../../skia/types";
34
34
 
35
35
  import { CommandType } from "./Core";
36
36
  import type { Command } from "./Core";
@@ -44,7 +44,7 @@ interface AnimationValues {
44
44
  animationValues: Set<SharedValue<unknown>>;
45
45
  }
46
46
 
47
- export class Recorder {
47
+ export class Recorder implements BaseRecorder {
48
48
  commands: Command[] = [];
49
49
  cursors: Command[][] = [];
50
50
  animationValues: Set<SharedValue<unknown>> = new Set();
@@ -5,11 +5,10 @@ import type {
5
5
  BoxShadowProps,
6
6
  } from "../../dom/types";
7
7
  import { NodeType } from "../../dom/types";
8
+ import type { BaseRecorder } from "../../skia/types/Recorder";
8
9
  import type { Node } from "../Node";
9
10
  import { isImageFilter, isShader, sortNodeChildren } from "../Node";
10
11
 
11
- import type { Recorder } from "./Recorder";
12
-
13
12
  export const processPaint = ({
14
13
  opacity,
15
14
  color,
@@ -117,7 +116,10 @@ const processCTM = ({
117
116
  return null;
118
117
  };
119
118
 
120
- const pushColorFilters = (recorder: Recorder, colorFilters: Node<any>[]) => {
119
+ const pushColorFilters = (
120
+ recorder: BaseRecorder,
121
+ colorFilters: Node<any>[]
122
+ ) => {
121
123
  colorFilters.forEach((colorFilter) => {
122
124
  if (colorFilter.children.length > 0) {
123
125
  pushColorFilters(recorder, colorFilter.children);
@@ -132,7 +134,7 @@ const pushColorFilters = (recorder: Recorder, colorFilters: Node<any>[]) => {
132
134
  });
133
135
  };
134
136
 
135
- const pushPathEffects = (recorder: Recorder, pathEffects: Node<any>[]) => {
137
+ const pushPathEffects = (recorder: BaseRecorder, pathEffects: Node<any>[]) => {
136
138
  pathEffects.forEach((pathEffect) => {
137
139
  if (pathEffect.children.length > 0) {
138
140
  pushPathEffects(recorder, pathEffect.children);
@@ -147,7 +149,10 @@ const pushPathEffects = (recorder: Recorder, pathEffects: Node<any>[]) => {
147
149
  });
148
150
  };
149
151
 
150
- const pushImageFilters = (recorder: Recorder, imageFilters: Node<any>[]) => {
152
+ const pushImageFilters = (
153
+ recorder: BaseRecorder,
154
+ imageFilters: Node<any>[]
155
+ ) => {
151
156
  imageFilters.forEach((imageFilter) => {
152
157
  if (imageFilter.children.length > 0) {
153
158
  pushImageFilters(recorder, imageFilter.children);
@@ -166,7 +171,7 @@ const pushImageFilters = (recorder: Recorder, imageFilters: Node<any>[]) => {
166
171
  });
167
172
  };
168
173
 
169
- const pushShaders = (recorder: Recorder, shaders: Node<any>[]) => {
174
+ const pushShaders = (recorder: BaseRecorder, shaders: Node<any>[]) => {
170
175
  shaders.forEach((shader) => {
171
176
  if (shader.children.length > 0) {
172
177
  pushShaders(recorder, shader.children);
@@ -175,13 +180,13 @@ const pushShaders = (recorder: Recorder, shaders: Node<any>[]) => {
175
180
  });
176
181
  };
177
182
 
178
- const pushMaskFilters = (recorder: Recorder, maskFilters: Node<any>[]) => {
183
+ const pushMaskFilters = (recorder: BaseRecorder, maskFilters: Node<any>[]) => {
179
184
  if (maskFilters.length > 0) {
180
185
  recorder.pushBlurMaskFilter(maskFilters[maskFilters.length - 1].props);
181
186
  }
182
187
  };
183
188
 
184
- const pushPaints = (recorder: Recorder, paints: Node<any>[]) => {
189
+ const pushPaints = (recorder: BaseRecorder, paints: Node<any>[]) => {
185
190
  paints.forEach((paint) => {
186
191
  recorder.savePaint(paint.props);
187
192
  const { colorFilters, maskFilters, shaders, imageFilters, pathEffects } =
@@ -195,7 +200,7 @@ const pushPaints = (recorder: Recorder, paints: Node<any>[]) => {
195
200
  });
196
201
  };
197
202
 
198
- const visitNode = (recorder: Recorder, node: Node<any>) => {
203
+ const visitNode = (recorder: BaseRecorder, node: Node<any>) => {
199
204
  if (node.type === NodeType.Group) {
200
205
  recorder.saveGroup();
201
206
  }
@@ -252,10 +257,10 @@ const visitNode = (recorder: Recorder, node: Node<any>) => {
252
257
  recorder.drawPaint();
253
258
  break;
254
259
  case NodeType.Image:
255
- recorder.drawImage(node.props);
260
+ recorder.drawImage(props);
256
261
  break;
257
262
  case NodeType.Circle:
258
- recorder.drawCircle(node.props);
263
+ recorder.drawCircle(props);
259
264
  break;
260
265
  case NodeType.Points:
261
266
  recorder.drawPoints(props);
@@ -323,7 +328,7 @@ const visitNode = (recorder: Recorder, node: Node<any>) => {
323
328
  }
324
329
  };
325
330
 
326
- export const visit = (recorder: Recorder, root: Node[]) => {
331
+ export const visit = (recorder: BaseRecorder, root: Node[]) => {
327
332
  root.forEach((node) => {
328
333
  visitNode(recorder, node);
329
334
  });