@shopify/react-native-skia 0.1.227 → 0.1.229

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. package/cpp/api/JsiSkCanvas.h +2 -1
  2. package/cpp/api/JsiSkMatrix.h +27 -11
  3. package/cpp/api/JsiSkTypeface.h +1 -0
  4. package/cpp/rnskia/dom/props/MatrixProp.h +14 -3
  5. package/lib/commonjs/dom/types/Common.d.ts +2 -2
  6. package/lib/commonjs/dom/types/Common.js.map +1 -1
  7. package/lib/commonjs/external/reanimated/interpolators.d.ts +1 -0
  8. package/lib/commonjs/external/reanimated/interpolators.js +16 -3
  9. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  10. package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +2 -1
  11. package/lib/commonjs/external/reanimated/moduleWrapper.js +9 -7
  12. package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -1
  13. package/lib/commonjs/renderer/Canvas.js +7 -13
  14. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  15. package/lib/commonjs/skia/core/Vector.d.ts +0 -5
  16. package/lib/commonjs/skia/core/Vector.js +1 -17
  17. package/lib/commonjs/skia/core/Vector.js.map +1 -1
  18. package/lib/commonjs/skia/types/Canvas.d.ts +2 -2
  19. package/lib/commonjs/skia/types/Canvas.js.map +1 -1
  20. package/lib/commonjs/skia/types/Matrix.d.ts +3 -13
  21. package/lib/commonjs/skia/types/Matrix.js +1 -16
  22. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  23. package/lib/commonjs/skia/types/Matrix4.d.ts +60 -1
  24. package/lib/commonjs/skia/types/Matrix4.js +159 -14
  25. package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
  26. package/lib/commonjs/skia/types/Path/Path.d.ts +2 -2
  27. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  28. package/lib/commonjs/skia/web/Host.d.ts +2 -3
  29. package/lib/commonjs/skia/web/Host.js +4 -12
  30. package/lib/commonjs/skia/web/Host.js.map +1 -1
  31. package/lib/commonjs/skia/web/JsiSkCanvas.js +12 -12
  32. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  33. package/lib/commonjs/skia/web/JsiSkColorFilterFactory.js +1 -1
  34. package/lib/commonjs/skia/web/JsiSkColorFilterFactory.js.map +1 -1
  35. package/lib/commonjs/skia/web/JsiSkFont.js +2 -2
  36. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  37. package/lib/commonjs/skia/web/JsiSkImage.js +6 -6
  38. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  39. package/lib/commonjs/skia/web/JsiSkImageFactory.js +2 -2
  40. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  41. package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js +3 -3
  42. package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -1
  43. package/lib/commonjs/skia/web/JsiSkMaskFilterFactory.js +1 -1
  44. package/lib/commonjs/skia/web/JsiSkMaskFilterFactory.js.map +1 -1
  45. package/lib/commonjs/skia/web/JsiSkMatrix.d.ts +2 -2
  46. package/lib/commonjs/skia/web/JsiSkMatrix.js +6 -1
  47. package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
  48. package/lib/commonjs/skia/web/JsiSkPaint.js +3 -3
  49. package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
  50. package/lib/commonjs/skia/web/JsiSkPath.js +4 -4
  51. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  52. package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js +1 -1
  53. package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js.map +1 -1
  54. package/lib/commonjs/skia/web/JsiSkPathFactory.js +1 -1
  55. package/lib/commonjs/skia/web/JsiSkPathFactory.js.map +1 -1
  56. package/lib/commonjs/skia/web/JsiSkPicture.js +1 -1
  57. package/lib/commonjs/skia/web/JsiSkPicture.js.map +1 -1
  58. package/lib/commonjs/skia/web/JsiSkShaderFactory.js +5 -5
  59. package/lib/commonjs/skia/web/JsiSkShaderFactory.js.map +1 -1
  60. package/lib/commonjs/skia/web/JsiSkVerticesFactory.js +3 -3
  61. package/lib/commonjs/skia/web/JsiSkVerticesFactory.js.map +1 -1
  62. package/lib/module/dom/types/Common.d.ts +2 -2
  63. package/lib/module/dom/types/Common.js.map +1 -1
  64. package/lib/module/external/reanimated/interpolators.d.ts +1 -0
  65. package/lib/module/external/reanimated/interpolators.js +14 -4
  66. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  67. package/lib/module/external/reanimated/moduleWrapper.d.ts +2 -1
  68. package/lib/module/external/reanimated/moduleWrapper.js +7 -6
  69. package/lib/module/external/reanimated/moduleWrapper.js.map +1 -1
  70. package/lib/module/renderer/Canvas.js +7 -12
  71. package/lib/module/renderer/Canvas.js.map +1 -1
  72. package/lib/module/skia/core/Vector.d.ts +0 -5
  73. package/lib/module/skia/core/Vector.js +0 -13
  74. package/lib/module/skia/core/Vector.js.map +1 -1
  75. package/lib/module/skia/types/Canvas.d.ts +2 -2
  76. package/lib/module/skia/types/Canvas.js.map +1 -1
  77. package/lib/module/skia/types/Matrix.d.ts +3 -13
  78. package/lib/module/skia/types/Matrix.js +0 -14
  79. package/lib/module/skia/types/Matrix.js.map +1 -1
  80. package/lib/module/skia/types/Matrix4.d.ts +60 -1
  81. package/lib/module/skia/types/Matrix4.js +132 -18
  82. package/lib/module/skia/types/Matrix4.js.map +1 -1
  83. package/lib/module/skia/types/Path/Path.d.ts +2 -2
  84. package/lib/module/skia/types/Path/Path.js.map +1 -1
  85. package/lib/module/skia/web/Host.d.ts +2 -3
  86. package/lib/module/skia/web/Host.js +2 -7
  87. package/lib/module/skia/web/Host.js.map +1 -1
  88. package/lib/module/skia/web/JsiSkCanvas.js +13 -13
  89. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  90. package/lib/module/skia/web/JsiSkColorFilterFactory.js +2 -2
  91. package/lib/module/skia/web/JsiSkColorFilterFactory.js.map +1 -1
  92. package/lib/module/skia/web/JsiSkFont.js +3 -3
  93. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  94. package/lib/module/skia/web/JsiSkImage.js +7 -7
  95. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  96. package/lib/module/skia/web/JsiSkImageFactory.js +3 -3
  97. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  98. package/lib/module/skia/web/JsiSkImageFilterFactory.js +4 -4
  99. package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -1
  100. package/lib/module/skia/web/JsiSkMaskFilterFactory.js +2 -2
  101. package/lib/module/skia/web/JsiSkMaskFilterFactory.js.map +1 -1
  102. package/lib/module/skia/web/JsiSkMatrix.d.ts +2 -2
  103. package/lib/module/skia/web/JsiSkMatrix.js +6 -1
  104. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  105. package/lib/module/skia/web/JsiSkPaint.js +4 -4
  106. package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
  107. package/lib/module/skia/web/JsiSkPath.js +5 -5
  108. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  109. package/lib/module/skia/web/JsiSkPathEffectFactory.js +2 -2
  110. package/lib/module/skia/web/JsiSkPathEffectFactory.js.map +1 -1
  111. package/lib/module/skia/web/JsiSkPathFactory.js +2 -2
  112. package/lib/module/skia/web/JsiSkPathFactory.js.map +1 -1
  113. package/lib/module/skia/web/JsiSkPicture.js +2 -2
  114. package/lib/module/skia/web/JsiSkPicture.js.map +1 -1
  115. package/lib/module/skia/web/JsiSkShaderFactory.js +6 -6
  116. package/lib/module/skia/web/JsiSkShaderFactory.js.map +1 -1
  117. package/lib/module/skia/web/JsiSkVerticesFactory.js +2 -2
  118. package/lib/module/skia/web/JsiSkVerticesFactory.js.map +1 -1
  119. package/lib/typescript/src/dom/types/Common.d.ts +2 -2
  120. package/lib/typescript/src/external/reanimated/interpolators.d.ts +1 -0
  121. package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +2 -1
  122. package/lib/typescript/src/skia/core/Vector.d.ts +0 -5
  123. package/lib/typescript/src/skia/types/Canvas.d.ts +2 -2
  124. package/lib/typescript/src/skia/types/Matrix.d.ts +3 -13
  125. package/lib/typescript/src/skia/types/Matrix4.d.ts +60 -1
  126. package/lib/typescript/src/skia/types/Path/Path.d.ts +2 -2
  127. package/lib/typescript/src/skia/web/Host.d.ts +2 -3
  128. package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +2 -2
  129. package/package.json +2 -1
  130. package/src/dom/types/Common.ts +2 -2
  131. package/src/external/reanimated/interpolators.ts +20 -5
  132. package/src/external/reanimated/moduleWrapper.ts +6 -0
  133. package/src/renderer/Canvas.tsx +6 -13
  134. package/src/skia/core/Vector.ts +0 -7
  135. package/src/skia/types/Canvas.ts +2 -2
  136. package/src/skia/types/Matrix.ts +4 -13
  137. package/src/skia/types/Matrix4.ts +190 -81
  138. package/src/skia/types/Path/Path.ts +2 -2
  139. package/src/skia/web/Host.ts +4 -3
  140. package/src/skia/web/JsiSkCanvas.ts +22 -15
  141. package/src/skia/web/JsiSkColorFilterFactory.ts +5 -2
  142. package/src/skia/web/JsiSkFont.ts +3 -3
  143. package/src/skia/web/JsiSkImage.ts +14 -11
  144. package/src/skia/web/JsiSkImageFactory.ts +3 -3
  145. package/src/skia/web/JsiSkImageFilterFactory.ts +5 -5
  146. package/src/skia/web/JsiSkMaskFilterFactory.ts +6 -2
  147. package/src/skia/web/JsiSkMatrix.ts +12 -3
  148. package/src/skia/web/JsiSkPaint.ts +4 -4
  149. package/src/skia/web/JsiSkPath.ts +8 -5
  150. package/src/skia/web/JsiSkPathEffectFactory.ts +2 -2
  151. package/src/skia/web/JsiSkPathFactory.ts +2 -2
  152. package/src/skia/web/JsiSkPicture.ts +4 -4
  153. package/src/skia/web/JsiSkShaderFactory.ts +6 -6
  154. package/src/skia/web/JsiSkVerticesFactory.ts +2 -2
