@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
@@ -50,9 +50,9 @@ target_include_directories(
50
50
  ${PACKAGE_NAME}
51
51
  PRIVATE
52
52
 
53
- # When installed in the development environment
54
53
  "${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
55
54
  "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
55
+ "${NODE_MODULES_DIR}/react-native/ReactCommon"
56
56
  "${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core"
57
57
  "${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
58
58
 
@@ -51,6 +51,13 @@ def defaultDir = null
51
51
  def androidSourcesDir = null
52
52
  def androidSourcesName = 'React Native sources'
53
53
 
54
+ def buildType = "debug"
55
+ tasks.all({ task ->
56
+ if (task.name == "buildCMakeRelease") {
57
+ buildType = "release"
58
+ }
59
+ })
60
+
54
61
  if (rootProject.ext.has('reactNativeAndroidRoot')) {
55
62
  defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
56
63
  androidSourcesDir = defaultDir.parentFile.toString()
@@ -81,6 +88,7 @@ def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\
81
88
  logger.warn("react-native-skia: React Native version: ${REACT_NATIVE_VERSION}")
82
89
  logger.warn("react-native-skia: Is Source build: ${sourceBuild}")
83
90
  logger.warn("react-native-skia: Prebuilt dir: ${prebuiltDir}")
91
+ logger.warn("react-native-skia: Build type: ${buildType}")
84
92
 
85
93
  buildscript {
86
94
  // The Android Gradle plugin is only required when opening the android folder stand-alone.
@@ -175,8 +183,15 @@ dependencies {
175
183
  //noinspection GradleDynamicVersion
176
184
  extractJNI("com.facebook.fbjni:fbjni:0.2.2")
177
185
 
178
- def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
179
- extractJNI(files(rnAAR))
186
+ if(REACT_NATIVE_VERSION < 69) {
187
+ def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
188
+ extractJNI(files(rnAAR))
189
+ } else {
190
+ // React Native >= 0.69
191
+ def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
192
+ def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include rnAarMatcher }).singleFile
193
+ extractJNI(files(rnAAR))
194
+ }
180
195
  }
181
196
 
182
197
  afterEvaluate { project ->
@@ -53,6 +53,11 @@ namespace RNSkia {
53
53
  }
54
54
 
55
55
  void RNSkDrawViewImpl::surfaceSizeChanged(int width, int height) {
56
+ if(width == 0 && height == 0) {
57
+ // Setting width/height to zero is nothing we need to care about when
58
+ // it comes to invalidating the surface.
59
+ return;
60
+ }
56
61
  _scaledWidth = width;
57
62
  _scaledHeight = height;
58
63
 
@@ -3,6 +3,7 @@
3
3
  #include <memory>
4
4
  #include <utility>
5
5
  #include <vector>
6
+ #include <numeric>
6
7
 
7
8
  #include <jsi/jsi.h>
8
9
  #include "JsiSkHostObjects.h"
@@ -86,6 +87,28 @@ namespace RNSkia
86
87
  return jsiWidths;
87
88
  }
88
89
 
90
+ JSI_HOST_FUNCTION(getTextWidth) {
91
+ auto str = arguments[0].asString(runtime).utf8(runtime);
92
+ auto numGlyphIDs = str.length();
93
+ std::vector<SkGlyphID> glyphs;
94
+ glyphs.resize(numGlyphIDs);
95
+ int glyphsSize = static_cast<int>(numGlyphIDs);
96
+ getObject()->textToGlyphs(str.c_str(), str.length(), SkTextEncoding::kUTF8,
97
+ static_cast<SkGlyphID *>(glyphs.data()), glyphsSize);
98
+ std::vector<SkScalar> widthPtrs;
99
+ widthPtrs.resize(numGlyphIDs);
100
+ if (count > 1)
101
+ {
102
+ auto paint = JsiSkPaint::fromValue(runtime, arguments[1]);
103
+ getObject()->getWidthsBounds(glyphs.data(), glyphsSize, static_cast<SkScalar *>(widthPtrs.data()), nullptr, paint.get());
104
+ }
105
+ else
106
+ {
107
+ getObject()->getWidthsBounds(glyphs.data(), glyphsSize, static_cast<SkScalar *>(widthPtrs.data()), nullptr, nullptr);
108
+ }
109
+ return jsi::Value(std::accumulate(widthPtrs.begin(), widthPtrs.end(), 0));
110
+ }
111
+
89
112
  JSI_HOST_FUNCTION(getMetrics)
90
113
  {
91
114
  SkFontMetrics fm;
@@ -273,7 +296,8 @@ namespace RNSkia
273
296
  JSI_EXPORT_FUNC(JsiSkFont, setEmbolden),
274
297
  JSI_EXPORT_FUNC(JsiSkFont, setSubpixel),
275
298
  JSI_EXPORT_FUNC(JsiSkFont, setTypeface),
276
- JSI_EXPORT_FUNC(JsiSkFont, getGlyphWidths))
299
+ JSI_EXPORT_FUNC(JsiSkFont, getGlyphWidths),
300
+ JSI_EXPORT_FUNC(JsiSkFont, getTextWidth))
277
301
 
278
302
  JsiSkFont(std::shared_ptr<RNSkPlatformContext> context, const SkFont &font)
279
303
  : JsiSkWrappingSharedPtrHostObject(std::move(context),
@@ -65,9 +65,7 @@ namespace RNSkia
65
65
  JSI_HOST_FUNCTION(encodeToBytes)
66
66
  {
67
67
  // Get optional parameters
68
- auto format = count >= 1 ? getFormatFromNumber(
69
- static_cast<int>(arguments[0].asNumber())) : SkEncodedImageFormat::kPNG;
70
-
68
+ auto format = count >= 1 ? static_cast<SkEncodedImageFormat>(arguments[0].asNumber()) : SkEncodedImageFormat::kPNG;
71
69
  auto quality = count == 2 ? arguments[1].asNumber() : 100.0;
72
70
 
73
71
  // Get data
@@ -89,8 +87,7 @@ namespace RNSkia
89
87
  JSI_HOST_FUNCTION(encodeToBase64)
90
88
  {
91
89
  // Get optional parameters
92
- auto format = count >= 1 ? getFormatFromNumber(
93
- static_cast<int>(arguments[0].asNumber())) : SkEncodedImageFormat::kPNG;
90
+ auto format = count >= 1 ? static_cast<SkEncodedImageFormat>(arguments[0].asNumber()) : SkEncodedImageFormat::kPNG;
94
91
 
95
92
  auto quality = count == 2 ? arguments[1].asNumber() : 100.0;
96
93
 
@@ -122,20 +119,6 @@ namespace RNSkia
122
119
  .asHostObject<JsiSkImage>(runtime)
123
120
  ->getObject();
124
121
  }
125
- private:
126
-
127
- SkEncodedImageFormat getFormatFromNumber(int value) {
128
- switch(value) {
129
- case 0: // PNG
130
- return SkEncodedImageFormat::kPNG;
131
- case 1: // JPEG
132
- return SkEncodedImageFormat::kJPEG;
133
- case 2: // WEBP
134
- return SkEncodedImageFormat::kWEBP;
135
- default:
136
- return SkEncodedImageFormat::kPNG;
137
- }
138
- }
139
122
  };
140
123
 
141
124
  } // namespace RNSkia
@@ -84,47 +84,20 @@ public:
84
84
  }
