@shopify/react-native-skia 0.1.132 → 0.1.136

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. package/android/CMakeLists.txt +1 -1
  2. package/android/build.gradle +17 -2
  3. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +5 -0
  4. package/cpp/api/JsiSkFont.h +25 -1
  5. package/cpp/api/JsiSkImage.h +2 -19
  6. package/cpp/api/JsiSkPaint.h +5 -32
  7. package/cpp/api/JsiSkPath.h +4 -4
  8. package/cpp/rnskia/RNSkValueApi.h +6 -6
  9. package/cpp/rnskia/values/{RNSkDerivedValue.h → RNSkComputedValue.h} +7 -7
  10. package/ios/RNSkia-iOS/SkiaManager.mm +1 -1
  11. package/jestSetup.js +5 -0
  12. package/lib/commonjs/animation/functions/interpolate.js +3 -2
  13. package/lib/commonjs/animation/functions/interpolate.js.map +1 -1
  14. package/lib/commonjs/animation/functions/interpolateColors.js +2 -2
  15. package/lib/commonjs/animation/functions/interpolateColors.js.map +1 -1
  16. package/lib/commonjs/animation/functions/interpolatePaths.js +45 -11
  17. package/lib/commonjs/animation/functions/interpolatePaths.js.map +1 -1
  18. package/lib/commonjs/mock/index.js +134 -0
  19. package/lib/commonjs/mock/index.js.map +1 -0
  20. package/lib/commonjs/skia/core/Data.js +33 -43
  21. package/lib/commonjs/skia/core/Data.js.map +1 -1
  22. package/lib/commonjs/skia/core/Typeface.js +1 -1
  23. package/lib/commonjs/skia/core/Typeface.js.map +1 -1
  24. package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
  25. package/lib/commonjs/skia/types/Image/Image.js +5 -5
  26. package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
  27. package/lib/commonjs/skia/types/Paint/Paint.js +3 -3
  28. package/lib/commonjs/skia/types/Paint/Paint.js.map +1 -1
  29. package/lib/commonjs/skia/types/Path/Path.js +0 -1
  30. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  31. package/lib/commonjs/skia/types/Shader/Shader.js +1 -7
  32. package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
  33. package/lib/commonjs/skia/web/JsiSkCanvas.js +1 -1
  34. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  35. package/lib/commonjs/skia/web/JsiSkFont.js +6 -0
  36. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  37. package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -2
  38. package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +1 -1
  39. package/lib/commonjs/skia/web/JsiSkImage.js +10 -6
  40. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  41. package/lib/commonjs/skia/web/{JsiImageFilterFactory.js → JsiSkImageFilterFactory.js} +1 -1
  42. package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -0
  43. package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
  44. package/lib/commonjs/skia/web/JsiSkPath.js +65 -52
  45. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  46. package/lib/commonjs/skia/web/JsiSkShaderFactory.js +1 -1
  47. package/lib/commonjs/skia/web/JsiSkShaderFactory.js.map +1 -1
  48. package/lib/commonjs/skia/web/JsiSkVerticesFactory.js +23 -1
  49. package/lib/commonjs/skia/web/JsiSkVerticesFactory.js.map +1 -1
  50. package/lib/commonjs/skia/web/JsiSkia.js +2 -2
  51. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  52. package/lib/commonjs/values/api.js +1 -7
  53. package/lib/commonjs/values/api.js.map +1 -1
  54. package/lib/commonjs/values/api.web.js +3 -3
  55. package/lib/commonjs/values/api.web.js.map +1 -1
  56. package/lib/commonjs/values/hooks/index.js +4 -4
  57. package/lib/commonjs/values/hooks/index.js.map +1 -1
  58. package/lib/commonjs/values/hooks/useComputedValue.js +32 -0
  59. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -0
  60. package/lib/commonjs/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +4 -4
  61. package/lib/commonjs/values/web/RNSkComputedValue.js.map +1 -0
  62. package/lib/commonjs/values/web/api.js +3 -3
  63. package/lib/commonjs/values/web/api.js.map +1 -1
  64. package/lib/commonjs/views/SkiaView.web.js +15 -15
  65. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  66. package/lib/commonjs/web/index.js +4 -2
  67. package/lib/commonjs/web/index.js.map +1 -1
  68. package/lib/module/animation/functions/interpolate.js +2 -2
  69. package/lib/module/animation/functions/interpolate.js.map +1 -1
  70. package/lib/module/animation/functions/interpolateColors.js +1 -1
  71. package/lib/module/animation/functions/interpolateColors.js.map +1 -1
  72. package/lib/module/animation/functions/interpolatePaths.js +44 -11
  73. package/lib/module/animation/functions/interpolatePaths.js.map +1 -1
  74. package/lib/module/mock/index.js +108 -0
  75. package/lib/module/mock/index.js.map +1 -0
  76. package/lib/module/skia/core/Data.js +32 -41
  77. package/lib/module/skia/core/Data.js.map +1 -1
  78. package/lib/module/skia/core/Typeface.js +1 -1
  79. package/lib/module/skia/core/Typeface.js.map +1 -1
  80. package/lib/module/skia/types/Font/Font.js.map +1 -1
  81. package/lib/module/skia/types/Image/Image.js +5 -5
  82. package/lib/module/skia/types/Image/Image.js.map +1 -1
  83. package/lib/module/skia/types/Paint/Paint.js +3 -3
  84. package/lib/module/skia/types/Paint/Paint.js.map +1 -1
  85. package/lib/module/skia/types/Path/Path.js +0 -1
  86. package/lib/module/skia/types/Path/Path.js.map +1 -1
  87. package/lib/module/skia/types/Shader/Shader.js +1 -7
  88. package/lib/module/skia/types/Shader/Shader.js.map +1 -1
  89. package/lib/module/skia/web/JsiSkCanvas.js +1 -1
  90. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  91. package/lib/module/skia/web/JsiSkFont.js +6 -0
  92. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  93. package/lib/module/skia/web/JsiSkFontMgr.js +0 -2
  94. package/lib/module/skia/web/JsiSkFontMgr.js.map +1 -1
  95. package/lib/module/skia/web/JsiSkImage.js +10 -7
  96. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  97. package/lib/module/skia/web/{JsiImageFilterFactory.js → JsiSkImageFilterFactory.js} +1 -1
  98. package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -0
  99. package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
  100. package/lib/module/skia/web/JsiSkPath.js +65 -52
  101. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  102. package/lib/module/skia/web/JsiSkShaderFactory.js +1 -1
  103. package/lib/module/skia/web/JsiSkShaderFactory.js.map +1 -1
  104. package/lib/module/skia/web/JsiSkVerticesFactory.js +24 -1
  105. package/lib/module/skia/web/JsiSkVerticesFactory.js.map +1 -1
  106. package/lib/module/skia/web/JsiSkia.js +1 -1
  107. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  108. package/lib/module/values/api.js +0 -4
  109. package/lib/module/values/api.js.map +1 -1
  110. package/lib/module/values/api.web.js +1 -1
  111. package/lib/module/values/api.web.js.map +1 -1
  112. package/lib/module/values/hooks/index.js +1 -1
  113. package/lib/module/values/hooks/index.js.map +1 -1
  114. package/lib/module/values/hooks/useComputedValue.js +18 -0
  115. package/lib/module/values/hooks/useComputedValue.js.map +1 -0
  116. package/lib/module/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +2 -2
  117. package/lib/module/values/web/RNSkComputedValue.js.map +1 -0
  118. package/lib/module/values/web/api.js +3 -3
  119. package/lib/module/values/web/api.js.map +1 -1
  120. package/lib/module/views/SkiaView.web.js +15 -15
  121. package/lib/module/views/SkiaView.web.js.map +1 -1
  122. package/lib/module/web/index.js +3 -1
  123. package/lib/module/web/index.js.map +1 -1
  124. package/lib/typescript/jestSetup.d.ts +1 -0
  125. package/lib/typescript/src/animation/functions/interpolate.d.ts +6 -0
  126. package/lib/typescript/src/animation/functions/interpolatePaths.d.ts +3 -1
  127. package/lib/typescript/src/mock/index.d.ts +16 -0
  128. package/lib/typescript/src/renderer/Canvas.d.ts +1 -1
  129. package/lib/typescript/src/skia/core/Data.d.ts +3 -3
  130. package/lib/typescript/src/skia/types/Font/Font.d.ts +6 -0
  131. package/lib/typescript/src/skia/types/Image/Image.d.ts +5 -5
  132. package/lib/typescript/src/skia/types/Paint/Paint.d.ts +3 -3
  133. package/lib/typescript/src/skia/types/Path/Path.d.ts +1 -2
  134. package/lib/typescript/src/skia/types/RuntimeEffect/RuntimeEffect.d.ts +1 -0
  135. package/lib/typescript/src/skia/types/Skia.d.ts +1 -1
  136. package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -0
  137. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +3 -3
  138. package/lib/typescript/src/skia/web/{JsiImageFilterFactory.d.ts → JsiSkImageFilterFactory.d.ts} +0 -0
  139. package/lib/typescript/src/skia/web/JsiSkPaint.d.ts +1 -1
  140. package/lib/typescript/src/values/api.d.ts +0 -1
  141. package/lib/typescript/src/values/api.web.d.ts +1 -1
  142. package/lib/typescript/src/values/hooks/index.d.ts +1 -1
  143. package/lib/typescript/src/values/hooks/{useDerivedValue.d.ts → useComputedValue.d.ts} +2 -1
  144. package/lib/typescript/src/values/types.d.ts +2 -2
  145. package/lib/typescript/src/values/web/{RNSkDerivedValue.d.ts → RNSkComputedValue.d.ts} +1 -1
  146. package/package.json +4 -3
  147. package/src/animation/functions/interpolate.ts +4 -2
  148. package/src/animation/functions/interpolateColors.ts +1 -1
  149. package/src/animation/functions/interpolatePaths.ts +59 -10
  150. package/src/mock/index.ts +110 -0
  151. package/src/skia/core/Data.ts +67 -50
  152. package/src/skia/core/Typeface.ts +6 -1
  153. package/src/skia/types/Font/Font.ts +7 -0
  154. package/src/skia/types/Image/Image.ts +4 -4
  155. package/src/skia/types/Paint/Paint.ts +1 -1
  156. package/src/skia/types/Path/Path.ts +0 -1
  157. package/src/skia/types/RuntimeEffect/RuntimeEffect.ts +1 -0
  158. package/src/skia/types/Shader/Shader.ts +3 -5
  159. package/src/skia/types/Skia.ts +1 -1
  160. package/src/skia/web/JsiSkCanvas.ts +2 -2
  161. package/src/skia/web/JsiSkFont.ts +6 -0
  162. package/src/skia/web/JsiSkFontMgr.ts +0 -4
  163. package/src/skia/web/JsiSkImage.ts +37 -16
  164. package/src/skia/web/{JsiImageFilterFactory.ts → JsiSkImageFilterFactory.ts} +0 -0
  165. package/src/skia/web/JsiSkPaint.ts +1 -1
  166. package/src/skia/web/JsiSkPath.ts +64 -47
  167. package/src/skia/web/JsiSkShaderFactory.ts +4 -1
  168. package/src/skia/web/JsiSkVerticesFactory.ts +15 -1
  169. package/src/skia/web/JsiSkia.ts +2 -2
  170. package/src/values/api.ts +0 -2
  171. package/src/values/api.web.ts +1 -1
  172. package/src/values/hooks/index.ts +1 -1
  173. package/src/values/hooks/useComputedValue.ts +23 -0
  174. package/src/values/types.ts +2 -2
  175. package/src/values/web/{RNSkDerivedValue.ts → RNSkComputedValue.ts} +1 -1
  176. package/src/values/web/api.ts +3 -3
  177. package/src/views/SkiaView.web.tsx +29 -28
  178. package/src/web/index.ts +3 -1
  179. package/lib/commonjs/skia/web/JsiImageFilterFactory.js.map +0 -1
  180. package/lib/commonjs/values/hooks/useDerivedValue.js +0 -25
  181. package/lib/commonjs/values/hooks/useDerivedValue.js.map +0 -1
  182. package/lib/commonjs/values/web/RNSkDerivedValue.js.map +0 -1
  183. package/lib/module/skia/web/JsiImageFilterFactory.js.map +0 -1
  184. package/lib/module/values/hooks/useDerivedValue.js +0 -14
  185. package/lib/module/values/hooks/useDerivedValue.js.map +0 -1
  186. package/lib/module/values/web/RNSkDerivedValue.js.map +0 -1
  187. package/src/values/hooks/useDerivedValue.ts +0 -18