@@ -1,7 +1,20 @@
1
+ type Point = { x: number; y: number };
1
2
  type Vec2 = readonly [number, number];
2
3
  type Vec3 = readonly [number, number, number];
3
4
  type Vec4 = readonly [number, number, number, number];
4
5
 
6
+ export type Matrix3 = readonly [
7
+ number,
8
+ number,
9
+ number,
10
+ number,
11
+ number,
12
+ number,
13
+ number,
14
+ number,
15
+ number
16
+ ];
17
+
5
18
  export type Matrix4 = readonly [
6
19
  number,
7
20
  number,
@@ -78,17 +91,18 @@ export const Matrix4 = (): Matrix4 => {
78
91
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
79
92
  };
80
93
 
81
- const translate = (x: number, y: number, z: number): Matrix4 => {
94
+ /**
95
+ * @worklet
96
+ */
97
+ export const translate = (x: number, y: number, z: number = 0): Matrix4 => {
82
98
  "worklet";
83
99
  return [1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1];
84
100
  };
85
101
 
86
- const scale = (sx: number, sy: number, sz: number): Matrix4 => {
87
- "worklet";
88
- return [sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1];
89
- };
90
-
91
- const perspective = (p: number): Matrix4 => {
102
+ /**
103
+ * @worklet
104
+ */
105
+ export const perspective = (p: number): Matrix4 => {
92
106
  "worklet";
93
107
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -1 / p, 1];
94
108
  };
@@ -136,15 +150,6 @@ const rotatedUnitSinCos = (
136
150
  ];
137
151
  };
138
152
 
139
- const rotate = (axis: Vec3, value: number) => {
140
- "worklet";
141
- return rotatedUnitSinCos(
142
- normalizeVec(axis),
143
- Math.sin(value),
144
- Math.cos(value)
145
- );
146
- };
147
-
148
153
  const matrixVecMul4 = (m: Matrix4, v: Vec4) => {
149
154
  "worklet";
150
155
  const [vx, vy, vz, vw] = v;
@@ -165,7 +170,10 @@ export const mapPoint3d = (m: Matrix4, v: Vec3) => {
165
170
  return [r[0] / r[3], r[1] / r[3], r[2] / r[3]] as const;
166
171
  };
167
172
 
168
- const multiply4 = (a: Matrix4, b: Matrix4): Matrix4 => {
173
+ /**
174
+ * @worklet
175
+ */
176
+ export const multiply4 = (a: Matrix4, b: Matrix4): Matrix4 => {
169
177
  "worklet";
170
178
  const result = new Array(16).fill(0);
171
179
  for (let i = 0; i < 4; i++) {
@@ -190,77 +198,178 @@ const skewX = (angle: number): Matrix4 => {
190
198
  return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
191
199
  };
192
200
 
193
- const toMatrix3 = (m: Matrix4) => {
201
+ /**
202
+ * @worklet
203
+ */
204
+ export const toMatrix3 = (m: Matrix4) => {
194
205
  "worklet";
195
206
  return [m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]];
196
207
  };
197
208
 
209
+ const rotate = (axis: Vec3, value: number) => {
210
+ "worklet";
211
+ return rotatedUnitSinCos(
212
+ normalizeVec(axis),
213
+ Math.sin(value),
214
+ Math.cos(value)
215
+ );
216
+ };
217
+
218
+ /**
219
+ * @worklet
220
+ */
221
+ export const pivot = (m: Matrix4, p: Point) => {
222
+ "worklet";
223
+ return multiply4(translate(p.x, p.y), multiply4(m, translate(-p.x, -p.y)));
224
+ };
225
+
226
+ /**
227
+ * @worklet
228
+ */
229
+ export const scale = (
230
+ sx: number,
231
+ sy: number,
232
+ sz: number = 1,
233
+ p?: Point
234
+ ): Matrix4 => {
235
+ "worklet";
236
+ const m4: Matrix4 = [sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1];
237
+ if (p) {
238
+ return pivot(m4, p);
239
+ }
240
+ return m4;
241
+ };
242
+
243
+ const rotateAxis = (axis: Vec3, angle: number, p?: Point) => {
244
+ "worklet";
245
+ const result = rotate(axis, angle);
246
+ if (p) {
247
+ return pivot(result, p);
248
+ }
249
+ return result;
250
+ };
251
+
252
+ /**
253
+ * @worklet
254
+ */
255
+ export const rotateZ = (value: number, p?: Point) => {
256
+ "worklet";
257
+ return rotateAxis([0, 0, 1], value, p);
258
+ };
259
+
260
+ /**
261
+ * @worklet
262
+ */
263
+ export const rotateX = (value: number, p?: Point) => {
264
+ "worklet";
265
+ return rotateAxis([1, 0, 0], value, p);
266
+ };
267
+
268
+ /**
269
+ * @worklet
270
+ */
271
+ export const rotateY = (value: number, p?: Point) => {
272
+ "worklet";
273
+ return rotateAxis([0, 1, 0], value, p);
274
+ };
275
+
198
276
  /**
199
277
  * @worklet
200
278
  */
201
279
  export const processTransform3d = (transforms: Transforms3d) => {
202
280
  "worklet";
203
- return toMatrix3(
204
- transforms.reduce((acc, val) => {
205
- const key = Object.keys(val)[0] as Transform3dName;
206
- const transform = val as Pick<Transformations, typeof key>;
207
- if (key === "translateX") {
208
- const value = transform[key];
209
- return multiply4(acc, translate(value, 0, 0));
210
- }
211
- if (key === "translate") {
212
- const [x, y, z = 0] = transform[key];
213
- return multiply4(acc, translate(x, y, z));
214
- }
215
- if (key === "translateY") {
216
- const value = transform[key];
217
- return multiply4(acc, translate(0, value, 0));
218
- }
219
- if (key === "translateZ") {
220
- const value = transform[key];
221
- return multiply4(acc, translate(0, 0, value));
222
- }
223
- if (key === "scale") {
224
- const value = transform[key];
225
- return multiply4(acc, scale(value, value, 1));
226
- }
227
- if (key === "scaleX") {
228
- const value = transform[key];
229
- return multiply4(acc, scale(value, 1, 1));
230
- }
231
- if (key === "scaleY") {
232
- const value = transform[key];
233
- return multiply4(acc, scale(1, value, 1));
234
- }
235
- if (key === "skewX") {
236
- const value = transform[key];
237
- return multiply4(acc, skewX(value));
238
- }
239
- if (key === "skewY") {
240
- const value = transform[key];
241
- return multiply4(acc, skewY(value));
242
- }
243
- if (key === "rotateX") {
244
- const value = transform[key];
245
- return multiply4(acc, rotate([1, 0, 0], value));
246
- }
247
- if (key === "rotateY") {
248
- const value = transform[key];
249
- return multiply4(acc, rotate([0, 1, 0], value));
250
- }
251
- if (key === "perspective") {
252
- const value = transform[key];
253
- return multiply4(acc, perspective(value));
254
- }
255
- if (key === "rotate" || key === "rotateZ") {
256
- const value = transform[key];
257
- return multiply4(acc, rotate([0, 0, 1], value));
258
- }
259
- if (key === "matrix") {
260
- const value = transform[key];
261
- return multiply4(acc, value);
262
- }
263
- return exhaustiveCheck(key);
264
- }, Matrix4())
265
- );
281
+ return transforms.reduce((acc, val) => {
282
+ const key = Object.keys(val)[0] as Transform3dName;
283
+ const transform = val as Pick<Transformations, typeof key>;
284
+ if (key === "translateX") {
285
+ const value = transform[key];
286
+ return multiply4(acc, translate(value, 0, 0));
287
+ }
288
+ if (key === "translate") {
289
+ const [x, y, z = 0] = transform[key];
290
+ return multiply4(acc, translate(x, y, z));
291
+ }
292
+ if (key === "translateY") {
293
+ const value = transform[key];
294
+ return multiply4(acc, translate(0, value, 0));
295
+ }
296
+ if (key === "translateZ") {
297
+ const value = transform[key];
298
+ return multiply4(acc, translate(0, 0, value));
299
+ }
300
+ if (key === "scale") {
301
+ const value = transform[key];
302
+ return multiply4(acc, scale(value, value, 1));
303
+ }
304
+ if (key === "scaleX") {
305
+ const value = transform[key];
306
+ return multiply4(acc, scale(value, 1, 1));
307
+ }
308
+ if (key === "scaleY") {
309
+ const value = transform[key];
310
+ return multiply4(acc, scale(1, value, 1));
311
+ }
312
+ if (key === "skewX") {
313
+ const value = transform[key];
314
+ return multiply4(acc, skewX(value));
315
+ }
316
+ if (key === "skewY") {
317
+ const value = transform[key];
318
+ return multiply4(acc, skewY(value));
319
+ }
320
+ if (key === "rotateX") {
321
+ const value = transform[key];
322
+ return multiply4(acc, rotate([1, 0, 0], value));
323
+ }
324
+ if (key === "rotateY") {
325
+ const value = transform[key];
326
+ return multiply4(acc, rotate([0, 1, 0], value));
327
+ }
328
+ if (key === "perspective") {
329
+ const value = transform[key];
330
+ return multiply4(acc, perspective(value));
331
+ }
332
+ if (key === "rotate" || key === "rotateZ") {
333
+ const value = transform[key];
334
+ return multiply4(acc, rotate([0, 0, 1], value));
335
+ }
336
+ if (key === "matrix") {
337
+ const value = transform[key];
338
+ return multiply4(acc, value);
339
+ }
340
+ return exhaustiveCheck(key);
341
+ }, Matrix4());
342
+ };
343
+
344
+ /**
345
+ * @worklet
346
+ */
347
+ export const convertToColumnMajor = (rowMajorMatrix: Matrix4) => {
348
+ "worklet";
349
+
350
+ const colMajorMatrix = new Array<number>(16);
351
+ const size = 4;
352
+ for (let row = 0; row < size; row++) {
353
+ for (let col = 0; col < size; col++) {
354
+ colMajorMatrix[col * size + row] = rowMajorMatrix[row * size + col];
355
+ }
356
+ }
357
+ return colMajorMatrix;
358
+ };
359
+
360
+ /**
361
+ * @worklet
362
+ */
363
+ export const convertToAffineMatrix = (m4: number[]) => {
364
+ "worklet";
365
+ // Extracting the relevant components from the 4x4 matrix
366
+ const a = m4[0]; // Scale X
367
+ const b = m4[1]; // Skew Y
368
+ const c = m4[4]; // Skew X
369
+ const d = m4[5]; // Scale Y
370
+ const tx = m4[12]; // Translate X
371
+ const ty = m4[13]; // Translate Y
372
+
373
+ // Returning the 6-element affine transformation matrix
374
+ return [a, b, c, d, tx, ty];
266
375
  };
@@ -2,7 +2,7 @@ import type { SkRect } from "../Rect";
2
2
  import type { SkPoint } from "../Point";
3
3
  import type { SkRRect } from "../RRect";
4
4
  import type { StrokeJoin, StrokeCap } from "../Paint";
5
- import type { SkMatrix } from "../Matrix";
5
+ import type { InputMatrix, SkMatrix } from "../Matrix";
6
6
  import type { SkJSIInstance } from "../JsiInstance";
7
7
 
8
8
  /**
@@ -540,7 +540,7 @@ export interface SkPath extends SkJSIInstance<"Path"> {
540
540
  /**
541
541
  * Transforms the path by the specified matrix.
542
542
  */
543
- transform(m3: SkMatrix | number[]): SkPath;
543
+ transform(m3: InputMatrix): SkPath;
544
544
 
545
545
  /**
546
546
  * Interpolates between Path with point array of equal size.
@@ -41,10 +41,11 @@ export abstract class HostObject<T, N extends string> extends BaseHostObject<
41
41
  }
42
42
  }
43
43
 
44
- export const getCkEnum = (e: EmbindEnum, v: number): EmbindEnumEntity =>
44
+ export const getEnum = (e: EmbindEnum, v: number): EmbindEnumEntity =>
45
45
  Object.values(e).find(({ value }) => value === v);
46
- export const ckEnum = (value: number): EmbindEnumEntity => ({ value });
46
+
47
47
  export const optEnum = (
48
+ e: EmbindEnum,
48
49
  value: number | undefined
49
50
  ): EmbindEnumEntity | undefined =>
50
- value === undefined ? undefined : { value };
51
+ value === undefined ? undefined : getEnum(e, value);
@@ -25,7 +25,7 @@ import type {
25
25
  SkVertices,
26
26
  } from "../types";
27
27
 
28
- import { ckEnum, getCkEnum, HostObject } from "./Host";
28
+ import { getEnum, HostObject } from "./Host";
29
29
  import { JsiSkPaint } from "./JsiSkPaint";
30
30
  import { JsiSkRect } from "./JsiSkRect";
31
31
  import { JsiSkRRect } from "./JsiSkRRect";
@@ -113,8 +113,8 @@ export class JsiSkCanvas
113
113
  JsiSkImage.fromValue(img),
114
114
  left,
115
115
  top,
116
- ckEnum(fm),
117
- ckEnum(mm),
116
+ getEnum(this.CanvasKit.FilterMode, fm),
117
+ getEnum(this.CanvasKit.MipmapMode, mm),
118
118
  paint ? JsiSkPaint.fromValue(paint) : paint
119
119
  );
120
120
  }
@@ -130,7 +130,7 @@ export class JsiSkCanvas
130
130
  JsiSkImage.fromValue(img),
131
131
  Array.from(JsiSkRect.fromValue(this.CanvasKit, center)),
132
132
  JsiSkRect.fromValue(this.CanvasKit, dest),
133
- ckEnum(filter),
133
+ getEnum(this.CanvasKit.FilterMode, filter),
134
134
  paint ? JsiSkPaint.fromValue(paint) : paint
135
135
  );
136
136
  }
@@ -165,8 +165,8 @@ export class JsiSkCanvas
165
165
  JsiSkImage.fromValue(img),
166
166
  JsiSkRect.fromValue(this.CanvasKit, src),
167
167
  JsiSkRect.fromValue(this.CanvasKit, dest),
168
- ckEnum(fm),
169
- ckEnum(mm),
168
+ getEnum(this.CanvasKit.FilterMode, fm),
169
+ getEnum(this.CanvasKit.MipmapMode, mm),
170
170
  paint ? JsiSkPaint.fromValue(paint) : paint
171
171
  );
172
172
  }
@@ -186,7 +186,7 @@ export class JsiSkCanvas
186
186
  drawVertices(verts: SkVertices, mode: BlendMode, paint: SkPaint) {
187
187
  this.ref.drawVertices(
188
188
  JsiSkVertices.fromValue(verts),
189
- ckEnum(mode),
189
+ getEnum(this.CanvasKit.BlendMode, mode),
190
190
  JsiSkPaint.fromValue(paint)
191
191
  );
192
192
  }
@@ -202,7 +202,7 @@ export class JsiSkCanvas
202
202
  cubics.map(({ x, y }) => [x, y]).flat(),
203
203
  colors,
204
204
  texs ? texs.flatMap((p) => Array.from(JsiSkPoint.fromValue(p))) : texs,
205
- mode ? ckEnum(mode) : null,
205
+ mode ? getEnum(this.CanvasKit.BlendMode, mode) : null,
206
206
  paint ? JsiSkPaint.fromValue(paint) : undefined
207
207
  );
208
208
  }
@@ -213,7 +213,7 @@ export class JsiSkCanvas
213
213
 
214
214
  drawPoints(mode: PointMode, points: SkPoint[], paint: SkPaint) {
215
215
  this.ref.drawPoints(
216
- ckEnum(mode),
216
+ getEnum(this.CanvasKit.PointMode, mode),
217
217
  points.map(({ x, y }) => [x, y]).flat(),
218
218
  JsiSkPaint.fromValue(paint)
219
219
  );
@@ -341,7 +341,10 @@ export class JsiSkCanvas
341
341
  }
342
342
 
343
343
  drawColor(color: SkColor, blendMode?: BlendMode) {
344
- this.ref.drawColor(color, blendMode ? ckEnum(blendMode) : undefined);
344
+ this.ref.drawColor(
345
+ color,
346
+ blendMode ? getEnum(this.CanvasKit.BlendMode, blendMode) : undefined
347
+ );
345
348
  }
346
349
 
347
350
  clear(color: SkColor) {
@@ -349,13 +352,17 @@ export class JsiSkCanvas
349
352
  }
350
353
 
351
354
  clipPath(path: SkPath, op: ClipOp, doAntiAlias: boolean) {
352
- this.ref.clipPath(JsiSkPath.fromValue(path), ckEnum(op), doAntiAlias);
355
+ this.ref.clipPath(
356
+ JsiSkPath.fromValue(path),
357
+ getEnum(this.CanvasKit.PathOp, op),
358
+ doAntiAlias
359
+ );
353
360
  }
354
361
 
355
362
  clipRect(rect: SkRect, op: ClipOp, doAntiAlias: boolean) {
356
363
  this.ref.clipRect(
357
364
  JsiSkRect.fromValue(this.CanvasKit, rect),
358
- ckEnum(op),
365
+ getEnum(this.CanvasKit.PathOp, op),
359
366
  doAntiAlias
360
367
  );
361
368
  }
@@ -363,7 +370,7 @@ export class JsiSkCanvas
363
370
  clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean) {
364
371
  this.ref.clipRRect(
365
372
  JsiSkRRect.fromValue(this.CanvasKit, rrect),
366
- ckEnum(op),
373
+ getEnum(this.CanvasKit.PathOp, op),
367
374
  doAntiAlias
368
375
  );
369
376
  }
@@ -381,8 +388,8 @@ export class JsiSkCanvas
381
388
  width: imageInfo.width,
382
389
  height: imageInfo.height,
383
390
  colorSpace: this.CanvasKit.ColorSpace.SRGB,
384
- alphaType: getCkEnum(this.CanvasKit.AlphaType, imageInfo.alphaType),
385
- colorType: getCkEnum(this.CanvasKit.ColorType, imageInfo.colorType),
391
+ alphaType: getEnum(this.CanvasKit.AlphaType, imageInfo.alphaType),
392
+ colorType: getEnum(this.CanvasKit.ColorType, imageInfo.colorType),
386
393
  };
387
394
  return this.ref.readPixels(srcX, srcY, pxInfo);
388
395
  }
@@ -8,7 +8,7 @@ import type {
8
8
  BlendMode,
9
9
  } from "../types";
10
10
 
11
- import { ckEnum, Host } from "./Host";
11
+ import { getEnum, Host } from "./Host";
12
12
  import { JsiSkColorFilter } from "./JsiSkColorFilter";
13
13
 
14
14
  export class JsiSkColorFilterFactory
@@ -29,7 +29,10 @@ export class JsiSkColorFilterFactory
29
29
  MakeBlend(color: SkColor, mode: BlendMode) {
30
30
  return new JsiSkColorFilter(
31
31
  this.CanvasKit,
32
- this.CanvasKit.ColorFilter.MakeBlend(color, ckEnum(mode))
32
+ this.CanvasKit.ColorFilter.MakeBlend(
33
+ color,
34
+ getEnum(this.CanvasKit.BlendMode, mode)
35
+ )
33
36
  );
34
37
  }
35
38
 
@@ -10,7 +10,7 @@ import type {
10
10
  SkTypeface,
11
11
  } from "../types";
12
12
 
13
- import { HostObject, NotImplementedOnRNWeb, ckEnum } from "./Host";
13
+ import { HostObject, NotImplementedOnRNWeb, getEnum } from "./Host";
14
14
  import { JsiSkPaint } from "./JsiSkPaint";
15
15
  import { JsiSkPoint } from "./JsiSkPoint";
16
16
  import { JsiSkRect } from "./JsiSkRect";
@@ -100,7 +100,7 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
100
100
  }
101
101
 
102
102
  setEdging(edging: FontEdging) {
103
- this.ref.setEdging(ckEnum(edging));
103
+ this.ref.setEdging(getEnum(this.CanvasKit.FontEdging, edging));
104
104
  }
105
105
 
106
106
  setEmbeddedBitmaps(embeddedBitmaps: boolean) {
@@ -108,7 +108,7 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
108
108
  }
109
109
 
110
110
  setHinting(hinting: FontHinting) {
111
- this.ref.setHinting(ckEnum(hinting));
111
+ this.ref.setHinting(getEnum(this.CanvasKit.FontHinting, hinting));
112
112
  }
113
113
 
114
114
  setLinearMetrics(linearMetrics: boolean) {
@@ -15,7 +15,7 @@ import type {
15
15
  ImageInfo,
16
16
  } from "../types";
17
17
 
18
- import { ckEnum, getCkEnum, HostObject } from "./Host";
18
+ import { getEnum, HostObject } from "./Host";
19
19
  import { JsiSkMatrix } from "./JsiSkMatrix";
20
20
  import { JsiSkShader } from "./JsiSkShader";
21
21
 
@@ -77,10 +77,10 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
77
77
  return new JsiSkShader(
78
78
  this.CanvasKit,
79
79
  this.ref.makeShaderOptions(
80
- ckEnum(tx),
81
- ckEnum(ty),
82
- ckEnum(fm),
83
- ckEnum(mm),
80
+ getEnum(this.CanvasKit.TileMode, tx),
81
+ getEnum(this.CanvasKit.TileMode, ty),
82
+ getEnum(this.CanvasKit.FilterMode, fm),
83
+ getEnum(this.CanvasKit.MipmapMode, mm),
84
84
  localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined
85
85
  )
86
86
  );
@@ -96,8 +96,8 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
96
96
  return new JsiSkShader(
97
97
  this.CanvasKit,
98
98
  this.ref.makeShaderCubic(
99
- ckEnum(tx),
100
- ckEnum(ty),
99
+ getEnum(this.CanvasKit.TileMode, tx),
100
+ getEnum(this.CanvasKit.TileMode, ty),
101
101
  B,
102
102
  C,
103
103
  localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined
@@ -108,9 +108,12 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
108
108
  encodeToBytes(fmt?: ImageFormat, quality?: number) {
109
109
  let result: Uint8Array | null;
110
110
  if (fmt && quality) {
111
- result = this.ref.encodeToBytes(ckEnum(fmt), quality);
111
+ result = this.ref.encodeToBytes(
112
+ getEnum(this.CanvasKit.ImageFormat, fmt),
113
+ quality
114
+ );
112
115
  } else if (fmt) {
113
- result = this.ref.encodeToBytes(ckEnum(fmt));
116
+ result = this.ref.encodeToBytes(getEnum(this.CanvasKit.ImageFormat, fmt));
114
117
  } else {
115
118
  result = this.ref.encodeToBytes();
116
119
  }
@@ -131,11 +134,11 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
131
134
  colorSpace: this.CanvasKit.ColorSpace.SRGB,
132
135
  width: imageInfo?.width ?? info.width,
133
136
  height: imageInfo?.height ?? info.height,
134
- alphaType: getCkEnum(
137
+ alphaType: getEnum(
135
138
  this.CanvasKit.AlphaType,
136
139
  (imageInfo ?? info).alphaType
137
140
  ),
138
- colorType: getCkEnum(
141
+ colorType: getEnum(
139
142
  this.CanvasKit.ColorType,
140
143
  (imageInfo ?? info).colorType
141
144
  ),
@@ -3,7 +3,7 @@ import type { CanvasKit } from "canvaskit-wasm";
3
3
  import type { SkData, ImageInfo, SkImage } from "../types";
4
4
  import type { ImageFactory } from "../types/Image/ImageFactory";
5
5
 
6
- import { Host, ckEnum } from "./Host";
6
+ import { Host, getEnum } from "./Host";
7
7
  import { JsiSkImage } from "./JsiSkImage";
8
8
  import { JsiSkData } from "./JsiSkData";
9
9
 
@@ -33,9 +33,9 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
33
33
  // see toSkImageInfo() from canvaskit
34
34
  const image = this.CanvasKit.MakeImage(
35
35
  {
36
- alphaType: ckEnum(info.alphaType),
36
+ alphaType: getEnum(this.CanvasKit.AlphaType, info.alphaType),
37
37
  colorSpace: this.CanvasKit.ColorSpace.SRGB,
38
- colorType: ckEnum(info.colorType),
38
+ colorType: getEnum(this.CanvasKit.ColorType, info.colorType),
39
39
  height: info.height,
40
40
  width: info.width,
41
41
  },
@@ -13,7 +13,7 @@ import type {
13
13
  TileMode,
14
14
  } from "../types";
15
15
 
16
- import { Host, NotImplementedOnRNWeb, ckEnum } from "./Host";
16
+ import { Host, NotImplementedOnRNWeb, getEnum } from "./Host";
17
17
  import { JsiSkImageFilter } from "./JsiSkImageFilter";
18
18
  import { JsiSkColorFilter } from "./JsiSkColorFilter";
19
19
 
@@ -42,8 +42,8 @@ export class JsiSkImageFilterFactory
42
42
  const inputFilter =
43
43
  input === null ? null : JsiSkImageFilter.fromValue<ImageFilter>(input);
44
44
  const filter = this.CanvasKit.ImageFilter.MakeDisplacementMap(
45
- ckEnum(channelX),
46
- ckEnum(channelY),
45
+ getEnum(this.CanvasKit.ColorChannel, channelX),
46
+ getEnum(this.CanvasKit.ColorChannel, channelY),
47
47
  scale,
48
48
  JsiSkImageFilter.fromValue(in1),
49
49
  inputFilter
@@ -69,7 +69,7 @@ export class JsiSkImageFilterFactory
69
69
  this.CanvasKit.ImageFilter.MakeBlur(
70
70
  sigmaX,
71
71
  sigmaY,
72
- ckEnum(mode),
72
+ getEnum(this.CanvasKit.TileMode, mode),
73
73
  input === null ? null : JsiSkImageFilter.fromValue(input)
74
74
  )
75
75
  );
@@ -199,7 +199,7 @@ export class JsiSkImageFilterFactory
199
199
  );
200
200
  }
201
201
  const filter = this.CanvasKit.ImageFilter.MakeBlend(
202
- ckEnum(mode),
202
+ getEnum(this.CanvasKit.BlendMode, mode),
203
203
  JsiSkImageFilter.fromValue(background),
204
204
  inputFilter
205
205
  );
@@ -3,7 +3,7 @@ import type { CanvasKit } from "canvaskit-wasm";
3
3
  import type { BlurStyle } from "../types";
4
4
  import type { MaskFilterFactory } from "../types/MaskFilter";
5
5
 
6
- import { Host, ckEnum } from "./Host";
6
+ import { Host, getEnum } from "./Host";
7
7
  import { JsiSkMaskFilter } from "./JsiSkMaskFilter";
8
8
 
9
9
  export class JsiSkMaskFilterFactory extends Host implements MaskFilterFactory {
@@ -14,7 +14,11 @@ export class JsiSkMaskFilterFactory extends Host implements MaskFilterFactory {
14
14
  MakeBlur(style: BlurStyle, sigma: number, respectCTM: boolean) {
15
15
  return new JsiSkMaskFilter(
16
16
  this.CanvasKit,
17
- this.CanvasKit.MaskFilter.MakeBlur(ckEnum(style), sigma, respectCTM)
17
+ this.CanvasKit.MaskFilter.MakeBlur(
18
+ getEnum(this.CanvasKit.BlurStyle, style),
19
+ sigma,
20
+ respectCTM
21
+ )
18
22
  );
19
23
  }
20
24
  }