85
85
 
86
86
  JSI_HOST_FUNCTION(setStyle) {
87
- int styleInt = arguments[0].asNumber();
88
- switch (styleInt) {
89
- case 0:
90
- getObject()->setStyle(SkPaint::kFill_Style);
91
- break;
92
- case 1:
93
- getObject()->setStyle(SkPaint::kStroke_Style);
94
- break;
95
- }
87
+ auto style = arguments[0].asNumber();
88
+ getObject()->setStyle(static_cast<SkPaint::Style>(style));
96
89
  return jsi::Value::undefined();
97
90
  }
98
91
 
99
92
  JSI_HOST_FUNCTION(setStrokeCap) {
100
- int cap = arguments[0].asNumber();
101
- switch (cap) {
102
- case 0:
103
- getObject()->setStrokeCap(SkPaint::kButt_Cap);
104
- break;
105
- case 1:
106
- getObject()->setStrokeCap(SkPaint::kRound_Cap);
107
- break;
108
- case 2:
109
- getObject()->setStrokeCap(SkPaint::kSquare_Cap);
110
- break;
111
- }
93
+ auto cap = arguments[0].asNumber();
94
+ getObject()->setStrokeCap(static_cast<SkPaint::Cap>(cap));
112
95
  return jsi::Value::undefined();
113
96
  }
114
97
 
115
98
  JSI_HOST_FUNCTION(setStrokeJoin) {
116
99
  int join = arguments[0].asNumber();
117
- switch (join) {
118
- case 0:
119
- getObject()->setStrokeJoin(SkPaint::kBevel_Join);
120
- break;
121
- case 1:
122
- getObject()->setStrokeJoin(SkPaint::kMiter_Join);
123
- break;
124
- case 2:
125
- getObject()->setStrokeJoin(SkPaint::kRound_Join);
126
- break;
127
- }
100
+ getObject()->setStrokeJoin(static_cast<SkPaint::Join>(join));
128
101
  return jsi::Value::undefined();
129
102
  }
130
103
 
@@ -480,8 +480,8 @@ public:
480
480
  auto cmds = jsi::Array(runtime, path.countVerbs());
481
481
  auto it = SkPath::Iter(path, false);
482
482
  // { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" };
483
- const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 };
484
- const int cmdCount[] = { 3 , 5 , 7 , 8 , 9 , 3 , 0 };
483
+ const int pointCount[] = { 1 , 1 , 2 , 2 , 3 , 0 , 0 };
484
+ const int cmdCount[] = { 3 , 3 , 5 , 6 , 7 , 1 , 0 };
485
485
  SkPoint points[4];
486
486
  SkPath::Verb verb;
487
487
  auto k = 0;
@@ -491,8 +491,8 @@ public:
491
491
  auto j = 0;
492
492
  cmd.setValueAtIndex(runtime, j++, jsi::Value(verbVal));
493
493
  for (int i = 0; i < pointCount[verbVal]; ++i) {
494
- cmd.setValueAtIndex(runtime, j++, jsi::Value(static_cast<double>(points[i].fX)));
495
- cmd.setValueAtIndex(runtime, j++, jsi::Value(static_cast<double>(points[i].fY)));
494
+ cmd.setValueAtIndex(runtime, j++, jsi::Value(static_cast<double>(points[1 + i].fX)));
495
+ cmd.setValueAtIndex(runtime, j++, jsi::Value(static_cast<double>(points[1 + i].fY)));
496
496
  }
497
497
  if (SkPath::kConic_Verb == verb) {
498
498
  cmd.setValueAtIndex(runtime, j, jsi::Value(static_cast<double>(it.conicWeight())));
@@ -4,7 +4,7 @@
4
4
  #include <JsiHostObject.h>
5
5
  #include <RNSkPlatformContext.h>
6
6
  #include <RNSkValue.h>
7
- #include <RNSkDerivedValue.h>
7
+ #include <RNSkComputedValue.h>
8
8
  #include <RNSkAnimation.h>
9
9
  #include <jsi/jsi.h>
10
10
 
@@ -33,13 +33,13 @@ public:
33
33
  std::make_shared<RNSkValue>(_platformContext, runtime, arguments, count));
34
34
  }
35
35
 
36
- JSI_HOST_FUNCTION(createDerivedValue) {
36
+ JSI_HOST_FUNCTION(createComputedValue) {
37
37
  // Creation and initialization is done in two steps to be able to use weak references when setting
38
38
  // up dependencies - since weak_from_this needs our instance to be a shared_ptr before calling
39
39
  // weak_from_this().
40
- auto derivedValue = std::make_shared<RNSkDerivedValue>(_platformContext, runtime, arguments, count);
41
- derivedValue->initializeDependencies(runtime, arguments, count);
42
- return jsi::Object::createFromHostObject(runtime, derivedValue);
40
+ auto computedValue = std::make_shared<RNSkComputedValue>(_platformContext, runtime, arguments, count);
41
+ computedValue->initializeDependencies(runtime, arguments, count);
42
+ return jsi::Object::createFromHostObject(runtime, computedValue);
43
43
  }
44
44
 
45
45
  JSI_HOST_FUNCTION(createAnimation) {
@@ -61,7 +61,7 @@ public:
61
61
  }
62
62
 
63
63
  JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkValueApi, createValue),
64
- JSI_EXPORT_FUNC(RNSkValueApi, createDerivedValue),
64
+ JSI_EXPORT_FUNC(RNSkValueApi, createComputedValue),
65
65
  JSI_EXPORT_FUNC(RNSkValueApi, createClockValue),
66
66
  JSI_EXPORT_FUNC(RNSkValueApi, createAnimation))
67
67
 
@@ -19,13 +19,13 @@ using namespace facebook;
19
19
  Creates a readonly value that depends on one or more other values. The derived value has a callback
