@shopify/react-native-skia 0.1.133 → 0.1.137

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +4 -47
  2. package/android/CMakeLists.txt +1 -1
  3. package/android/build.gradle +17 -2
  4. package/cpp/api/JsiSkFont.h +25 -1
  5. package/cpp/api/JsiSkMatrix.h +12 -0
  6. package/cpp/rnskia/RNSkValueApi.h +6 -6
  7. package/cpp/rnskia/values/{RNSkDerivedValue.h → RNSkComputedValue.h} +7 -7
  8. package/ios/RNSkia-iOS/SkiaManager.mm +1 -1
  9. package/jestSetup.js +5 -0
  10. package/lib/commonjs/animation/functions/interpolate.js +3 -2
  11. package/lib/commonjs/animation/functions/interpolate.js.map +1 -1
  12. package/lib/commonjs/animation/functions/interpolateColors.js +2 -2
  13. package/lib/commonjs/animation/functions/interpolateColors.js.map +1 -1
  14. package/lib/commonjs/animation/functions/interpolatePaths.js +45 -11
  15. package/lib/commonjs/animation/functions/interpolatePaths.js.map +1 -1
  16. package/lib/commonjs/mock/index.js +134 -0
  17. package/lib/commonjs/mock/index.js.map +1 -0
  18. package/lib/commonjs/renderer/components/Group.js +1 -1
  19. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  20. package/lib/commonjs/renderer/processors/Transform.js +8 -15
  21. package/lib/commonjs/renderer/processors/Transform.js.map +1 -1
  22. package/lib/commonjs/skia/core/Data.js +33 -43
  23. package/lib/commonjs/skia/core/Data.js.map +1 -1
  24. package/lib/commonjs/skia/core/Typeface.js +1 -1
  25. package/lib/commonjs/skia/core/Typeface.js.map +1 -1
  26. package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
  27. package/lib/commonjs/skia/types/Matrix.js +17 -2
  28. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  29. package/lib/commonjs/skia/web/JsiSkFont.js +6 -0
  30. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  31. package/lib/commonjs/skia/web/JsiSkMatrix.js +4 -0
  32. package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
  33. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  34. package/lib/commonjs/values/api.js +1 -7
  35. package/lib/commonjs/values/api.js.map +1 -1
  36. package/lib/commonjs/values/api.web.js +3 -3
  37. package/lib/commonjs/values/api.web.js.map +1 -1
  38. package/lib/commonjs/values/hooks/index.js +4 -4
  39. package/lib/commonjs/values/hooks/index.js.map +1 -1
  40. package/lib/commonjs/values/hooks/useComputedValue.js +32 -0
  41. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -0
  42. package/lib/commonjs/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +4 -4
  43. package/lib/commonjs/values/web/RNSkComputedValue.js.map +1 -0
  44. package/lib/commonjs/values/web/api.js +3 -3
  45. package/lib/commonjs/values/web/api.js.map +1 -1
  46. package/lib/commonjs/views/SkiaView.web.js +18 -18
  47. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  48. package/lib/commonjs/web/LoadSkiaWeb.js +25 -0
  49. package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -0
  50. package/lib/commonjs/web/WithSkiaWeb.js +38 -0
  51. package/lib/commonjs/web/WithSkiaWeb.js.map +1 -0
  52. package/lib/commonjs/web/index.js +22 -12
  53. package/lib/commonjs/web/index.js.map +1 -1
  54. package/lib/module/animation/functions/interpolate.js +2 -2
  55. package/lib/module/animation/functions/interpolate.js.map +1 -1
  56. package/lib/module/animation/functions/interpolateColors.js +1 -1
  57. package/lib/module/animation/functions/interpolateColors.js.map +1 -1
  58. package/lib/module/animation/functions/interpolatePaths.js +44 -11
  59. package/lib/module/animation/functions/interpolatePaths.js.map +1 -1
  60. package/lib/module/mock/index.js +108 -0
  61. package/lib/module/mock/index.js.map +1 -0
  62. package/lib/module/renderer/components/Group.js +1 -1
  63. package/lib/module/renderer/components/Group.js.map +1 -1
  64. package/lib/module/renderer/processors/Transform.js +8 -15
  65. package/lib/module/renderer/processors/Transform.js.map +1 -1
  66. package/lib/module/skia/core/Data.js +32 -41
  67. package/lib/module/skia/core/Data.js.map +1 -1
  68. package/lib/module/skia/core/Typeface.js +1 -1
  69. package/lib/module/skia/core/Typeface.js.map +1 -1
  70. package/lib/module/skia/types/Font/Font.js.map +1 -1
  71. package/lib/module/skia/types/Matrix.js +11 -1
  72. package/lib/module/skia/types/Matrix.js.map +1 -1
  73. package/lib/module/skia/web/JsiSkFont.js +6 -0
  74. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  75. package/lib/module/skia/web/JsiSkMatrix.js +4 -0
  76. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  77. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  78. package/lib/module/values/api.js +0 -4
  79. package/lib/module/values/api.js.map +1 -1
  80. package/lib/module/values/api.web.js +1 -1
  81. package/lib/module/values/api.web.js.map +1 -1
  82. package/lib/module/values/hooks/index.js +1 -1
  83. package/lib/module/values/hooks/index.js.map +1 -1
  84. package/lib/module/values/hooks/useComputedValue.js +18 -0
  85. package/lib/module/values/hooks/useComputedValue.js.map +1 -0
  86. package/lib/module/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +2 -2
  87. package/lib/module/values/web/RNSkComputedValue.js.map +1 -0
  88. package/lib/module/values/web/api.js +3 -3
  89. package/lib/module/values/web/api.js.map +1 -1
  90. package/lib/module/views/SkiaView.web.js +18 -18
  91. package/lib/module/views/SkiaView.web.js.map +1 -1
  92. package/lib/module/web/LoadSkiaWeb.js +12 -0
  93. package/lib/module/web/LoadSkiaWeb.js.map +1 -0
  94. package/lib/module/web/WithSkiaWeb.js +22 -0
  95. package/lib/module/web/WithSkiaWeb.js.map +1 -0
  96. package/lib/module/web/index.js +2 -9
  97. package/lib/module/web/index.js.map +1 -1
  98. package/lib/typescript/jestSetup.d.ts +1 -0
  99. package/lib/typescript/src/animation/functions/interpolate.d.ts +6 -0
  100. package/lib/typescript/src/animation/functions/interpolatePaths.d.ts +3 -1
  101. package/lib/typescript/src/mock/index.d.ts +16 -0
  102. package/lib/typescript/src/renderer/Canvas.d.ts +1 -1
  103. package/lib/typescript/src/renderer/processors/Transform.d.ts +2 -2
  104. package/lib/typescript/src/skia/core/Data.d.ts +3 -3
  105. package/lib/typescript/src/skia/types/Font/Font.d.ts +6 -0
  106. package/lib/typescript/src/skia/types/Matrix.d.ts +5 -1
  107. package/lib/typescript/src/skia/types/Skia.d.ts +1 -1
  108. package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -0
  109. package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -0
  110. package/lib/typescript/src/values/api.d.ts +0 -1
  111. package/lib/typescript/src/values/api.web.d.ts +1 -1
  112. package/lib/typescript/src/values/hooks/index.d.ts +1 -1
  113. package/lib/typescript/src/values/hooks/{useDerivedValue.d.ts → useComputedValue.d.ts} +2 -1
  114. package/lib/typescript/src/values/types.d.ts +2 -2
  115. package/lib/typescript/src/values/web/{RNSkDerivedValue.d.ts → RNSkComputedValue.d.ts} +1 -1
  116. package/lib/typescript/src/views/SkiaView.web.d.ts +2 -2
  117. package/lib/typescript/src/web/LoadSkiaWeb.d.ts +6 -0
  118. package/lib/typescript/src/web/WithSkiaWeb.d.ts +10 -0
  119. package/lib/typescript/src/web/index.d.ts +2 -5
  120. package/package.json +8 -3
  121. package/scripts/setup-canvaskit.js +74 -0
  122. package/src/animation/functions/interpolate.ts +4 -2
  123. package/src/animation/functions/interpolateColors.ts +1 -1
  124. package/src/animation/functions/interpolatePaths.ts +59 -10
  125. package/src/mock/index.ts +110 -0
  126. package/src/renderer/components/Group.tsx +1 -1
  127. package/src/renderer/processors/Transform.ts +7 -10
  128. package/src/skia/core/Data.ts +67 -50
  129. package/src/skia/core/Typeface.ts +6 -1
  130. package/src/skia/types/Font/Font.ts +7 -0
  131. package/src/skia/types/Matrix.ts +18 -2
  132. package/src/skia/types/Skia.ts +1 -1
  133. package/src/skia/web/JsiSkFont.ts +6 -0
  134. package/src/skia/web/JsiSkMatrix.ts +4 -0
  135. package/src/skia/web/JsiSkia.ts +1 -1
  136. package/src/values/api.ts +0 -2
  137. package/src/values/api.web.ts +1 -1
  138. package/src/values/hooks/index.ts +1 -1
  139. package/src/values/hooks/useComputedValue.ts +23 -0
  140. package/src/values/types.ts +2 -2
  141. package/src/values/web/{RNSkDerivedValue.ts → RNSkComputedValue.ts} +1 -1
  142. package/src/values/web/api.ts +3 -3
  143. package/src/views/SkiaView.web.tsx +27 -24
  144. package/src/web/LoadSkiaWeb.tsx +18 -0
  145. package/src/web/WithSkiaWeb.tsx +32 -0
  146. package/src/web/index.ts +2 -15
  147. package/lib/commonjs/values/hooks/useDerivedValue.js +0 -25
  148. package/lib/commonjs/values/hooks/useDerivedValue.js.map +0 -1
  149. package/lib/commonjs/values/web/RNSkDerivedValue.js.map +0 -1
  150. package/lib/module/values/hooks/useDerivedValue.js +0 -14
  151. package/lib/module/values/hooks/useDerivedValue.js.map +0 -1
  152. package/lib/module/values/web/RNSkDerivedValue.js.map +0 -1
  153. package/src/values/hooks/useDerivedValue.ts +0 -18
