@shopify/react-native-skia 0.1.134 → 0.1.138

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 (108) hide show
  1. package/README.md +4 -47
  2. package/android/build.gradle +1 -2
  3. package/cpp/api/JsiSkFont.h +25 -1
  4. package/cpp/api/JsiSkMatrix.h +12 -0
  5. package/cpp/api/JsiSkTypeface.h +1 -29
  6. package/jestSetup.js +5 -0
  7. package/lib/commonjs/animation/functions/interpolate.js +3 -2
  8. package/lib/commonjs/animation/functions/interpolate.js.map +1 -1
  9. package/lib/commonjs/animation/functions/interpolateColors.js +2 -2
  10. package/lib/commonjs/animation/functions/interpolateColors.js.map +1 -1
  11. package/lib/commonjs/animation/functions/interpolatePaths.js +45 -11
  12. package/lib/commonjs/animation/functions/interpolatePaths.js.map +1 -1
  13. package/lib/commonjs/mock/index.js +121 -177
  14. package/lib/commonjs/mock/index.js.map +1 -1
  15. package/lib/commonjs/renderer/components/Group.js +1 -1
  16. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  17. package/lib/commonjs/renderer/processors/Transform.js +8 -15
  18. package/lib/commonjs/renderer/processors/Transform.js.map +1 -1
  19. package/lib/commonjs/skia/core/Data.js +7 -4
  20. package/lib/commonjs/skia/core/Data.js.map +1 -1
  21. package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
  22. package/lib/commonjs/skia/types/Matrix.js +18 -3
  23. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  24. package/lib/commonjs/skia/web/JsiSkFont.js +6 -0
  25. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  26. package/lib/commonjs/skia/web/JsiSkMatrix.js +4 -0
  27. package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
  28. package/lib/commonjs/values/api.js +1 -7
  29. package/lib/commonjs/values/api.js.map +1 -1
  30. package/lib/commonjs/values/hooks/useComputedValue.js +2 -2
  31. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
  32. package/lib/commonjs/views/SkiaView.web.js +27 -37
  33. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  34. package/lib/commonjs/web/LoadSkiaWeb.js +29 -0
  35. package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -0
  36. package/lib/commonjs/web/WithSkiaWeb.js +39 -0
  37. package/lib/commonjs/web/WithSkiaWeb.js.map +1 -0
  38. package/lib/commonjs/web/index.js +22 -12
  39. package/lib/commonjs/web/index.js.map +1 -1
  40. package/lib/module/animation/functions/interpolate.js +2 -2
  41. package/lib/module/animation/functions/interpolate.js.map +1 -1
  42. package/lib/module/animation/functions/interpolateColors.js +1 -1
  43. package/lib/module/animation/functions/interpolateColors.js.map +1 -1
  44. package/lib/module/animation/functions/interpolatePaths.js +44 -11
  45. package/lib/module/animation/functions/interpolatePaths.js.map +1 -1
  46. package/lib/module/mock/index.js +103 -147
  47. package/lib/module/mock/index.js.map +1 -1
  48. package/lib/module/renderer/components/Group.js +1 -1
  49. package/lib/module/renderer/components/Group.js.map +1 -1
  50. package/lib/module/renderer/processors/Transform.js +8 -15
  51. package/lib/module/renderer/processors/Transform.js.map +1 -1
  52. package/lib/module/skia/core/Data.js +7 -4
  53. package/lib/module/skia/core/Data.js.map +1 -1
  54. package/lib/module/skia/types/Font/Font.js.map +1 -1
  55. package/lib/module/skia/types/Matrix.js +12 -2
  56. package/lib/module/skia/types/Matrix.js.map +1 -1
  57. package/lib/module/skia/web/JsiSkFont.js +6 -0
  58. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  59. package/lib/module/skia/web/JsiSkMatrix.js +4 -0
  60. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  61. package/lib/module/values/api.js +0 -4
  62. package/lib/module/values/api.js.map +1 -1
  63. package/lib/module/values/hooks/useComputedValue.js +1 -1
  64. package/lib/module/values/hooks/useComputedValue.js.map +1 -1
  65. package/lib/module/views/SkiaView.web.js +27 -37
  66. package/lib/module/views/SkiaView.web.js.map +1 -1
  67. package/lib/module/web/LoadSkiaWeb.js +16 -0
  68. package/lib/module/web/LoadSkiaWeb.js.map +1 -0
  69. package/lib/module/web/WithSkiaWeb.js +23 -0
  70. package/lib/module/web/WithSkiaWeb.js.map +1 -0
  71. package/lib/module/web/index.js +2 -9
  72. package/lib/module/web/index.js.map +1 -1
  73. package/lib/typescript/jestSetup.d.ts +1 -0
  74. package/lib/typescript/src/animation/functions/interpolate.d.ts +6 -0
  75. package/lib/typescript/src/animation/functions/interpolatePaths.d.ts +3 -1
  76. package/lib/typescript/src/mock/index.d.ts +11 -42
  77. package/lib/typescript/src/renderer/Canvas.d.ts +1 -1
  78. package/lib/typescript/src/renderer/processors/Transform.d.ts +2 -2
  79. package/lib/typescript/src/skia/types/Font/Font.d.ts +6 -0
  80. package/lib/typescript/src/skia/types/Matrix.d.ts +6 -2
  81. package/lib/typescript/src/skia/types/Typeface/Typeface.d.ts +1 -4
  82. package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -0
  83. package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -0
  84. package/lib/typescript/src/values/api.d.ts +0 -1
  85. package/lib/typescript/src/views/SkiaView.web.d.ts +4 -6
  86. package/lib/typescript/src/web/LoadSkiaWeb.d.ts +6 -0
  87. package/lib/typescript/src/web/WithSkiaWeb.d.ts +12 -0
  88. package/lib/typescript/src/web/index.d.ts +2 -5
  89. package/package.json +7 -3
  90. package/scripts/setup-canvaskit.js +74 -0
  91. package/src/animation/functions/interpolate.ts +4 -2
  92. package/src/animation/functions/interpolateColors.ts +1 -1
  93. package/src/animation/functions/interpolatePaths.ts +59 -10
  94. package/src/mock/index.ts +103 -149
  95. package/src/renderer/components/Group.tsx +1 -1
  96. package/src/renderer/processors/Transform.ts +7 -10
  97. package/src/skia/core/Data.ts +7 -8
  98. package/src/skia/types/Font/Font.ts +7 -0
  99. package/src/skia/types/Matrix.ts +19 -3
  100. package/src/skia/types/Typeface/Typeface.ts +1 -4
  101. package/src/skia/web/JsiSkFont.ts +6 -0
  102. package/src/skia/web/JsiSkMatrix.ts +4 -0
  103. package/src/values/api.ts +0 -2
  104. package/src/values/hooks/useComputedValue.ts +1 -1
  105. package/src/views/SkiaView.web.tsx +36 -43
  106. package/src/web/LoadSkiaWeb.tsx +24 -0
  107. package/src/web/WithSkiaWeb.tsx +37 -0
  108. package/src/web/index.ts +2 -15
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).
@@ -133,8 +133,7 @@ android {
133
133
 
134
134
  externalNativeBuild {
135
135
  cmake {
136
- path file('CMakeLists.txt')
137
- version '3.10.2'
136
+ path file('CMakeLists.txt')
138
137
  }
139
138
  }
140
139
 
@@ -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
  /**
@@ -22,24 +22,12 @@ using namespace facebook;
22
22
 
23
23
  class JsiSkTypeface : public JsiSkWrappingSkPtrHostObject<SkTypeface> {
24
24
  public:
25
- JSI_PROPERTY_GET(bold) {
26
- RNSkLogger::warnToJavascriptConsole(runtime, "Typeface.bold is deprecated and will be removed in a future release.");
27
- return jsi::Value(getObject()->isBold());
28
- }
29
-
30
- JSI_PROPERTY_GET(italic) {
31
- RNSkLogger::warnToJavascriptConsole(runtime, "Typeface.italic is deprecated and will be removed in a future release.");
32
- return jsi::Value(getObject()->isItalic());
33
- }
34
-
35
25
  // TODO: declare in JsiSkWrappingSkPtrHostObject via extra template parameter?
36
26
  JSI_PROPERTY_GET(__typename__) {
37
27
  return jsi::String::createFromUtf8(runtime, "Typeface");
38
28
  }
39
29
 
40
- JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkTypeface, bold),
41
- JSI_EXPORT_PROP_GET(JsiSkTypeface, italic),
42
- JSI_EXPORT_PROP_GET(JsiSkTypeface, __typename__))
30
+ JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkTypeface, __typename__))
43
31
 
44
32
  JsiSkTypeface(std::shared_ptr<RNSkPlatformContext> context,
45
33
  sk_sp<SkTypeface> typeface)
@@ -64,22 +52,6 @@ public:
64
52
  return jsi::Object::createFromHostObject(
65
53
  runtime, std::make_shared<JsiSkTypeface>(std::move(context), std::move(tf)));
66
54
  }
67
-
68
- private:
69
- static SkFontStyle getFontStyleFromNumber(int fontStyle) {
70
- switch (fontStyle) {
71
- case 0:
72
- return SkFontStyle::Normal();
73
- case 1:
74
- return SkFontStyle::Bold();
75
- case 2:
76
- return SkFontStyle::Italic();
77
- case 3:
78
- return SkFontStyle::BoldItalic();
79
- default:
80
- return SkFontStyle::Normal();
81
- };
82
- }
83
55
  };
84
56
 
85
57
  } // namespace RNSkia
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,aA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AAM,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\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;;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;;;AACO,SAASK,4BAAT,CACLX,IADK,EAEwB;AAC7B;AACA,Q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G,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,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,C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ATM","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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BC,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,CAAV;AACA,SAAOG,EAAE,CAACE,WAAH,CAAeH,EAAf,EAAmBE,CAAnB,CAAP;AACD,CATD;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,gBAAgB,GAAG,CAC9BP,KAD8B,EAE9BQ,KAF8B,EAG9BC,WAH8B,EAI9BC,OAJ8B,KAK3B;AACH,QAAMC,aAAa,GAAG,+CAA6BD,OAA7B,CAAtB;;AACA,MAAIV,KAAK,G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AAIpB,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"]}