20
20
  function that is used to calculate the new value when any of the dependencies change.
21
21
  */
22
- class RNSkDerivedValue : public RNSkReadonlyValue
22
+ class RNSkComputedValue : public RNSkReadonlyValue
23
23
  {
24
24
  public:
25
- RNSkDerivedValue(std::shared_ptr<RNSkPlatformContext> platformContext,
26
- jsi::Runtime &runtime,
27
- const jsi::Value *arguments,
28
- size_t count
25
+ RNSkComputedValue(std::shared_ptr<RNSkPlatformContext> platformContext,
26
+ jsi::Runtime &runtime,
27
+ const jsi::Value *arguments,
28
+ size_t count
29
29
  )
30
30
  : RNSkReadonlyValue(platformContext) {
31
31
  // Verify input
@@ -70,7 +70,7 @@ public:
70
70
  _unsubscribers.push_back(dep->addListener([weakSelf = weak_from_this()](jsi::Runtime& runtime) {
71
71
  auto self = weakSelf.lock();
72
72
  if(self) {
73
- auto selfAsThis = std::dynamic_pointer_cast<RNSkDerivedValue>(self);
73
+ auto selfAsThis = std::dynamic_pointer_cast<RNSkComputedValue>(self);
74
74
  selfAsThis->dependencyUpdated(runtime);
75
75
  }
76
76
  }));
@@ -80,7 +80,7 @@ public:
80
80
  dependencyUpdated(runtime);
81
81
  }
82
82
 
83
- virtual ~RNSkDerivedValue() {
83
+ virtual ~RNSkComputedValue() {
84
84
  // Unregister listeners
85
85
  for(const auto &unsubscribe: _unsubscribers) {
86
86
  unsubscribe();
@@ -34,7 +34,7 @@
34
34
  if (cxxBridge.runtime) {
35
35
 
36
36
  auto callInvoker = bridge.jsCallInvoker;
37
- jsi::Runtime* jsRuntime = (jsi::Runtime*)cxxBridge.runtime;
37
+ facebook::jsi::Runtime* jsRuntime = (facebook::jsi::Runtime*)cxxBridge.runtime;
38
38
 
39
39
  // Create platform context
40
40
  _platformContext = std::make_shared<RNSkia::PlatformContext>(jsRuntime, callInvoker);
package/jestSetup.js ADDED
@@ -0,0 +1,5 @@
1
+ /* globals jest */
2
+ jest.mock(
3
+ "@shopify/react-native-skia",
4
+ () => require("@shopify/react-native-skia/lib/commonjs/mock").Mock
5
+ );
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Extrapolate = void 0;
7
7
  exports.interpolate = interpolate;
8
+ exports.validateInterpolationOptions = validateInterpolationOptions;
8
9
 
9
10
  /* eslint-disable max-len */
10
11
  let Extrapolate;
@@ -40,7 +41,7 @@ function isExtrapolate(value) {
40
41
  // if type is correct, converts it to ExtrapolationConfig
41
42
 
42
43
 
43
- function validateType(type) {
44
+ function validateInterpolationOptions(type) {
44
45
  // initialize extrapolationConfig with default extrapolation
45
46
  const extrapolationConfig = {
46
47
  extrapolateLeft: Extrapolate.EXTEND,
@@ -106,7 +107,7 @@ function interpolate(x, input, output, type) {
106
107
  throw Error("Interpolation input and output should contain at least two values.");
107
108
  }
108
109
 
109
- const extrapolationConfig = validateType(type);
110
+ const extrapolationConfig = validateInterpolationOptions(type);
110
111
  const {
111
112
  length
112
113
  } = input;
@@ -1 +1 @@
1
- {"version":3,"sources":["interpolate.ts"],"names":["Extrapolate","getVal","type","coef","val","leftEdgeOutput","rightEdgeOutput","x","IDENTITY","CLAMP","EXTEND","isExtrapolate","value","validateType","extrapolationConfig","extrapolateLeft","extrapolateRight","Error","Object","assign","internalInterpolate","narrowedInput","leftEdgeInput","rightEdgeInput","progress","interpolate","input","output","length","i"],"mappings":";;;;;;;;AAAA;IACYA,W;;;WAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;GAAAA,W,2BAAAA,W;;AA6BZ,SAASC,MAAT,CACEC,IADF,EAEEC,IAFF,EAGEC,GAHF,EAIEC,cAJF,EAKEC,eALF,EAMEC,CANF,EAOU;AACR,UAAQL,IAAR;AACE,SAAKF,WAAW,CAACQ,QAAjB;AACE,aAAOD,CAAP;;AACF,SAAKP,WAAW,CAACS,KAAjB;AACE,UAAIN,IAAI,GAAGC,GAAP,GAAaD,IAAI,GAAGE,cAAxB,EAAwC;AACtC,eAAOA,cAAP;AACD;;AACD,aAAOC,eAAP;;AACF,SAAKN,WAAW,CAACU,MAAjB;AACA;AACE,aAAON,GAAP;AAVJ;AAYD;;AAED,SAASO,aAAT,CAAuBC,KAAvB,EAA4D;AAC1D,SACEA,KAAK,KAAKZ,WAAW,CAACU,MAAtB,IACAE,KAAK,KAAKZ,WAAW,CAACS,KADtB,IAEAG,KAAK,KAAKZ,WAAW,CAACQ,QAHxB;AAKD,C,CAED;AACA;;;AACA,SAASK,YAAT,CAAsBX,IAAtB,EAA4E;AAC1E;AACA,QAAMY,mBAAgD,GAAG;AACvDC,IAAAA,eAAe,EAAEf,WAAW,CAACU,MAD0B;AAEvDM,IAAAA,gBAAgB,EAAEhB,WAAW,CAACU;AAFyB,GAAzD;;AAKA,MAAI,CAACR,IAAL,EAAW;AACT,WAAOY,mBAAP;AACD;;AAED,MAAI,OAAOZ,IAAP,KAAgB,QAApB,EAA8B;AAC5B,QAAI,CAACS,aAAa,CAACT,IAAD,CAAlB,EAA0B;AACxB,YAAM,IAAIe,KAAJ,CACH;AACT,iEAFY,CAAN;AAID;;AACDH,IAAAA,mBAAmB,CAACC,eAApB,GAAsCb,IAAtC;AACAY,IAAAA,mBAAmB,CAACE,gBAApB,GAAuCd,IAAvC;AACA,W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d,GAA8BI,KAAK,CAACG,CAAC,GAAG,CAAL,CAAnC;AACAR,UAAAA,aAAa,CAACE,cAAd,GAA+BG,KAAK,CAACG,CAAD,CAApC;AACAR,UAAAA,aAAa,CAAChB,cAAd,GAA+BsB,MAAM,CAACE,CAAC,GAAG,CAAL,CAArC;AACAR,UAAAA,aAAa,CAACf,eAAd,GAAgCqB,MAAM,CAACE,CAAD,CAAtC;AACA;AACD;AACF;AACF;AACF;;AAED,SAAOT,mBAAmB,CAACb,CAAD,EAAIc,aAAJ,EAAmBP,mBAAnB,CAA1B;AACD","sourcesContent":["/* eslint-disable max-len */\nexport enum Extrapolate {\n IDENTITY = \"identity\",\n CLAMP = \"clamp\",\n EXTEND = \"extend\",\n}\n\ninterface InterpolationNarrowedInput {\n leftEdgeInput: number;\n rightEdgeInput: number;\n leftEdgeOutput: number;\n rightEdgeOutput: number;\n}\n\nexport interface ExtrapolationConfig {\n extrapolateLeft?: Extrapolate | string;\n extrapolateRight?: Extrapolate | string;\n}\n\ninterface RequiredExtrapolationConfig {\n extrapolateLeft: Extrapolate;\n extrapolateRight: Extrapolate;\n}\n\nexport type ExtrapolationType =\n | ExtrapolationConfig\n | Extrapolate\n | string\n | undefined;\n\nfunction getVal(\n type: Extrapolate,\n coef: number,\n val: number,\n leftEdgeOutput: number,\n rightEdgeOutput: number,\n x: number\n): number {\n switch (type) {\n case Extrapolate.IDENTITY:\n return x;\n case Extrapolate.CLAMP:\n if (coef * val < coef * leftEdgeOutput) {\n return leftEdgeOutput;\n }\n return rightEdgeOutput;\n case Extrapolate.EXTEND:\n default:\n return val;\n }\n}\n\nfunction isExtrapolate(value: string): value is Extrapolate {\n return (\n value === Extrapolate.EXTEND ||\n value === Extrapolate.CLAMP ||\n value === Extrapolate.IDENTITY\n );\n}\n\n// validates extrapolations type\n// if type is correct, converts it to ExtrapolationConfig\nfunction validateType(type: ExtrapolationType): RequiredExtrapolationConfig {\n // initialize extrapolationConfig with default extrapolation\n const extrapolationConfig: RequiredExtrapolationConfig = {\n extrapolateLeft: Extrapolate.EXTEND,\n extrapolateRight: Extrapolate.EXTEND,\n };\n\n if (!type) {\n return extrapolationConfig;\n }\n\n if (typeof type === \"string\") {\n if (!isExtrapolate(type)) {\n throw new Error(\n `No supported value for \"interpolate\" \\nSupported values: [\"extend\", \"clamp\", \"identity\", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\\n Valid example:\n interpolate(value, [inputRange], [outputRange], \"clamp\")`\n );\n }\n extrapolationConfig.extrapolateLeft = type;\n extrapolationConfig.extrapolateRight = type;\n return extrapolationConfig;\n }\n\n // otherwise type is extrapolation config object\n if (\n (type.extrapolateLeft && !isExtrapolate(type.extrapolateLeft)) ||\n (type.extrapolateRight && !isExtrapolate(type.extrapolateRight))\n ) {\n throw new Error(\n `No supported value for \"interpolate\" \\nSupported values: [\"extend\", \"clamp\", \"identity\", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\\n Valid example:\n interpolate(value, [inputRange], [outputRange], {\n extrapolateLeft: Extrapolation.CLAMP,\n extrapolateRight: Extrapolation.IDENTITY\n }})`\n );\n }\n\n Object.assign(extrapolationConfig, type);\n return extrapolationConfig;\n}\n\nfunction internalInterpolate(\n x: number,\n narrowedInput: InterpolationNarrowedInput,\n extrapolationConfig: RequiredExtrapolationConfig\n) {\n const { leftEdgeInput, rightEdgeInput, leftEdgeOutput, rightEdgeOutput } =\n narrowedInput;\n if (rightEdgeInput - leftEdgeInput === 0) {\n return leftEdgeOutput;\n }\n const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);\n const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);\n const coef = rightEdgeOutput >= leftEdgeOutput ? 1 : -1;\n\n if (coef * val < coef * leftEdgeOutput) {\n return getVal(\n extrapolationConfig.extrapolateLeft,\n coef,\n val,\n leftEdgeOutput,\n rightEdgeOutput,\n x\n );\n } else if (coef * val > coef * rightEdgeOutput) {\n return getVal(\n extrapolationConfig.extrapolateRight,\n coef,\n val,\n leftEdgeOutput,\n rightEdgeOutput,\n x\n );\n }\n\n return val;\n}\n\n// e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)\nexport function interpolate(\n x: number,\n input: readonly number[],\n output: readonly number[],\n type?: ExtrapolationType\n): number {\n if (input.length < 2 || output.length < 2) {\n throw Error(\n \"Interpolation input and output should contain at least two values.\"\n );\n }\n\n const extrapolationConfig = validateType(type);\n const { length } = input;\n const narrowedInput: InterpolationNarrowedInput = {\n leftEdgeInput: input[0],\n rightEdgeInput: input[1],\n leftEdgeOutput: output[0],\n rightEdgeOutput: output[1],\n };\n if (length > 2) {\n if (x > input[length - 1]) {\n narrowedInput.leftEdgeInput = input[length - 2];\n narrowedInput.rightEdgeInput = input[length - 1];\n narrowedInput.leftEdgeOutput = output[length - 2];\n narrowedInput.rightEdgeOutput = output[length - 1];\n } else {\n for (let i = 1; i < length; ++i) {\n if (x <= input[i]) {\n narrowedInput.leftEdgeInput = input[i - 1];\n narrowedInput.rightEdgeInput = input[i];\n narrowedInput.leftEdgeOutput = output[i - 1];\n narrowedInput.rightEdgeOutput = output[i];\n break;\n }\n }\n }\n }\n\n return internalInterpolate(x, narrowedInput, extrapolationConfig);\n}\n"]}
1
+ {"version":3,"sources":["interpolate.ts"],"names":["Extrapolate","getVal","type","coef","val","leftEdgeOutput","rightEdgeOutput","x","IDENTITY","CLAMP","EXTEND","isExtrapolate","value","validateInterpolationOptions","extrapolationConfig","extrapolateLeft","extrapolateRight","Error","Object","assign","internalInterpolate","narrowedInput","leftEdgeInput","rightEdgeInput","progress","interpolate","input","output","length","i"],"mappings":";;;;;;;;;AAAA;IACYA,W;;;WAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;GAAAA,W,2BAAAA,W;;AA6BZ,SAASC,MAAT,CACEC,IADF,EAEEC,IAFF,EAGEC,GAHF,EAIEC,cAJF,EAKEC,eALF,EAMEC,C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AACD;AACF;AACF;AACF;;AAED,SAAOT,mBAAmB,CAACb,CAAD,EAAIc,aAAJ,EAAmBP,mBAAnB,CAA1B;AACD","sourcesContent":["/* eslint-disable max-len */\nexport enum Extrapolate {\n IDENTITY = \"identity\",\n CLAMP = \"clamp\",\n EXTEND = \"extend\",\n}\n\ninterface InterpolationNarrowedInput {\n leftEdgeInput: number;\n rightEdgeInput: number;\n leftEdgeOutput: number;\n rightEdgeOutput: number;\n}\n\nexport interface ExtrapolationConfig {\n extrapolateLeft?: Extrapolate | string;\n extrapolateRight?: Extrapolate | string;\n}\n\ninterface RequiredExtrapolationConfig {\n extrapolateLeft: Extrapolate;\n extrapolateRight: Extrapolate;\n}\n\nexport type ExtrapolationType =\n | ExtrapolationConfig\n | Extrapolate\n | string\n | undefined;\n\nfunction getVal(\n type: Extrapolate,\n coef: number,\n val: number,\n leftEdgeOutput: number,\n rightEdgeOutput: number,\n x: number\n): number {\n switch (type) {\n case Extrapolate.IDENTITY:\n return x;\n case Extrapolate.CLAMP:\n if (coef * val < coef * leftEdgeOutput) {\n return leftEdgeOutput;\n }\n return rightEdgeOutput;\n case Extrapolate.EXTEND:\n default:\n return val;\n }\n}\n\nfunction isExtrapolate(value: string): value is Extrapolate {\n return (\n value === Extrapolate.EXTEND ||\n value === Extrapolate.CLAMP ||\n value === Extrapolate.IDENTITY\n );\n}\n\n// validates extrapolations type\n// if type is correct, converts it to ExtrapolationConfig\nexport function validateInterpolationOptions(\n type: ExtrapolationType\n): RequiredExtrapolationConfig {\n // initialize extrapolationConfig with default extrapolation\n const extrapolationConfig: RequiredExtrapolationConfig = {\n extrapolateLeft: Extrapolate.EXTEND,\n extrapolateRight: Extrapolate.EXTEND,\n };\n\n if (!type) {\n return extrapolationConfig;\n }\n\n if (typeof type === \"string\") {\n if (!isExtrapolate(type)) {\n throw new Error(\n `No supported value for \"interpolate\" \\nSupported values: [\"extend\", \"clamp\", \"identity\", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\\n Valid example:\n interpolate(value, [inputRange], [outputRange], \"clamp\")`\n );\n }\n extrapolationConfig.extrapolateLeft = type;\n extrapolationConfig.extrapolateRight = type;\n return extrapolationConfig;\n }\n\n // otherwise type is extrapolation config object\n if (\n (type.extrapolateLeft && !isExtrapolate(type.extrapolateLeft)) ||\n (type.extrapolateRight && !isExtrapolate(type.extrapolateRight))\n ) {\n throw new Error(\n `No supported value for \"interpolate\" \\nSupported values: [\"extend\", \"clamp\", \"identity\", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\\n Valid example:\n interpolate(value, [inputRange], [outputRange], {\n extrapolateLeft: Extrapolation.CLAMP,\n extrapolateRight: Extrapolation.IDENTITY\n }})`\n );\n }\n\n Object.assign(extrapolationConfig, type);\n return extrapolationConfig;\n}\n\nfunction internalInterpolate(\n x: number,\n narrowedInput: InterpolationNarrowedInput,\n extrapolationConfig: RequiredExtrapolationConfig\n) {\n const { leftEdgeInput, rightEdgeInput, leftEdgeOutput, rightEdgeOutput } =\n narrowedInput;\n if (rightEdgeInput - leftEdgeInput === 0) {\n return leftEdgeOutput;\n }\n const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);\n const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);\n const coef = rightEdgeOutput >= leftEdgeOutput ? 1 : -1;\n\n if (coef * val < coef * leftEdgeOutput) {\n return getVal(\n extrapolationConfig.extrapolateLeft,\n coef,\n val,\n leftEdgeOutput,\n rightEdgeOutput,\n x\n );\n } else if (coef * val > coef * rightEdgeOutput) {\n return getVal(\n extrapolationConfig.extrapolateRight,\n coef,\n val,\n leftEdgeOutput,\n rightEdgeOutput,\n x\n );\n }\n\n return val;\n}\n\n// e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)\nexport function interpolate(\n x: number,\n input: readonly number[],\n output: readonly number[],\n type?: ExtrapolationType\n): number {\n if (input.length < 2 || output.length < 2) {\n throw Error(\n \"Interpolation input and output should contain at least two values.\"\n );\n }\n\n const extrapolationConfig = validateInterpolationOptions(type);\n const { length } = input;\n const narrowedInput: InterpolationNarrowedInput = {\n leftEdgeInput: input[0],\n rightEdgeInput: input[1],\n leftEdgeOutput: output[0],\n rightEdgeOutput: output[1],\n };\n if (length > 2) {\n if (x > input[length - 1]) {\n narrowedInput.leftEdgeInput = input[length - 2];\n narrowedInput.rightEdgeInput = input[length - 1];\n narrowedInput.leftEdgeOutput = output[length - 2];\n narrowedInput.rightEdgeOutput = output[length - 1];\n } else {\n for (let i = 1; i < length; ++i) {\n if (x <= input[i]) {\n narrowedInput.leftEdgeInput = input[i - 1];\n narrowedInput.rightEdgeInput = input[i];\n narrowedInput.leftEdgeOutput = output[i - 1];\n narrowedInput.rightEdgeOutput = output[i];\n break;\n }\n }\n }\n }\n\n return internalInterpolate(x, narrowedInput, extrapolationConfig);\n}\n"]}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.mixColors = exports.interpolateColors = void 0;
7
7
 
8
- var _renderer = require("../../renderer");
8
+ var _math = require("../../renderer/processors/math");
9
9
 
10
10
  var _skia = require("../../skia");
11
11
 
@@ -32,7 +32,7 @@ const mixColors = (value, x, y) => {
32
32
 
33
33
  const c2 = _skia.Skia.Color(y);
34
34
 
35
- return new Float32Array([(0, _renderer.mix)(value, c1[0], c2[0]), (0, _renderer.mix)(value, c1[1], c2[1]), (0, _renderer.mix)(value, c1[2], c2[2]), (0, _renderer.mix)(value, c1[3], c2[3])]);
35
+ return new Float32Array([(0, _math.mix)(value, c1[0], c2[0]), (0, _math.mix)(value, c1[1], c2[1]), (0, _math.mix)(value, c1[2], c2[2]), (0, _math.mix)(value, c1[3], c2[3])]);
36
36
  };
37
37
 
38
38
  exports.mixColors = mixColors;
@@ -1 +1 @@
1
- {"version":3,"sources":["interpolateColors.ts"],"names":["interpolateColorsRGB","value","inputRange","outputRange","r","map","c","g","b","a","Float32Array","interpolateColors","_outputRange","cl","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GL,WAAKC,KAAL,CAAWE,CAAX,CAAX;;AACA,QAAMG,EAAE,GAAGN,WAAKC,KAAL,CAAWG,CAAX,CAAX;;AACA,SAAO,IAAIR,YAAJ,CAAiB,CACtB,mBAAIT,KAAJ,EAAWkB,EAAE,CAAC,CAAD,CAAb,EAAkBC,EAAE,CAAC,CAAD,CAApB,CADsB,EAEtB,mBAAInB,KAAJ,EAAWkB,EAAE,CAAC,CAAD,CAAb,EAAkBC,EAAE,CAAC,CAAD,CAApB,CAFsB,EAGtB,mBAAInB,KAAJ,EAAWkB,EAAE,CAAC,CAAD,CAAb,EAAkBC,EAAE,CAAC,CAAD,CAApB,CAHsB,EAItB,mBAAInB,KAAJ,EAAWkB,EAAE,CAAC,CAAD,CAAb,EAAkBC,EAAE,CAAC,CAAD,CAApB,CAJsB,CAAjB,CAAP;AAMD,CATM","sourcesContent":["import { mix } from \"../../renderer\";\nimport type { Color, SkColor } from \"../../skia\";\nimport { Skia } from \"../../skia\";\n\nimport { interpolate } from \"./interpolate\";\n\nconst interpolateColorsRGB = (\n value: number,\n inputRange: number[],\n outputRange: SkColor[]\n) => {\n const r = interpolate(\n value,\n inputRange,\n outputRange.map((c) => c[0]),\n \"clamp\"\n );\n const g = interpolate(\n value,\n inputRange,\n outputRange.map((c) => c[1]),\n \"clamp\"\n );\n const b = interpolate(\n value,\n inputRange,\n outputRange.map((c) => c[2]),\n \"clamp\"\n );\n const a = interpolate(\n value,\n inputRange,\n outputRange.map((c) => c[3]),\n \"clamp\"\n );\n return new Float32Array([r, g, b, a]);\n};\n\nexport const interpolateColors = (\n value: number,\n inputRange: number[],\n _outputRange: Color[]\n) => {\n const outputRange = _outputRange.map((cl) => Skia.Color(cl));\n return interpolateColorsRGB(value, inputRange, outputRange);\n};\n\nexport const mixColors = (value: number, x: Color, y: Color) => {\n const c1 = Skia.Color(x);\n const c2 = Skia.Color(y);\n return new Float32Array([\n mix(value, c1[0], c2[0]),\n mix(value, c1[1], c2[1]),\n mix(value, c1[2], c2[2]),\n mix(value, c1[3], c2[3]),\n ]);\n};\n"]}
1
+ {"version":3,"sources":["interpolateColors.ts"],"names":["interpolateColorsRGB","value","inputRange","outputRange","r","map","c","g","b","a","Float32Array","interpolateColors","_outputRange","cl","Skia","Color","mixColors","x","y","c1","c2"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AAEA,MAAMA,oBAAoB,GAAG,CAC3BC,KAD2B,EAE3BC,UAF2B,EAG3BC,WAH2B,KAIxB;AACH,QAAMC,CAAC,GAAG,8BACRH,KADQ,EAERC,UAFQ,EAGRC,WAAW,CAACE,GAAZ,CAAiBC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAAxB,CAHQ,EAIR,OAJQ,CAAV;AAMA,QAAMC,CAAC,GAAG,8BACRN,KADQ,EAERC,UAFQ,EAGRC,WAAW,CAACE,GAAZ,CAAiBC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAAxB,CAHQ,EAIR,OAJQ,CAAV;AAMA,QAAME,CAAC,GAAG,8BACRP,KADQ,EAERC,UAFQ,EAGRC,WAAW,CAACE,GAAZ,CAAiBC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAAxB,CAHQ,EAIR,OAJQ,CAAV;AAMA,QAAMG,CAAC,GAAG,8BACRR,KADQ,EAERC,UAFQ,EAGRC,WAAW,CAACE,GAAZ,CAAiBC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAAxB,CAHQ,EAIR,OAJQ,CAAV;AAMA,SAAO,IAAII,YAAJ,CAAiB,CAACN,CAAD,EAAIG,CAAJ,EAAOC,CAAP,EAAUC,CAAV,CAAjB,CAAP;AACD,CA9BD;;AAgCO,MAAME,iBAAiB,GAAG,CAC/BV,KAD+B,EAE/BC,UAF+B,EAG/BU,YAH+B,KAI5B;AACH,QAAMT,WAAW,GAAGS,YAAY,CAACP,GAAb,CAAkBQ,EAAD,IAAQC,WAAKC,KAAL,CAAWF,EAAX,CAAzB,CAApB;;AACA,SAAOb,oBAAoB,CAACC,KAAD,EAAQC,UAAR,EAAoBC,WAApB,CAA3B;AACD,CAPM;;;;AASA,MAAMa,SAAS,GAAG,CAACf,KAAD,EAAgBgB,CAAhB,EAA0BC,CAA1B,KAAuC;AAC9D,QAAMC,EAAE,GAAGL,WAAKC,KAAL,CAAWE,CAAX,CAAX;;AACA,QAAMG,EAAE,GAAGN,WAAKC,KAAL,CAAWG,CAAX,CAAX;;AACA,SAAO,IAAIR,YAAJ,CAAiB,CACtB,eAAIT,KAAJ,EAAWkB,EAAE,CAAC,CAAD,CAAb,EAAkBC,EAAE,CAAC,CAAD,CAApB,CADsB,EAEtB,eAAInB,KAAJ,EAAWkB,EAAE,CAAC,CAAD,CAAb,EAAkBC,EAAE,CAAC,CAAD,CAApB,CAFsB,EAGtB,eAAInB,KAAJ,EAAWkB,EAAE,CAAC,CAAD,CAAb,EAAkBC,EAAE,CAAC,CAAD,CAApB,CAHsB,EAItB,eAAInB,KAAJ,EAAWkB,EAAE,CAAC,CAAD,CAAb,EAAkBC,EAAE,CAAC,CAAD,CAApB,CAJsB,CAAjB,CAAP;AAMD,CATM","sourcesContent":["import { mix } from \"../../renderer/processors/math\";\nimport type { Color, SkColor } from \"../../skia\";\nimport { Skia } from \"../../skia\";\n\nimport { interpolate } from \"./interpolate\";\n\nconst interpolateColorsRGB = (\n value: number,\n inputRange: number[],\n outputRange: SkColor[]\n) => {\n const r = interpolate(\n value,\n inputRange,\n outputRange.map((c) => c[0]),\n \"clamp\"\n );\n const g = interpolate(\n value,\n inputRange,\n outputRange.map((c) => c[1]),\n \"clamp\"\n );\n const b = interpolate(\n value,\n inputRange,\n outputRange.map((c) => c[2]),\n \"clamp\"\n );\n const a = interpolate(\n value,\n inputRange,\n outputRange.map((c) => c[3]),\n \"clamp\"\n );\n return new Float32Array([r, g, b, a]);\n};\n\nexport const interpolateColors = (\n value: number,\n inputRange: number[],\n _outputRange: Color[]\n) => {\n const outputRange = _outputRange.map((cl) => Skia.Color(cl));\n return interpolateColorsRGB(value, inputRange, outputRange);\n};\n\nexport const mixColors = (value: number, x: Color, y: Color) => {\n const c1 = Skia.Color(x);\n const c2 = Skia.Color(y);\n return new Float32Array([\n mix(value, c1[0], c2[0]),\n mix(value, c1[1], c2[1]),\n mix(value, c1[2], c2[2]),\n mix(value, c1[3], c2[3]),\n ]);\n};\n"]}
@@ -5,11 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.interpolatePaths = void 0;
7
7
 
8
+ var _typeddash = require("../../renderer/typeddash");
9
+
10
+ var _interpolate = require("./interpolate");
11
+
12
+ const lerp = (value, from, to, p1, p2) => {
13
+ const t = (value - from) / (to - from);
14
+ return p2.interpolate(p1, t);
15
+ };
8
16
  /**
9
17
  * Maps an input value within a range to an output path within a path range.
10
18
  * @param value - The input value.
11
19
  * @param inputRange - The range of the input value.
12
20
  * @param outputRange - The range of the output path.
21
+ * @param options - Extrapolation options
13
22
  * @returns The output path.
14
23
  * @example <caption>Map a value between 0 and 1 to a path between two paths.</caption>
15
24
  * const path1 = new Path();
@@ -20,25 +29,50 @@ exports.interpolatePaths = void 0;
20
29
  * path2.lineTo(0, 100);
21
30
  * const path = interpolatePath(0.5, [0, 1], [path1, path2]);
22
31
  */
23
- const interpolatePaths = (value, input, outputRange) => {
32
+
33
+
34
+ const interpolatePaths = (value, input, outputRange, options) => {
35
+ const extrapolation = (0, _interpolate.validateInterpolationOptions)(options);
36
+
37
+ if (value < input[0]) {
38
+ switch (extrapolation.extrapolateLeft) {
39
+ case _interpolate.Extrapolate.CLAMP:
40
+ return outputRange[0];
41
+
42
+ case _interpolate.Extrapolate.EXTEND:
43
+ return lerp(value, input[0], input[1], outputRange[0], outputRange[1]);
44
+
45
+ case _interpolate.Extrapolate.IDENTITY:
46
+ throw new Error("Identity is not a supported extrapolation type for interpolatePaths()");
47
+
48
+ default:
49
+ (0, _typeddash.exhaustiveCheck)(extrapolation.extrapolateLeft);
50
+ }
51
+ } else if (value > input[input.length - 1]) {
52
+ switch (extrapolation.extrapolateRight) {
53
+ case _interpolate.Extrapolate.CLAMP:
54
+ return outputRange[outputRange.length - 1];
55
+
56
+ case _interpolate.Extrapolate.EXTEND:
57
+ return lerp(value, input[input.length - 2], input[input.length - 1], outputRange[input.length - 2], outputRange[input.length - 1]);
58
+
59
+ case _interpolate.Extrapolate.IDENTITY:
60
+ throw new Error("Identity is not a supported extrapolation type for interpolatePaths()");
61
+
62
+ default:
63
+ (0, _typeddash.exhaustiveCheck)(extrapolation.extrapolateRight);
64
+ }
65
+ }
66
+
24
67
  let i = 0;
25
68
 
26
69
  for (; i <= input.length - 1; i++) {
27
70
  if (value >= input[i] && value <= input[i + 1]) {
28
71
  break;
29
72
  }
30
-
31
- if (i === input.length - 1) {
32
- if (value < input[0]) {
33
- return outputRange[0];
34
- } else {
35
- return outputRange[i];
36
- }
37
- }
38
73
  }
39
74
 
40
- const t = (value - input[i]) / (input[i + 1] - input[i]);
41
- return outputRange[i + 1].interpolate(outputRange[i], t);
75
+ return lerp(value, input[i], input[i + 1], outputRange[i], outputRange[i + 1]);
42
76
  };
43
77
 
44
78
  exports.interpolatePaths = interpolatePaths;
@@ -1 +1 @@
1
- {"version":3,"sources":["interpolatePaths.ts"],"names":["interpolatePaths","value","input","outputRange","i","length","t","interpolate"],"mappings":";;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,gBAAgB,GAAG,CAC9BC,KAD8B,EAE9BC,KAF8B,EAG9BC,WAH8B,KAI3B;AACH,MAAIC,CAAC,GAAG,CAAR;;AACA,SAAOA,CAAC,IAAIF,KAAK,CAACG,MAAN,GAAe,CAA3B,EAA8BD,CAAC,EAA/B,EAAmC;AACjC,QAAIH,KAAK,IAAIC,KAAK,CAACE,CAAD,CAAd,IAAqBH,KAAK,IAAIC,KAAK,CAACE,CAAC,GAAG,CAAL,CAAvC,EAAgD;AAC9C;AACD;;AACD,QAAIA,CAAC,KAAKF,KAAK,CAACG,MAAN,GAAe,CAAzB,EAA4B;AAC1B,UAAIJ,KAAK,GAAGC,KAAK,CAAC,CAAD,CAAjB,EAAsB;AACpB,eAAOC,WAAW,CAAC,CAAD,CAAlB;AACD,OAFD,MAEO;AACL,eAAOA,WAAW,CAACC,CAAD,CAAlB;AACD;AACF;AACF;;AACD,QAAME,CAAC,GAAG,CAACL,KAAK,GAAGC,KAAK,CAACE,CAAD,CAAd,KAAsBF,KAAK,CAACE,CAAC,GAAG,CAAL,CAAL,GAAeF,KAAK,CAACE,CAAD,CAA1C,CAAV;AACA,SAAOD,WAAW,CAACC,CAAC,GAAG,CAAL,CAAX,CAAmBG,WAAnB,CAA+BJ,WAAW,CAACC,CAAD,CAA1C,EAA+CE,CAA/C,CAAP;AACD,CApBM","sourcesContent":["import type { SkPath } from \"../../skia/types\";\n\n/**\n * Maps an input value within a range to an output path within a path range.\n * @param value - The input value.\n * @param inputRange - The range of the input value.\n * @param outputRange - The range of the output path.\n * @returns The output path.\n * @example <caption>Map a value between 0 and 1 to a path between two paths.</caption>\n * const path1 = new Path();\n * path1.moveTo(0, 0);\n * path1.lineTo(100, 0);\n * const path2 = new Path();\n * path2.moveTo(0, 0);\n * path2.lineTo(0, 100);\n * const path = interpolatePath(0.5, [0, 1], [path1, path2]);\n */\nexport const interpolatePaths = (\n value: number,\n input: number[],\n outputRange: SkPath[]\n) => {\n let i = 0;\n for (; i <= input.length - 1; i++) {\n if (value >= input[i] && value <= input[i + 1]) {\n break;\n }\n if (i === input.length - 1) {\n if (value < input[0]) {\n return outputRange[0];\n } else {\n return outputRange[i];\n }\n }\n }\n const t = (value - input[i]) / (input[i + 1] - input[i]);\n return outputRange[i + 1].interpolate(outputRange[i], t)!;\n};\n"]}
1
+ {"version":3,"sources":["interpolatePaths.ts"],"names":["lerp","value","from","to","p1","p2","t","interpolate","interpolatePaths","input","outputRange","options","extrapolation","extrapolateLeft","Extrapolate","CLAMP","EXTEND","IDENTITY","Error","length","extrapolateRight","i"],"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MAAjB;AACE,eAAOhB,IAAI,CACTC,KADS,EAETQ,KAAK,CAACA,KAAK,CAACU,MAAN,GAAe,CAAhB,CAFI,EAGTV,KAAK,CAACA,KAAK,CAACU,MAAN,GAAe,CAAhB,CAHI,EAITT,WAAW,CAACD,KAAK,CAACU,MAAN,GAAe,CAAhB,CAJF,EAKTT,WAAW,CAACD,KAAK,CAACU,MAAN,GAAe,CAAhB,CALF,CAAX;;AAOF,WAAKL,yBAAYG,QAAjB;AACE,cAAM,IAAIC,KAAJ,CACJ,uEADI,CAAN;;AAGF;AACE,wCAAgBN,aAAa,CAACQ,gBAA9B;AAhBJ;AAkBD;;AACD,MAAIC,CAAC,GAAG,CAAR;;AACA,SAAOA,CAAC,IAAIZ,KAAK,CAACU,MAAN,GAAe,CAA3B,EAA8BE,CAAC,EAA/B,EAAmC;AACjC,QAAIpB,KAAK,IAAIQ,KAAK,CAACY,CAAD,CAAd,IAAqBpB,KAAK,IAAIQ,KAAK,CAACY,CAAC,GAAG,CAAL,CAAvC,EAAgD;AAC9C;AACD;AACF;;AACD,SAAOrB,IAAI,CACTC,KADS,EAETQ,KAAK,CAACY,CAAD,CAFI,EAGTZ,KAAK,CAACY,CAAC,GAAG,CAAL,CAHI,EAITX,WAAW,CAACW,CAAD,CAJF,EAKTX,WAAW,CAACW,CAAC,GAAG,CAAL,CALF,CAAX;AAOD,CArDM","sourcesContent":["import type { SkPath } from \"../../skia/types\";\nimport { exhaustiveCheck } from \"../../renderer/typeddash\";\n\nimport type { ExtrapolationType } from \"./interpolate\";\nimport { validateInterpolationOptions, Extrapolate } from \"./interpolate\";\n\nconst lerp = (\n value: number,\n from: number,\n to: number,\n p1: SkPath,\n p2: SkPath\n) => {\n const t = (value - from) / (to - from);\n return p2.interpolate(p1, t)!;\n};\n\n/**\n * Maps an input value within a range to an output path within a path range.\n * @param value - The input value.\n * @param inputRange - The range of the input value.\n * @param outputRange - The range of the output path.\n * @param options - Extrapolation options\n * @returns The output path.\n * @example <caption>Map a value between 0 and 1 to a path between two paths.</caption>\n * const path1 = new Path();\n * path1.moveTo(0, 0);\n * path1.lineTo(100, 0);\n * const path2 = new Path();\n * path2.moveTo(0, 0);\n * path2.lineTo(0, 100);\n * const path = interpolatePath(0.5, [0, 1], [path1, path2]);\n */\nexport const interpolatePaths = (\n value: number,\n input: number[],\n outputRange: SkPath[],\n options?: ExtrapolationType\n) => {\n const extrapolation = validateInterpolationOptions(options);\n if (value < input[0]) {\n switch (extrapolation.extrapolateLeft) {\n case Extrapolate.CLAMP:\n return outputRange[0];\n case Extrapolate.EXTEND:\n return lerp(value, input[0], input[1], outputRange[0], outputRange[1]);\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateLeft);\n }\n } else if (value > input[input.length - 1]) {\n switch (extrapolation.extrapolateRight) {\n case Extrapolate.CLAMP:\n return outputRange[outputRange.length - 1];\n case Extrapolate.EXTEND:\n return lerp(\n value,\n input[input.length - 2],\n input[input.length - 1],\n outputRange[input.length - 2],\n outputRange[input.length - 1]\n );\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateRight);\n }\n }\n let i = 0;\n for (; i <= input.length - 1; i++) {\n if (value >= input[i] && value <= input[i + 1]) {\n break;\n }\n }\n return lerp(\n value,\n input[i],\n input[i + 1],\n outputRange[i],\n outputRange[i + 1]\n );\n};\n"]}