package/README.md CHANGED
@@ -1,52 +1,9 @@
1
1
  # React Native Skia
2
2
 
3
- React Native Skia brings the [Skia Graphics Library](https://skia.org/) to React Native.
4
- Skia serves as the graphics engine for Google Chrome and Chrome OS, Android, Flutter, Mozilla Firefox, Firefox OS, and many other products.
3
+ High-performance 2d Graphics for React Native using Skia
5
4
 
6
- Checkout the full documentation [here](https://shopify.github.io/react-native-skia).
7
-
8
- ```sh
9
- yarn add @shopify/react-native-skia
10
- ```
11
-
12
- Or using npm:
13
-
14
- ```sh
15
- npm install @shopify/react-native-skia
16
- ```
17
-
18
- ## iOS
19
-
20
- Run `pod install` on the `ios/` directory.
21
-
22
- ## Android
23
-
24
- > **Version compatibility**: `react-native@>=0.66` is required.
25
-
26
- Currently, you will need Android NDK to be installed.
27
- If you have Android Studio installed, make sure `$ANDROID_NDK` is available.
28
- `ANDROID_NDK=/Users/username/Library/Android/sdk/ndk-bundle` for instance.
5
+ <img width="400" alt="skia" src="https://user-images.githubusercontent.com/306134/146549218-b7959ad9-0107-4c1c-b439-b96c780f5230.png">
29
6
 
30
- If the NDK is not installed, you can install it via Android Studio by going to the menu _File > Project Structure_
31
-
32
- And then the _SDK Location_ section. It will show you the NDK path, or the option to download it if you don't have it installed.
33
-
34
- ### Proguard
35
-
36
- If you're using Proguard, make sure to add the following rule:
37
-
38
- ```
39
- -keep class com.shopify.reactnative.skia.** { *; }
40
- ```
41
-
42
- ## Playground
43
-
44
- We have an example project you can play with [here](https://github.com/Shopify/react-native-skia/tree/main/example).
45
-
46
- ```sh
47
- yarn
48
- cd package && yarn && cd ..
49
- cd example && yarn && yarn start
50
- ```
7
+ Checkout the full documentation [here](https://shopify.github.io/react-native-skia).
51
8
 
52
- To run the example project on iOS, you will need to run `pod install`, and on Android, you will also need Android NDK to be installed ([see here](#android)).
9
+ Documentation on the library development is available [here](https://github.com/Shopify/react-native-skia#library-development).
@@ -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 ->
@@ -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),
@@ -46,6 +46,10 @@ public:
46
46
  );
47
47
  }
48
48
 
49
+ JSI_PROPERTY_GET(__typename__) {
50
+ return jsi::String::createFromUtf8(runtime, "Matrix");
51
+ }
52
+
49
53
  JSI_HOST_FUNCTION(concat) {
50
54
  auto m3 = JsiSkMatrix::fromValue(runtime, arguments[0]);
51
55
  getObject()->preConcat(*m3);
@@ -78,6 +82,13 @@ public:
78
82
  getObject()->preRotate(SkRadiansToDegrees(a));
79
83
  return jsi::Value::undefined();
80
84
  }
85
+
86
+ JSI_HOST_FUNCTION(identity) {
87
+ getObject()->setIdentity();
88
+ return jsi::Value::undefined();
89
+ }
90
+
91
+ JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkMatrix, __typename__))
81
92
 
82
93
  JSI_EXPORT_FUNCTIONS(
83
94
  JSI_EXPORT_FUNC(JsiSkMatrix, concat),
@@ -85,6 +96,7 @@ public:
85
96
  JSI_EXPORT_FUNC(JsiSkMatrix, scale),
86
97
  JSI_EXPORT_FUNC(JsiSkMatrix, skew),
87
98
  JSI_EXPORT_FUNC(JsiSkMatrix, rotate),
99
+ JSI_EXPORT_FUNC(JsiSkMatrix, identity),
88
100
  )
89
101
 
90
102
  /**
@@ -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,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A,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,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;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AAEG,KAAK,CAAC,CAAD,CAF2B;AAGhDrB,IAAAA,cAAc,EAAEsB,MAAM,CAAC,CAAD,CAH0B;AAIhDrB,IAAAA,eAAe,EAAEqB,MAAM,CAAC,CAAD;AAJyB,GAAlD;;AAMA,MAAIC,MAAM,GAAG,CAAb,EAAgB;AACd,QAAIrB,CAAC,GAAGmB,KAAK,CAACE,MAAM,GAAG,CAAV,CAAb,EAA2B;AACzBP,MAAAA,aAAa,CAACC,aAAd,GAA8BI,KAAK,CAACE,MAAM,GAAG,CAAV,CAAnC;AACAP,MAAAA,aAAa,CAACE,cAAd,GAA+BG,KAAK,CAACE,MAAM,GAAG,CAAV,CAApC;AACAP,MAAAA,aAAa,CAAChB,cAAd,GAA+BsB,MAAM,CAACC,MAAM,GAAG,CAAV,CAArC;AACAP,MAAAA,aAAa,CAACf,eAAd,GAAgCqB,MAAM,CAACC,MAAM,GAAG,CAAV,CAAtC;AACD,KALD,MAKO;AACL,WAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,MAApB,EAA4B,EAAEC,CAA9B,EAAiC;AAC/B,YAAItB,CAAC,IAAImB,KAAK,CAACG,CAAD,CAAd,EAAmB;AACjBR,UAAAA,aAAa,CAACC,aAAd,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\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","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,EAGR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C,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;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,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"],"mappings":";;;;;;;AACA;;AAGA;;AAEA,MAAMA,IAAI,GAAG,CACXC,KADW,EAEXC,IAFW,EAGXC,EAHW,EAIXC,EAJW,EAKXC,EALW,KAMR;AACH,QAAMC,CAAC,GAAG,CAACL,KAAK,GAAGC,IAAT,KAAkBC,EAAE,GAAGD,IAAvB,CA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AJF,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"]}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.vec = exports.Skia = exports.Mock = void 0;
7
+
8
+ var Values = _interopRequireWildcard(require("../values/web"));
9
+
10
+ var ValuesHooks = _interopRequireWildcard(require("../values/hooks"));
11
+
12
+ var BaseSkia = _interopRequireWildcard(require("../skia/types"));
13
+
14
+ var _useSharedValueEffect = require("../external/reanimated/useSharedValueEffect");
15
+
16
+ var timingFunctions = _interopRequireWildcard(require("../animation/timing"));
17
+
18
+ var springFunctions = _interopRequireWildcard(require("../animation/spring"));
19
+
20
+ var decayFunctions = _interopRequireWildcard(require("../animation/decay"));
21
+
22
+ var interpolateFn = _interopRequireWildcard(require("../animation/functions/interpolate"));
23
+
24
+ var interpolatePathFn = _interopRequireWildcard(require("../animation/functions/interpolatePaths"));
25
+
26
+ var interpolateVectorFn = _interopRequireWildcard(require("../animation/functions/interpolateVector"));
27
+
28
+ var _ShaderLib = require("../renderer/components/shaders/ShaderLib");
29
+
30
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
+
32
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
33
+
34
+ /* eslint-disable @typescript-eslint/no-explicit-any */
35
+ class Stub {
36
+ constructor() {
37
+ return new Proxy(() => {}, {
38
+ get: () => new Stub(),
39
+ apply: () => new Stub(),
40
+ set: () => true
41
+ });
42
+ }
43
+
44
+ }
45
+
46
+ const Noop = () => {};
47
+
48
+ const Skia = new Stub();
49
+ exports.Skia = Skia;
50
+
51
+ const vec = (x, y) => {
52
+ var _ref;
53
+
54
+ return {
55
+ x: x !== null && x !== void 0 ? x : 0,
56
+ y: (_ref = y !== null && y !== void 0 ? y : x) !== null && _ref !== void 0 ? _ref : 0
57
+ };
58
+ };
59
+
60
+ exports.vec = vec;
61
+ const Mock = {
62
+ // SkiaExports
63
+ // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc
64
+ Skia,
65
+ ...BaseSkia,
66
+ // 2. Hooks
67
+ useDataCollection: Noop,
68
+ useRawData: Noop,
69
+ useData: Noop,
70
+ useFont: Noop,
71
+ useTypeface: Noop,
72
+ useImage: Noop,
73
+ usePath: Noop,
74
+ useSVG: Noop,
75
+ useTextPath: Noop,
76
+ usePaint: Noop,
77
+ usePicture: Noop,
78
+ useSvgPath: Noop,
79
+ // 3. Point/Rect/Transform utilities
80
+ vec,
81
+ rect: (x, y, width, height) => ({
82
+ x,
83
+ y,
84
+ width,
85
+ height
86
+ }),
87
+ rrect: (r, rx, ry) => ({
88
+ rect: r,
89
+ rx,
90
+ ry
91
+ }),
92
+ point: vec,
93
+ add: (a, b) => vec(a.x + b.x, a.y + b.y),
94
+ sub: (a, b) => vec(a.x - b.x, a.y - b.y),
95
+ neg: a => vec(-a.x, -a.y),
96
+ dist: (a, b) => Math.hypot(a.x - b.x, a.y - b.y),
97
+ translate: _ref2 => {
98
+ let {
99
+ x,
100
+ y
101
+ } = _ref2;
102
+ return [{
103
+ translateX: x
104
+ }, {
105
+ translateY: y
106
+ }];
107
+ },
108
+ bounds: Noop,
109
+ topLeft: Noop,
110
+ topRight: Noop,
111
+ bottomLeft: Noop,
112
+ bottomRight: Noop,
113
+ center: Noop,
114
+ processTransform2d: Noop,
115
+ // ExternalExports
116
+ useSharedValueEffect: _useSharedValueEffect.useSharedValueEffect,
117
+ // ValueExports
118
+ ...Values,
119
+ ...ValuesHooks,
120
+ // Animations
121
+ ...timingFunctions,
122
+ ...springFunctions,
123
+ ...decayFunctions,
124
+ ...interpolateFn,
125
+ ...interpolatePathFn,
126
+ ...interpolateVectorFn,
127
+ interpolateColors: (_value, _inputRange, _outputRange) => Float32Array.of(0, 0, 0, 0),
128
+ mixColors: (_v, _x, _y) => Float32Array.of(0, 0, 0, 0),
129
+ ShaderLib: _ShaderLib.ShaderLib,
130
+ createDrawing: Noop,
131
+ createDeclaration: Noop
132
+ };
133
+ exports.Mock = Mock;
134
+ //# sourceMappingURL=index.js.map