@@ -17,6 +17,29 @@ import { ckEnum, HostObject, optEnum, toValue } from "./Host";
17
17
  import { JsiSkPoint } from "./JsiSkPoint";
18
18
  import { JsiSkRect } from "./JsiSkRect";
19
19
 
20
+ const CommandCount = {
21
+ [PathVerb.Move]: 3,
22
+ [PathVerb.Line]: 3,
23
+ [PathVerb.Quad]: 5,
24
+ [PathVerb.Conic]: 6,
25
+ [PathVerb.Cubic]: 7,
26
+ [PathVerb.Close]: 1,
27
+ };
28
+
29
+ const areCmdsInterpolatable = (cmd1: PathCommand[], cmd2: PathCommand[]) => {
30
+ if (cmd1.length !== cmd2.length) {
31
+ return false;
32
+ }
33
+ for (let i = 0; i < cmd1.length; i++) {
34
+ if (cmd1[i][0] !== cmd2[i][0]) {
35
+ return false;
36
+ } else if (cmd1[i][0] === PathVerb.Conic && cmd1[i][5] !== cmd2[i][5]) {
37
+ return false;
38
+ }
39
+ }
40
+ return true;
41
+ };
42
+
20
43
  export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
21
44
  constructor(CanvasKit: CanvasKit, ref: Path) {
22
45
  super(CanvasKit, ref, "Path");
@@ -300,20 +323,25 @@ export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
300
323
  // throw new NotImplementedOnRNWeb();
301
324
  const cmd1 = this.toCmds();
302
325
  const cmd2 = end.toCmds();
303
- if (cmd1.length !== cmd2.length) {
326
+ if (!areCmdsInterpolatable(cmd1, cmd2)) {
304
327
  return null;
305
328
  }
306
329
  const interpolated: PathCommand[] = [];
307
- for (let i = 0; i < cmd1.length; i++) {
308
- if (cmd1[i][0] !== cmd2[i][0]) {
309
- return null;
310
- }
311
- const cmd: PathCommand = [cmd1[i][0]];
312
- for (let j = 1; j < cmd1[i].length; j++) {
313
- cmd.push(cmd2[i][j] + (cmd1[i][j] - cmd2[i][j]) * t);
314
- }
315
- interpolated.push(cmd);
316
- }
330
+ cmd1.forEach((cmd, i) => {
331
+ const interpolatedCmd = [cmd[0]];
332
+ interpolated.push(interpolatedCmd);
333
+ cmd.forEach((c, j) => {
334
+ if (j === 0) {
335
+ return;
336
+ }
337
+ if (interpolatedCmd[0] === PathVerb.Conic && j === 5) {
338
+ interpolatedCmd.push(c);
339
+ } else {
340
+ const c2 = cmd2[i][j];
341
+ interpolatedCmd.push(c2 + (c - c2) * t);
342
+ }
343
+ });
344
+ });
317
345
  const path = this.CanvasKit.Path.MakeFromCmds(interpolated.flat());
318
346
  if (path === null) {
319
347
  return null;
@@ -326,44 +354,33 @@ export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
326
354
  // throw new NotImplementedOnRNWeb();
327
355
  const cmd1 = this.toCmds();
328
356
  const cmd2 = path2.toCmds();
329
- if (cmd1.length !== cmd2.length) {
330
- return false;
331
- }
332
- for (let i = 0; i < cmd1.length; i++) {
333
- if (cmd1[i][0] !== cmd2[i][0]) {
334
- return false;
335
- }
336
- }
337
- return true;
338
- }
339
-
340
- toCmds(): PathCommand[] {
341
- const cmds: PathCommand[] = [];
342
- let cmd = [];
343
- const flatCmds = this.ref.toCmds();
344
- const CmdCount = {
345
- [PathVerb.Move]: 3,
346
- [PathVerb.Line]: 3,
347
- [PathVerb.Quad]: 5,
348
- [PathVerb.Conic]: 6,
349
- [PathVerb.Cubic]: 7,
350
- [PathVerb.Close]: 0,
351
- [PathVerb.Done]: 0,
352
- };
353
- for (let i = 0; i < flatCmds.length; i++) {
354
- if (cmd.length === 0 && flatCmds[i] === PathVerb.Done) {
355
- break;
357
+ return areCmdsInterpolatable(cmd1, cmd2);
358
+ }
359
+
360
+ toCmds() {
361
+ const cmds = this.ref.toCmds();
362
+ const result = cmds.reduce<PathCommand[]>((acc, cmd, i) => {
363
+ if (i === 0) {
364
+ acc.push([]);
356
365
  }
357
- const c = flatCmds[i];
358
- cmd.push(c);
359
- if (cmd.length > 1) {
360
- const length = CmdCount[cmd[0] as PathVerb];
361
- if (cmd.length === length) {
362
- cmds.push(cmd);
363
- cmd = [];
366
+ const current = acc[acc.length - 1];
367
+ if (current.length === 0) {
368
+ current.push(cmd);
369
+ const length = CommandCount[current[0] as PathVerb];
370
+ if (current.length === length && i !== cmds.length - 1) {
371
+ acc.push([]);
372
+ }
373
+ } else {
374
+ const length = CommandCount[current[0] as PathVerb];
375
+ if (current.length < length) {
376
+ current.push(cmd);
377
+ }
378
+ if (current.length === length && i !== cmds.length - 1) {
379
+ acc.push([]);
364
380
  }
365
381
  }
366
- }
367
- return cmds.concat(cmd);
382
+ return acc;
383
+ }, []);
384
+ return result;
368
385
  }
369
386
  }
@@ -172,7 +172,10 @@ export class JsiSkShaderFactory extends Host implements ShaderFactory {
172
172
  MakeColor(color: SkColor) {
173
173
  return new JsiSkShader(
174
174
  this.CanvasKit,
175
- this.CanvasKit.Shader.MakeColor(toValue(color))
175
+ this.CanvasKit.Shader.MakeColor(
176
+ toValue(color),
177
+ this.CanvasKit.ColorSpace.SRGB
178
+ )
176
179
  );
177
180
  }
178
181
  }
@@ -5,6 +5,20 @@ import type { SkColor, SkPoint, VertexMode } from "../types";
5
5
  import { ckEnum } from "./Host";
6
6
  import { JsiSkVertices } from "./JsiSkVertices";
7
7
 
8
+ const concat = (...arrays: Float32Array[]) => {
9
+ let totalLength = 0;
10
+ for (const arr of arrays) {
11
+ totalLength += arr.length;
12
+ }
13
+ const result = new Float32Array(totalLength);
14
+ let offset = 0;
15
+ for (const arr of arrays) {
16
+ result.set(arr, offset);
17
+ offset += arr.length;
18
+ }
19
+ return result;
20
+ };
21
+
8
22
  export const MakeVertices = (
9
23
  CanvasKit: CanvasKit,
10
24
  mode: VertexMode,
@@ -20,7 +34,7 @@ export const MakeVertices = (
20
34
  ckEnum(mode),
21
35
  positions.map(({ x, y }) => [x, y]).flat(),
22
36
  (textureCoordinates || []).map(({ x, y }) => [x, y]).flat(),
23
- colors,
37
+ !colors ? null : colors.reduce((a, c) => concat(a, c)),
24
38
  indices,
25
39
  isVolatile
26
40
  )
@@ -27,7 +27,7 @@ import { JsiSkColorFilterFactory } from "./JsiSkColorFilterFactory";
27
27
  import { JsiSkTypefaceFactory } from "./JsiSkTypefaceFactory";
28
28
  import { JsiSkMaskFilterFactory } from "./JsiSkMaskFilterFactory";
29
29
  import { JsiSkRuntimeEffectFactory } from "./JsiSkRuntimeEffectFactory";
30
- import { JsiSkImageFilterFactory } from "./JsiImageFilterFactory";
30
+ import { JsiSkImageFilterFactory } from "./JsiSkImageFilterFactory";
31
31
  import { JsiSkShaderFactory } from "./JsiSkShaderFactory";
32
32
  import { JsiSkPathEffectFactory } from "./JsiSkPathEffectFactory";
33
33
  import { JsiSkDataFactory } from "./JsiSkDataFactory";
@@ -63,7 +63,7 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
63
63
  new JsiSkPictureRecorder(CanvasKit, new CanvasKit.PictureRecorder()),
64
64
  Picture: new JsiSkPictureFactory(CanvasKit),
65
65
  Path: new JsiSkPathFactory(CanvasKit),
66
- Matrix: (matrix?: number[]) =>
66
+ Matrix: (matrix?: readonly number[]) =>
67
67
  new JsiSkMatrix(
68
68
  CanvasKit,
69
69
  matrix
package/src/values/api.ts CHANGED
@@ -6,5 +6,3 @@ declare global {
6
6
 
7
7
  const { SkiaValueApi } = global;
8
8
  export const ValueApi = SkiaValueApi;
9
-
10
- export const { createValue, createDerivedValue } = ValueApi;
@@ -2,4 +2,4 @@ import { ValueApi as ValueApiWeb } from "./web";
2
2
 
3
3
  export const ValueApi = ValueApiWeb;
4
4
 
5
- export const { createValue, createDerivedValue } = ValueApi;
5
+ export const { createValue, createComputedValue } = ValueApi;
@@ -1,4 +1,4 @@
1
1
  export * from "./useClockValue";
2
- export * from "./useDerivedValue";
2
+ export * from "./useComputedValue";
3
3
  export * from "./useValue";
4
4
  export * from "./useValueEffect";
@@ -0,0 +1,23 @@
1
+ import { useMemo } from "react";
2
+
3
+ import { ValueApi } from "../api";
4
+ import { isValue } from "../../renderer/processors/Animations";
5
+
6
+ /**
7
+ * Creates a new computed value - a value that will calculate its value depending
8
+ * on other values.
9
+ * @param cb Callback to calculate new value
10
+ * @param values Dependant values
11
+ * @returns A readonly value
12
+ */
13
+ export const useComputedValue = <R>(cb: () => R, values: unknown[]) =>
14
+ useMemo(
15
+ () => ValueApi.createComputedValue<R>(cb, values.filter(isValue)),
16
+ // eslint-disable-next-line react-hooks/exhaustive-deps
17
+ values
18
+ );
19
+
20
+ export const useDerivedValue = <R>(cb: () => R, values: unknown[]) => {
21
+ console.warn("useDerivedValue is deprecated. Use useComputedValue instead.");
22
+ return useComputedValue(cb, values);
23
+ };
@@ -46,10 +46,10 @@ export interface ISkiaValueApi {
46
46
  */
47
47
  createValue: <T>(initialValue: T) => SkiaMutableValue<T>;
48
48
  /**
49
- * Creates a derived value. This is a calculated value that returns the result of
49
+ * Creates a computed value. This is a calculated value that returns the result of
50
50
  * a function that is called with the values of the dependencies.
51
51
  */
52
- createDerivedValue: <R>(
52
+ createComputedValue: <R>(
53
53
  cb: () => R,
54
54
  values: Array<SkiaValue<unknown>>
55
55
  ) => SkiaValue<R>;
@@ -2,7 +2,7 @@ import type { DependencyList } from "react";
2
2
 
3
3
  import { RNSkReadonlyValue } from "./RNSkReadonlyValue";
4
4
 
5
- export class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {
5
+ export class RNSkComputedValue<T> extends RNSkReadonlyValue<T> {
6
6
  constructor(callback: () => T, dependencies: DependencyList) {
7
7
  // Initialize dependencies - we can't call this yet, since
8
8
  // super if not called and it requires a start value to be set.
@@ -9,18 +9,18 @@ import type {
9
9
 
10
10
  import { RNSkAnimation } from "./RNSkAnimation";
11
11
  import { RNSkClockValue } from "./RNSkClockValue";
12
- import { RNSkDerivedValue } from "./RNSkDerivedValue";
12
+ import { RNSkComputedValue } from "./RNSkComputedValue";
13
13
  import { RNSkValue } from "./RNSkValue";
14
14
 
15
15
  export const ValueApi: ISkiaValueApi = {
16
16
  createValue: function <T>(initialValue: T): SkiaMutableValue<T> {
17
17
  return new RNSkValue(initialValue);
18
18
  },
19
- createDerivedValue: function <R>(
19
+ createComputedValue: function <R>(
20
20
  cb: () => R,
21
21
  values: SkiaValue<unknown>[]
22
22
  ): SkiaValue<R> {
23
- return new RNSkDerivedValue(cb, values);
23
+ return new RNSkComputedValue(cb, values);
24
24
  },
25
25
  createClockValue: function (): SkiaClockValue {
26
26
  return new RNSkClockValue(requestAnimationFrame.bind(window));
@@ -36,24 +36,27 @@ export class SkiaView extends React.Component<
36
36
  }
37
37
 
38
38
  private onLayout(evt: LayoutChangeEvent) {
39
- this.setState({
40
- width: evt.nativeEvent.layout.width,
41
- height: evt.nativeEvent.layout.height,
42
- });
43
- // Reset canvas / surface on layout change
44
- if (this._canvasRef.current) {
45
- // Create surface
46
- this._surface = new JsiSkSurface(
47
- global.CanvasKit,
48
- global.CanvasKit.MakeCanvasSurface(this._canvasRef.current)!
49
- );
50
- // Get canvas and repaint
51
- if (this._surface) {
52
- this._canvas = this._surface.getCanvas();
53
- this.requestRedraw();
54
- this.redraw();
39
+ this.setState(
40
+ {
41
+ width: evt.nativeEvent.layout.width,
42
+ height: evt.nativeEvent.layout.height,
43
+ },
44
+ () => {
45
+ // Reset canvas / surface on layout change
46
+ if (this._canvasRef.current) {
47
+ // Create surface
48
+ this._surface = new JsiSkSurface(
49
+ global.CanvasKit,
50
+ global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)!
51
+ );
52
+ // Get canvas and repaint
53
+ if (this._surface) {
54
+ this._canvas = this._surface.getCanvas();
55
+ this.requestRedraw();
56
+ }
57
+ }
55
58
  }
56
- }
59
+ );
57
60
  }
58
61
 
59
62
  componentDidMount() {
@@ -175,17 +178,15 @@ export class SkiaView extends React.Component<
175
178
  const { mode, debug = false, ...viewProps } = this.props;
176
179
  return (
177
180
  <View {...viewProps} onLayout={this.onLayout.bind(this)}>
178
- {this.state.width > -1 ? (
179
- <canvas
180
- ref={this._canvasRef}
181
- width={`${this.state.width}px`}
182
- height={`${this.state.height}px`}
183
- onPointerDown={this.handleTouchStart.bind(this)}
184
- onPointerMove={this.handleTouchMove.bind(this)}
185
- onPointerUp={this.handleTouchEnd.bind(this)}
186
- onPointerCancel={this.handleTouchCancel.bind(this)}
187
- />
188
- ) : null}
181
+ <canvas
182
+ ref={this._canvasRef}
183
+ width={this.state.width}
184
+ height={this.state.height}
185
+ onPointerDown={this.handleTouchStart.bind(this)}
186
+ onPointerMove={this.handleTouchMove.bind(this)}
187
+ onPointerUp={this.handleTouchEnd.bind(this)}
188
+ onPointerCancel={this.handleTouchCancel.bind(this)}
189
+ />
189
190
  </View>
190
191
  );
191
192
  }
package/src/web/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- import CanvasKitInit from "canvaskit-wasm";
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-expect-error
3
+ import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
2
4
  import type { CanvasKit as CanvasKitType } from "canvaskit-wasm";
3
5
 
4
6
  declare global {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["JsiImageFilterFactory.ts"],"names":["JsiSkImageFilterFactory","Host","constructor","CanvasKit","MakeOffset","_dx","_dy","_input","NotImplementedOnRNWeb","MakeDisplacementMap","_channelX","_channelY","_scale","_in1","MakeShader","_shader","MakeBlur","sigmaX","sigmaY","mode","input","JsiSkImageFilter","ImageFilter","MakeColorFilter","cf","MakeCompose","outer","inner","MakeDropShadow","_sigmaX","_sigmaY","_color","_cropRect","MakeDropShadowOnly","MakeErode","_rx","_ry","MakeDilate","MakeBlend","_mode","_background","_foreground","MakeRuntimeShader","_builder","_childShaderName"],"mappings":";;;;;;;AAeA;;AACA;;AAEO,MAAMA,uBAAN,SACGC,UADH,CAGP;AACEC,EAAAA,WAAW,CAACC,SAAD,EAAuB;AAChC,UAAMA,SAAN;AACD;;AAEDC,EAAAA,UAAU,CACRC,GADQ,EAERC,GAFQ,EAGRC,MAHQ,EAIO;AACf,UAAM,IAAIC,2BAAJ,EAAN;AACD;;AAEDC,EAAAA,mBAAmB,CACjBC,SADiB,EAEjBC,SAFiB,EAGjBC,MAHiB,EAIjBC,IAJiB,EAKjBN,MALiB,EAMF;AACf,UAAM,IAAIC,2BAAJ,EAAN;AACD;;AAEDM,EAAAA,UAAU,CAACC,OAAD,EAAoBR,MAApB,EAAiE;AACzE,UAAM,IAAIC,2BAAJ,EAAN;AACD;;AAEDQ,EAAAA,QAAQ,CACNC,MADM,EAENC,MAFM,EAGNC,IAHM,EAINC,KAJM,EAKN;AACA,WAAO,IAAIC,kCAAJ,CACL,KAAKlB,SADA,EAEL,KAAKA,SAAL,CAAemB,WAAf,CAA2BN,QAA3B,CACEC,MADF,EAEEC,MAFF,EAGE,kBAAOC,IAAP,CAHF,EAIEC,KAAK,KAAK,IAAV,GAAiB,IAAjB,GAAwB,mBAAQA,KAAR,CAJ1B,CAFK,CAAP;AASD;;AAEDG,EAAAA,eAAe,CAACC,EAAD,EAAoBJ,KAApB,EAAiD;AAC9D,WAAO,IAAIC,kCAAJ,CACL,KAAKlB,SADA,EAEL,KAAKA,SAAL,CAAemB,WAAf,CAA2BC,eAA3B,CACE,mBAAQC,EAAR,CADF,EAEEJ,KAAK,KAAK,IAAV,GAAiB,IAAjB,GAAwB,mBAAQA,KAAR,CAF1B,CAFK,CAAP;AAOD;;AAEDK,EAAAA,WAAW,CAACC,KAAD,EAA8BC,KAA9B,EAA2D;AACpE,WAAO,IAAIN,kCAAJ,CACL,KAAKlB,SADA,EAEL,KAAKA,SAAL,CAAemB,WAAf,CAA2BG,WAA3B,CACEC,KAAK,KAAK,IAAV,GAAiB,IAAjB,GAAwB,mBAAQA,KAAR,CAD1B,EAEEC,KAAK,KAAK,IAAV,GAAiB,IAAjB,GAAwB,mBAAQA,KAAR,CAF1B,CAFK,CAAP;AAOD;;AAEDC,EAAAA,cAAc,CACZvB,GADY,EAEZC,GAFY,EAGZuB,OAHY,EAIZC,OAJY,EAKZC,MALY,EAMZxB,MANY,EAOZyB,SAPY,EAQG;AACf,UAAM,IAAIxB,2BAAJ,EAAN;AACD;;AAEDyB,EAAAA,kBAAkB,CAChB5B,GADgB,EAEhBC,GAFgB,EAGhBuB,OAHgB,EAIhBC,OAJgB,EAKhBC,MALgB,EAMhBxB,MANgB,EAOhByB,SAPgB,EAQD;AACf,UAAM,IAAIxB,2BAAJ,EAAN;AACD;;AAED0B,EAAAA,SAAS,CACPC,GADO,EAEPC,GAFO,EAGP7B,MAHO,EAIPyB,SAJO,EAKQ;AACf,UAAM,IAAIxB,2BAAJ,EAAN;AACD;;AAED6B,EAAAA,UAAU,CACRF,GADQ,EAERC,GAFQ,EAGR7B,MAHQ,EAIRyB,SAJQ,EAKO;AACf,UAAM,IAAIxB,2BAAJ,EAAN;AACD;;AAED8B,EAAAA,SAAS,CACPC,KADO,EAEPC,WAFO,EAGPC,WAHO,EAIPT,SAJO,EAKQ;AACf,UAAM,IAAIxB,2BAAJ,EAAN;AACD;;AAEDkC,EAAAA,iBAAiB,CACfC,QADe,EAEfC,gBAFe,EAGfrC,MAHe,EAIA;AACf,UAAM,IAAIC,2BAAJ,EAAN;AACD;;AAzHH","sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type {\n ColorChannel,\n ImageFilterFactory,\n SkColor,\n SkColorFilter,\n SkImageFilter,\n BlendMode,\n SkRect,\n SkRuntimeShaderBuilder,\n SkShader,\n TileMode,\n} from \"../types\";\n\nimport { Host, NotImplementedOnRNWeb, ckEnum, toValue } from \"./Host\";\nimport { JsiSkImageFilter } from \"./JsiSkImageFilter\";\n\nexport class JsiSkImageFilterFactory\n extends Host\n implements ImageFilterFactory\n{\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeOffset(\n _dx: number,\n _dy: number,\n _input: SkImageFilter | null\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeDisplacementMap(\n _channelX: ColorChannel,\n _channelY: ColorChannel,\n _scale: number,\n _in1: SkImageFilter,\n _input: SkImageFilter | null\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeShader(_shader: SkShader, _input: SkImageFilter | null): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeBlur(\n sigmaX: number,\n sigmaY: number,\n mode: TileMode,\n input: SkImageFilter | null\n ) {\n return new JsiSkImageFilter(\n this.CanvasKit,\n this.CanvasKit.ImageFilter.MakeBlur(\n sigmaX,\n sigmaY,\n ckEnum(mode),\n input === null ? null : toValue(input)\n )\n );\n }\n\n MakeColorFilter(cf: SkColorFilter, input: SkImageFilter | null) {\n return new JsiSkImageFilter(\n this.CanvasKit,\n this.CanvasKit.ImageFilter.MakeColorFilter(\n toValue(cf),\n input === null ? null : toValue(input)\n )\n );\n }\n\n MakeCompose(outer: SkImageFilter | null, inner: SkImageFilter | null) {\n return new JsiSkImageFilter(\n this.CanvasKit,\n this.CanvasKit.ImageFilter.MakeCompose(\n outer === null ? null : toValue(outer),\n inner === null ? null : toValue(inner)\n )\n );\n }\n\n MakeDropShadow(\n _dx: number,\n _dy: number,\n _sigmaX: number,\n _sigmaY: number,\n _color: SkColor,\n _input: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeDropShadowOnly(\n _dx: number,\n _dy: number,\n _sigmaX: number,\n _sigmaY: number,\n _color: SkColor,\n _input: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeErode(\n _rx: number,\n _ry: number,\n _input: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeDilate(\n _rx: number,\n _ry: number,\n _input: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeBlend(\n _mode: BlendMode,\n _background: SkImageFilter,\n _foreground: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeRuntimeShader(\n _builder: SkRuntimeShaderBuilder,\n _childShaderName: string | null,\n _input: SkImageFilter | null\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n}\n"]}
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useDerivedValue = void 0;
7
-
8
- var _react = require("react");
9
-
10
- var _api = require("../api");
11
-
12
- var _processors = require("../../renderer/processors");
13
-
14
- /**
15
- * Creates a new derived value - a value that will calculate its value depending
16
- * on other values.
17
- * @param cb Callback to calculate new value
18
- * @param values Dependant values
19
- * @returns A readonly value
20
- */
21
- const useDerivedValue = (cb, values) => (0, _react.useMemo)(() => _api.ValueApi.createDerivedValue(cb, values.filter(_processors.isValue)), // eslint-disable-next-line react-hooks/exhaustive-deps
22
- values);
23
-
24
- exports.useDerivedValue = useDerivedValue;
25
- //# sourceMappingURL=useDerivedValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useDerivedValue.ts"],"names":["useDerivedValue","cb","values","ValueApi","createDerivedValue","filter","isValue"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,eAAe,GAAG,CAAIC,EAAJ,EAAiBC,MAAjB,KAC7B,oBACE,MAAMC,cAASC,kBAAT,CAA+BH,EAA/B,EAAmCC,MAAM,CAACG,MAAP,CAAcC,mBAAd,CAAnC,CADR,EAEE;AACAJ,MAHF,CADK","sourcesContent":["import { useMemo } from \"react\";\n\nimport { ValueApi } from \"../api\";\nimport { isValue } from \"../../renderer/processors\";\n\n/**\n * Creates a new derived value - a value that will calculate its value depending\n * on other values.\n * @param cb Callback to calculate new value\n * @param values Dependant values\n * @returns A readonly value\n */\nexport const useDerivedValue = <R>(cb: () => R, values: unknown[]) =>\n useMemo(\n () => ValueApi.createDerivedValue<R>(cb, values.filter(isValue)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n values\n );\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["RNSkDerivedValue.ts"],"names":["RNSkDerivedValue","RNSkReadonlyValue","constructor","callback","dependencies","unsubscribers","notifyUpdateRef","current","undefined","forEach","dep","push","addListener","_unsubscribers","dependecyUpdated","bind","_callback","update","unsubscribe"],"mappings":";;;;;;;AAEA;;;;AAEO,MAAMA,gBAAN,SAAkCC,oCAAlC,CAAuD;AAC5DC,EAAAA,WAAW,CAACC,QAAD,EAAoBC,YAApB,EAAkD;AAC3D;AACA;AACA,UAAMC,aAAgC,GAAG,EAAzC;AACA,UAAMC,eAAsD,GAAG;AAC7DC,MAAAA,OAAO,EAAEC;AADoD,KAA/D;AAGAJ,IAAAA,YAAY,CAACK,OAAb,CAAsBC,GAAD,IAAS;AAC5B,UAAI,kBAAkBA,GAAlB,IAAyB,iBAAiBA,GAA9C,EAAmD;AACjDL,QAAAA,aAAa,CAACM,IAAd,CACGD,GAAD,CAAoCE,WAApC,CAAgD;AAAA;;AAAA,0CAC9CN,eAAe,CAACC,OAD8B,0DAC9C,2BAAAD,eAAe,CAD+B;AAAA,SAAhD,CADF;AAKD;AACF,KARD;AASA,UAAMH,QAAQ,EAAd;;AAhB2D;;AAAA;;AAiB3D,SAAKU,cAAL,GAAsBR,aAAtB;AACAC,IAAAA,eAAe,CAACC,OAAhB,GAA0B,KAAKO,gBAAL,CAAsBC,IAAtB,CAA2B,IAA3B,CAA1B;AACA,SAAKC,SAAL,GAAiBb,QAAjB;AACD;;AAEOW,EAAAA,gBAAgB,GAAG;AACzB,SAAKG,MAAL,CAAY,KAAKD,SAAL,EAAZ;AACD;;AAKME,EAAAA,WAAW,GAAG;AACnB,SAAKL,cAAL,CAAoBJ,OAApB,CAA6BS,WAAD,IAAiBA,WAAW,EAAxD;AACD;;AAhC2D","sourcesContent":["import type { DependencyList } from \"react\";\n\nimport { RNSkReadonlyValue } from \"./RNSkReadonlyValue\";\n\nexport class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {\n constructor(callback: () => T, dependencies: DependencyList) {\n // Initialize dependencies - we can't call this yet, since\n // super if not called and it requires a start value to be set.\n const unsubscribers: Array<() => void> = [];\n const notifyUpdateRef: { current: (() => void) | undefined } = {\n current: undefined,\n };\n dependencies.forEach((dep) => {\n if (\"__typename__\" in dep && \"addListener\" in dep) {\n unsubscribers.push(\n (dep as RNSkReadonlyValue<unknown>).addListener(() =>\n notifyUpdateRef.current?.()\n )\n );\n }\n });\n super(callback());\n this._unsubscribers = unsubscribers;\n notifyUpdateRef.current = this.dependecyUpdated.bind(this);\n this._callback = callback;\n }\n\n private dependecyUpdated() {\n this.update(this._callback());\n }\n\n private _callback: () => T;\n private _unsubscribers: Array<() => void>;\n\n public unsubscribe() {\n this._unsubscribers.forEach((unsubscribe) => unsubscribe());\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["JsiImageFilterFactory.ts"],"names":["Host","NotImplementedOnRNWeb","ckEnum","toValue","JsiSkImageFilter","JsiSkImageFilterFactory","constructor","CanvasKit","MakeOffset","_dx","_dy","_input","MakeDisplacementMap","_channelX","_channelY","_scale","_in1","MakeShader","_shader","MakeBlur","sigmaX","sigmaY","mode","input","ImageFilter","MakeColorFilter","cf","MakeCompose","outer","inner","MakeDropShadow","_sigmaX","_sigmaY","_color","_cropRect","MakeDropShadowOnly","MakeErode","_rx","_ry","MakeDilate","MakeBlend","_mode","_background","_foreground","MakeRuntimeShader","_builder","_childShaderName"],"mappings":"AAeA,SAASA,IAAT,EAAeC,qBAAf,EAAsCC,MAAtC,EAA8CC,OAA9C,QAA6D,QAA7D;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AAEA,OAAO,MAAMC,uBAAN,SACGL,IADH,CAGP;AACEM,EAAAA,WAAW,CAACC,SAAD,EAAuB;AAChC,UAAMA,SAAN;AACD;;AAEDC,EAAAA,UAAU,CACRC,GADQ,EAERC,GAFQ,EAGRC,MAHQ,EAIO;AACf,UAAM,IAAIV,qBAAJ,EAAN;AACD;;AAEDW,EAAAA,mBAAmB,CACjBC,SADiB,EAEjBC,SAFiB,EAGjBC,MAHiB,EAIjBC,IAJiB,EAKjBL,MALiB,EAMF;AACf,UAAM,IAAIV,qBAAJ,EAAN;AACD;;AAEDgB,EAAAA,UAAU,CAACC,OAAD,EAAoBP,MAApB,EAAiE;AACzE,UAAM,IAAIV,qBAAJ,EAAN;AACD;;AAEDkB,EAAAA,QAAQ,CACNC,MADM,EAENC,MAFM,EAGNC,IAHM,EAINC,KAJM,EAKN;AACA,WAAO,IAAInB,gBAAJ,CACL,KAAKG,SADA,EAEL,KAAKA,SAAL,CAAeiB,WAAf,CAA2BL,QAA3B,CACEC,MADF,EAEEC,MAFF,EAGEnB,MAAM,CAACoB,IAAD,CAHR,EAIEC,KAAK,KAAK,IAAV,GAAiB,IAAjB,GAAwBpB,OAAO,CAACoB,KAAD,CAJjC,CAFK,CAAP;AASD;;AAEDE,EAAAA,eAAe,CAACC,EAAD,EAAoBH,KAApB,EAAiD;AAC9D,WAAO,IAAInB,gBAAJ,CACL,KAAKG,SADA,EAEL,KAAKA,SAAL,CAAeiB,WAAf,CAA2BC,eAA3B,CACEtB,OAAO,CAACuB,EAAD,CADT,EAEEH,KAAK,KAAK,IAAV,GAAiB,IAAjB,GAAwBpB,OAAO,CAACoB,KAAD,CAFjC,CAFK,CAAP;AAOD;;AAEDI,EAAAA,WAAW,CAACC,KAAD,EAA8BC,KAA9B,EAA2D;AACpE,WAAO,IAAIzB,gBAAJ,CACL,KAAKG,SADA,EAEL,KAAKA,SAAL,CAAeiB,WAAf,CAA2BG,WAA3B,CACEC,KAAK,KAAK,IAAV,GAAiB,IAAjB,GAAwBzB,OAAO,CAACyB,KAAD,CADjC,EAEEC,KAAK,KAAK,IAAV,GAAiB,IAAjB,GAAwB1B,OAAO,CAAC0B,KAAD,CAFjC,CAFK,CAAP;AAOD;;AAEDC,EAAAA,cAAc,CACZrB,GADY,EAEZC,GAFY,EAGZqB,OAHY,EAIZC,OAJY,EAKZC,MALY,EAMZtB,MANY,EAOZuB,SAPY,EAQG;AACf,UAAM,IAAIjC,qBAAJ,EAAN;AACD;;AAEDkC,EAAAA,kBAAkB,CAChB1B,GADgB,EAEhBC,GAFgB,EAGhBqB,OAHgB,EAIhBC,OAJgB,EAKhBC,MALgB,EAMhBtB,MANgB,EAOhBuB,SAPgB,EAQD;AACf,UAAM,IAAIjC,qBAAJ,EAAN;AACD;;AAEDmC,EAAAA,SAAS,CACPC,GADO,EAEPC,GAFO,EAGP3B,MAHO,EAIPuB,SAJO,EAKQ;AACf,UAAM,IAAIjC,qBAAJ,EAAN;AACD;;AAEDsC,EAAAA,UAAU,CACRF,GADQ,EAERC,GAFQ,EAGR3B,MAHQ,EAIRuB,SAJQ,EAKO;AACf,UAAM,IAAIjC,qBAAJ,EAAN;AACD;;AAEDuC,EAAAA,SAAS,CACPC,KADO,EAEPC,WAFO,EAGPC,WAHO,EAIPT,SAJO,EAKQ;AACf,UAAM,IAAIjC,qBAAJ,EAAN;AACD;;AAED2C,EAAAA,iBAAiB,CACfC,QADe,EAEfC,gBAFe,EAGfnC,MAHe,EAIA;AACf,UAAM,IAAIV,qBAAJ,EAAN;AACD;;AAzHH","sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type {\n ColorChannel,\n ImageFilterFactory,\n SkColor,\n SkColorFilter,\n SkImageFilter,\n BlendMode,\n SkRect,\n SkRuntimeShaderBuilder,\n SkShader,\n TileMode,\n} from \"../types\";\n\nimport { Host, NotImplementedOnRNWeb, ckEnum, toValue } from \"./Host\";\nimport { JsiSkImageFilter } from \"./JsiSkImageFilter\";\n\nexport class JsiSkImageFilterFactory\n extends Host\n implements ImageFilterFactory\n{\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeOffset(\n _dx: number,\n _dy: number,\n _input: SkImageFilter | null\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeDisplacementMap(\n _channelX: ColorChannel,\n _channelY: ColorChannel,\n _scale: number,\n _in1: SkImageFilter,\n _input: SkImageFilter | null\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeShader(_shader: SkShader, _input: SkImageFilter | null): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeBlur(\n sigmaX: number,\n sigmaY: number,\n mode: TileMode,\n input: SkImageFilter | null\n ) {\n return new JsiSkImageFilter(\n this.CanvasKit,\n this.CanvasKit.ImageFilter.MakeBlur(\n sigmaX,\n sigmaY,\n ckEnum(mode),\n input === null ? null : toValue(input)\n )\n );\n }\n\n MakeColorFilter(cf: SkColorFilter, input: SkImageFilter | null) {\n return new JsiSkImageFilter(\n this.CanvasKit,\n this.CanvasKit.ImageFilter.MakeColorFilter(\n toValue(cf),\n input === null ? null : toValue(input)\n )\n );\n }\n\n MakeCompose(outer: SkImageFilter | null, inner: SkImageFilter | null) {\n return new JsiSkImageFilter(\n this.CanvasKit,\n this.CanvasKit.ImageFilter.MakeCompose(\n outer === null ? null : toValue(outer),\n inner === null ? null : toValue(inner)\n )\n );\n }\n\n MakeDropShadow(\n _dx: number,\n _dy: number,\n _sigmaX: number,\n _sigmaY: number,\n _color: SkColor,\n _input: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeDropShadowOnly(\n _dx: number,\n _dy: number,\n _sigmaX: number,\n _sigmaY: number,\n _color: SkColor,\n _input: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeErode(\n _rx: number,\n _ry: number,\n _input: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeDilate(\n _rx: number,\n _ry: number,\n _input: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeBlend(\n _mode: BlendMode,\n _background: SkImageFilter,\n _foreground: SkImageFilter | null,\n _cropRect?: SkRect\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n\n MakeRuntimeShader(\n _builder: SkRuntimeShaderBuilder,\n _childShaderName: string | null,\n _input: SkImageFilter | null\n ): SkImageFilter {\n throw new NotImplementedOnRNWeb();\n }\n}\n"]}
@@ -1,14 +0,0 @@
1
- import { useMemo } from "react";
2
- import { ValueApi } from "../api";
3
- import { isValue } from "../../renderer/processors";
4
- /**
5
- * Creates a new derived value - a value that will calculate its value depending
6
- * on other values.
7
- * @param cb Callback to calculate new value
8
- * @param values Dependant values
9
- * @returns A readonly value
10
- */
11
-
12
- export const useDerivedValue = (cb, values) => useMemo(() => ValueApi.createDerivedValue(cb, values.filter(isValue)), // eslint-disable-next-line react-hooks/exhaustive-deps
13
- values);
14
- //# sourceMappingURL=useDerivedValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useDerivedValue.ts"],"names":["useMemo","ValueApi","isValue","useDerivedValue","cb","values","createDerivedValue","filter"],"mappings":"AAAA,SAASA,OAAT,QAAwB,OAAxB;AAEA,SAASC,QAAT,QAAyB,QAAzB;AACA,SAASC,OAAT,QAAwB,2BAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,eAAe,GAAG,CAAIC,EAAJ,EAAiBC,MAAjB,KAC7BL,OAAO,CACL,MAAMC,QAAQ,CAACK,kBAAT,CAA+BF,EAA/B,EAAmCC,MAAM,CAACE,MAAP,CAAcL,OAAd,CAAnC,CADD,EAEL;AACAG,MAHK,CADF","sourcesContent":["import { useMemo } from \"react\";\n\nimport { ValueApi } from \"../api\";\nimport { isValue } from \"../../renderer/processors\";\n\n/**\n * Creates a new derived value - a value that will calculate its value depending\n * on other values.\n * @param cb Callback to calculate new value\n * @param values Dependant values\n * @returns A readonly value\n */\nexport const useDerivedValue = <R>(cb: () => R, values: unknown[]) =>\n useMemo(\n () => ValueApi.createDerivedValue<R>(cb, values.filter(isValue)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n values\n );\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["RNSkDerivedValue.ts"],"names":["RNSkReadonlyValue","RNSkDerivedValue","constructor","callback","dependencies","unsubscribers","notifyUpdateRef","current","undefined","forEach","dep","push","addListener","_unsubscribers","dependecyUpdated","bind","_callback","update","unsubscribe"],"mappings":";;AAEA,SAASA,iBAAT,QAAkC,qBAAlC;AAEA,OAAO,MAAMC,gBAAN,SAAkCD,iBAAlC,CAAuD;AAC5DE,EAAAA,WAAW,CAACC,QAAD,EAAoBC,YAApB,EAAkD;AAC3D;AACA;AACA,UAAMC,aAAgC,GAAG,EAAzC;AACA,UAAMC,eAAsD,GAAG;AAC7DC,MAAAA,OAAO,EAAEC;AADoD,KAA/D;AAGAJ,IAAAA,YAAY,CAACK,OAAb,CAAsBC,GAAD,IAAS;AAC5B,UAAI,kBAAkBA,GAAlB,IAAyB,iBAAiBA,GAA9C,EAAmD;AACjDL,QAAAA,aAAa,CAACM,IAAd,CACGD,GAAD,CAAoCE,WAApC,CAAgD;AAAA;;AAAA,0CAC9CN,eAAe,CAACC,OAD8B,0DAC9C,2BAAAD,eAAe,CAD+B;AAAA,SAAhD,CADF;AAKD;AACF,KARD;AASA,UAAMH,QAAQ,EAAd;;AAhB2D;;AAAA;;AAiB3D,SAAKU,cAAL,GAAsBR,aAAtB;AACAC,IAAAA,eAAe,CAACC,OAAhB,GAA0B,KAAKO,gBAAL,CAAsBC,IAAtB,CAA2B,IAA3B,CAA1B;AACA,SAAKC,SAAL,GAAiBb,QAAjB;AACD;;AAEOW,EAAAA,gBAAgB,GAAG;AACzB,SAAKG,MAAL,CAAY,KAAKD,SAAL,EAAZ;AACD;;AAKME,EAAAA,WAAW,GAAG;AACnB,SAAKL,cAAL,CAAoBJ,OAApB,CAA6BS,WAAD,IAAiBA,WAAW,EAAxD;AACD;;AAhC2D","sourcesContent":["import type { DependencyList } from \"react\";\n\nimport { RNSkReadonlyValue } from \"./RNSkReadonlyValue\";\n\nexport class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {\n constructor(callback: () => T, dependencies: DependencyList) {\n // Initialize dependencies - we can't call this yet, since\n // super if not called and it requires a start value to be set.\n const unsubscribers: Array<() => void> = [];\n const notifyUpdateRef: { current: (() => void) | undefined } = {\n current: undefined,\n };\n dependencies.forEach((dep) => {\n if (\"__typename__\" in dep && \"addListener\" in dep) {\n unsubscribers.push(\n (dep as RNSkReadonlyValue<unknown>).addListener(() =>\n notifyUpdateRef.current?.()\n )\n );\n }\n });\n super(callback());\n this._unsubscribers = unsubscribers;\n notifyUpdateRef.current = this.dependecyUpdated.bind(this);\n this._callback = callback;\n }\n\n private dependecyUpdated() {\n this.update(this._callback());\n }\n\n private _callback: () => T;\n private _unsubscribers: Array<() => void>;\n\n public unsubscribe() {\n this._unsubscribers.forEach((unsubscribe) => unsubscribe());\n }\n}\n"]}
@@ -1,18 +0,0 @@
1
- import { useMemo } from "react";
2
-
3
- import { ValueApi } from "../api";
4
- import { isValue } from "../../renderer/processors";
5
-
6
- /**
7
- * Creates a new derived value - a value that will calculate its value depending
8
- * on other values.
9
- * @param cb Callback to calculate new value
10
- * @param values Dependant values
11
- * @returns A readonly value
12
- */
13
- export const useDerivedValue = <R>(cb: () => R, values: unknown[]) =>
14
- useMemo(
15
- () => ValueApi.createDerivedValue<R>(cb, values.filter(isValue)),
16
- // eslint-disable-next-line react-hooks/exhaustive-deps
17
- values
18
- );