react-native-wagmi-charts 1.0.4 → 1.2.1

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 (132) hide show
  1. package/.DS_Store +0 -0
  2. package/.prettierrc.js +5 -0
  3. package/README.md +171 -121
  4. package/example/.DS_Store +0 -0
  5. package/example/README.md +32 -0
  6. package/example/package.json +1 -1
  7. package/example/src/App.tsx +32 -7
  8. package/example/src/CandlestickChart.tsx +23 -11
  9. package/example/src/LineChart.tsx +51 -20
  10. package/example/src/{candlestick-data.json → data/candlestick-data.json} +0 -0
  11. package/example/src/{candlestick-data2.json → data/candlestick-data2.json} +0 -0
  12. package/example/src/{line-data.json → data/line-data.json} +0 -0
  13. package/example/src/{line-data2.json → data/line-data2.json} +0 -0
  14. package/example/yarn.lock +5 -5
  15. package/lib/commonjs/charts/candle/Crosshair.js +6 -17
  16. package/lib/commonjs/charts/candle/Crosshair.js.map +1 -1
  17. package/lib/commonjs/charts/candle/CrosshairTooltip.js +12 -8
  18. package/lib/commonjs/charts/candle/CrosshairTooltip.js.map +1 -1
  19. package/lib/commonjs/charts/candle/DatetimeText.js +7 -8
  20. package/lib/commonjs/charts/candle/DatetimeText.js.map +1 -1
  21. package/lib/commonjs/charts/candle/Line.js.map +1 -1
  22. package/lib/commonjs/charts/candle/PriceText.js +7 -8
  23. package/lib/commonjs/charts/candle/PriceText.js.map +1 -1
  24. package/lib/commonjs/charts/candle/useCandleData.js.map +1 -1
  25. package/lib/commonjs/charts/candle/useCandlestickChart.js.map +1 -1
  26. package/lib/commonjs/charts/candle/useDatetime.js.map +1 -1
  27. package/lib/commonjs/charts/candle/usePrice.js.map +1 -1
  28. package/lib/commonjs/charts/candle/utils.js.map +1 -1
  29. package/lib/commonjs/charts/line/Chart.js.map +1 -1
  30. package/lib/commonjs/charts/line/Cursor.js.map +1 -1
  31. package/lib/commonjs/charts/line/CursorCrosshair.js +4 -3
  32. package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
  33. package/lib/commonjs/charts/line/CursorLine.js +8 -1
  34. package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
  35. package/lib/commonjs/charts/line/DatetimeText.js +7 -8
  36. package/lib/commonjs/charts/line/DatetimeText.js.map +1 -1
  37. package/lib/commonjs/charts/line/Path.js +13 -16
  38. package/lib/commonjs/charts/line/Path.js.map +1 -1
  39. package/lib/commonjs/charts/line/PriceText.js +7 -8
  40. package/lib/commonjs/charts/line/PriceText.js.map +1 -1
  41. package/lib/commonjs/charts/line/interpolatePath.js +600 -0
  42. package/lib/commonjs/charts/line/interpolatePath.js.map +1 -0
  43. package/lib/commonjs/charts/line/useDatetime.js.map +1 -1
  44. package/lib/commonjs/charts/line/usePrice.js.map +1 -1
  45. package/lib/commonjs/charts/line/utils.js +1 -70
  46. package/lib/commonjs/charts/line/utils.js.map +1 -1
  47. package/lib/commonjs/components/AnimatedText.js +63 -0
  48. package/lib/commonjs/components/AnimatedText.js.map +1 -0
  49. package/lib/commonjs/utils.js.map +1 -1
  50. package/lib/module/charts/candle/Crosshair.js +7 -16
  51. package/lib/module/charts/candle/Crosshair.js.map +1 -1
  52. package/lib/module/charts/candle/CrosshairTooltip.js +10 -8
  53. package/lib/module/charts/candle/CrosshairTooltip.js.map +1 -1
  54. package/lib/module/charts/candle/DatetimeText.js +6 -7
  55. package/lib/module/charts/candle/DatetimeText.js.map +1 -1
  56. package/lib/module/charts/candle/Line.js.map +1 -1
  57. package/lib/module/charts/candle/PriceText.js +6 -7
  58. package/lib/module/charts/candle/PriceText.js.map +1 -1
  59. package/lib/module/charts/candle/useCandleData.js.map +1 -1
  60. package/lib/module/charts/candle/useCandlestickChart.js.map +1 -1
  61. package/lib/module/charts/candle/useDatetime.js.map +1 -1
  62. package/lib/module/charts/candle/usePrice.js.map +1 -1
  63. package/lib/module/charts/candle/utils.js.map +1 -1
  64. package/lib/module/charts/line/Chart.js.map +1 -1
  65. package/lib/module/charts/line/Cursor.js.map +1 -1
  66. package/lib/module/charts/line/CursorCrosshair.js +4 -3
  67. package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
  68. package/lib/module/charts/line/CursorLine.js +7 -1
  69. package/lib/module/charts/line/CursorLine.js.map +1 -1
  70. package/lib/module/charts/line/DatetimeText.js +6 -7
  71. package/lib/module/charts/line/DatetimeText.js.map +1 -1
  72. package/lib/module/charts/line/Path.js +11 -15
  73. package/lib/module/charts/line/Path.js.map +1 -1
  74. package/lib/module/charts/line/PriceText.js +6 -7
  75. package/lib/module/charts/line/PriceText.js.map +1 -1
  76. package/lib/module/charts/line/interpolatePath.js +587 -0
  77. package/lib/module/charts/line/interpolatePath.js.map +1 -0
  78. package/lib/module/charts/line/useDatetime.js.map +1 -1
  79. package/lib/module/charts/line/usePrice.js.map +1 -1
  80. package/lib/module/charts/line/utils.js +1 -66
  81. package/lib/module/charts/line/utils.js.map +1 -1
  82. package/lib/module/components/AnimatedText.js +43 -0
  83. package/lib/module/components/AnimatedText.js.map +1 -0
  84. package/lib/module/utils.js.map +1 -1
  85. package/lib/typescript/src/charts/candle/Crosshair.d.ts +4 -4
  86. package/lib/typescript/src/charts/candle/DatetimeText.d.ts +3 -2
  87. package/lib/typescript/src/charts/candle/Line.d.ts +1 -1
  88. package/lib/typescript/src/charts/candle/PriceText.d.ts +3 -3
  89. package/lib/typescript/src/charts/candle/types.d.ts +8 -3
  90. package/lib/typescript/src/charts/candle/useCandleData.d.ts +3 -3
  91. package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts +2 -1
  92. package/lib/typescript/src/charts/candle/useDatetime.d.ts +5 -7
  93. package/lib/typescript/src/charts/candle/usePrice.d.ts +5 -8
  94. package/lib/typescript/src/charts/candle/utils.d.ts +1 -1
  95. package/lib/typescript/src/charts/line/Chart.d.ts +1 -1
  96. package/lib/typescript/src/charts/line/Cursor.d.ts +1 -2
  97. package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +3 -2
  98. package/lib/typescript/src/charts/line/DatetimeText.d.ts +5 -6
  99. package/lib/typescript/src/charts/line/Path.d.ts +17 -1
  100. package/lib/typescript/src/charts/line/PriceText.d.ts +3 -2
  101. package/lib/typescript/src/charts/line/interpolatePath.d.ts +50 -0
  102. package/lib/typescript/src/charts/line/useDatetime.d.ts +4 -5
  103. package/lib/typescript/src/charts/line/usePrice.d.ts +3 -2
  104. package/lib/typescript/src/charts/line/utils.d.ts +0 -13
  105. package/lib/typescript/src/components/AnimatedText.d.ts +9 -0
  106. package/lib/typescript/src/utils.d.ts +2 -4
  107. package/package.json +4 -4
  108. package/src/charts/candle/Crosshair.tsx +20 -20
  109. package/src/charts/candle/CrosshairTooltip.tsx +11 -4
  110. package/src/charts/candle/DatetimeText.tsx +5 -4
  111. package/src/charts/candle/Line.tsx +1 -1
  112. package/src/charts/candle/PriceText.tsx +5 -5
  113. package/src/charts/candle/types.ts +11 -3
  114. package/src/charts/candle/useCandleData.ts +3 -2
  115. package/src/charts/candle/useCandlestickChart.ts +2 -1
  116. package/src/charts/candle/useDatetime.ts +7 -3
  117. package/src/charts/candle/usePrice.ts +10 -3
  118. package/src/charts/candle/utils.ts +1 -1
  119. package/src/charts/line/Chart.tsx +1 -1
  120. package/src/charts/line/Cursor.tsx +7 -3
  121. package/src/charts/line/CursorCrosshair.tsx +4 -3
  122. package/src/charts/line/CursorLine.tsx +9 -1
  123. package/src/charts/line/DatetimeText.tsx +8 -7
  124. package/src/charts/line/Path.tsx +25 -21
  125. package/src/charts/line/PriceText.tsx +5 -4
  126. package/src/charts/line/interpolatePath.ts +650 -0
  127. package/src/charts/line/useDatetime.ts +3 -2
  128. package/src/charts/line/usePrice.ts +2 -1
  129. package/src/charts/line/utils.ts +2 -79
  130. package/src/components/AnimatedText.tsx +53 -0
  131. package/src/utils.ts +3 -3
  132. package/yarn.lock +5 -5
@@ -0,0 +1,600 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.splitCurve = splitCurve;
7
+ exports.pathCommandsFromString = pathCommandsFromString;
8
+ exports.interpolatePathCommands = interpolatePathCommands;
9
+ exports.default = interpolatePath;
10
+
11
+ // @ts-nocheck
12
+
13
+ /**
14
+ * Reanimated compatible fork of https://github.com/pbeshai/d3-interpolate-path
15
+ */
16
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
17
+
18
+ /**
19
+ * de Casteljau's algorithm for drawing and splitting bezier curves.
20
+ * Inspired by https://pomax.github.io/bezierinfo/
21
+ *
22
+ * @param {Number[][]} points Array of [x,y] points: [start, control1, control2, ..., end]
23
+ * The original segment to split.
24
+ * @param {Number} t Where to split the curve (value between [0, 1])
25
+ * @return {Object} An object { left, right } where left is the segment from 0..t and
26
+ * right is the segment from t..1.
27
+ */
28
+ function decasteljau(points, t) {
29
+ 'worklet';
30
+
31
+ const left = [];
32
+ const right = [];
33
+
34
+ function decasteljauRecurse(points, t) {
35
+ 'worklet';
36
+
37
+ if (points.length === 1) {
38
+ left.push(points[0]);
39
+ right.push(points[0]);
40
+ } else {
41
+ const newPoints = Array(points.length - 1);
42
+
43
+ for (let i = 0; i < newPoints.length; i++) {
44
+ if (i === 0) {
45
+ left.push(points[0]);
46
+ }
47
+
48
+ if (i === newPoints.length - 1) {
49
+ right.push(points[i + 1]);
50
+ }
51
+
52
+ newPoints[i] = [(1 - t) * points[i][0] + t * points[i + 1][0], (1 - t) * points[i][1] + t * points[i + 1][1]];
53
+ }
54
+
55
+ decasteljauRecurse(newPoints, t);
56
+ }
57
+ }
58
+
59
+ if (points.length) {
60
+ decasteljauRecurse(points, t);
61
+ }
62
+
63
+ return {
64
+ left,
65
+ right: right.reverse()
66
+ };
67
+ }
68
+ /**
69
+ * Convert segments represented as points back into a command object
70
+ *
71
+ * @param {Number[][]} points Array of [x,y] points: [start, control1, control2, ..., end]
72
+ * Represents a segment
73
+ * @return {Object} A command object representing the segment.
74
+ */
75
+
76
+
77
+ function pointsToCommand(points) {
78
+ 'worklet';
79
+
80
+ const command = {};
81
+
82
+ if (points.length === 4) {
83
+ command.x2 = points[2][0];
84
+ command.y2 = points[2][1];
85
+ }
86
+
87
+ if (points.length >= 3) {
88
+ command.x1 = points[1][0];
89
+ command.y1 = points[1][1];
90
+ }
91
+
92
+ command.x = points[points.length - 1][0];
93
+ command.y = points[points.length - 1][1];
94
+
95
+ if (points.length === 4) {
96
+ // start, control1, control2, end
97
+ command.type = 'C';
98
+ } else if (points.length === 3) {
99
+ // start, control, end
100
+ command.type = 'Q';
101
+ } else {
102
+ // start, end
103
+ command.type = 'L';
104
+ }
105
+
106
+ return command;
107
+ }
108
+ /**
109
+ * Runs de Casteljau's algorithm enough times to produce the desired number of segments.
110
+ *
111
+ * @param {Number[][]} points Array of [x,y] points for de Casteljau (the initial segment to split)
112
+ * @param {Number} segmentCount Number of segments to split the original into
113
+ * @return {Number[][][]} Array of segments
114
+ */
115
+
116
+
117
+ function splitCurveAsPoints(points, segmentCount) {
118
+ 'worklet';
119
+
120
+ segmentCount = segmentCount || 2;
121
+ const segments = [];
122
+ let remainingCurve = points;
123
+ const tIncrement = 1 / segmentCount; // x-----x-----x-----x
124
+ // t= 0.33 0.66 1
125
+ // x-----o-----------x
126
+ // r= 0.33
127
+ // x-----o-----x
128
+ // r= 0.5 (0.33 / (1 - 0.33)) === tIncrement / (1 - (tIncrement * (i - 1))
129
+ // x-----x-----x-----x----x
130
+ // t= 0.25 0.5 0.75 1
131
+ // x-----o----------------x
132
+ // r= 0.25
133
+ // x-----o----------x
134
+ // r= 0.33 (0.25 / (1 - 0.25))
135
+ // x-----o----x
136
+ // r= 0.5 (0.25 / (1 - 0.5))
137
+
138
+ for (let i = 0; i < segmentCount - 1; i++) {
139
+ const tRelative = tIncrement / (1 - tIncrement * i);
140
+ const split = decasteljau(remainingCurve, tRelative);
141
+ segments.push(split.left);
142
+ remainingCurve = split.right;
143
+ } // last segment is just to the end from the last point
144
+
145
+
146
+ segments.push(remainingCurve);
147
+ return segments;
148
+ }
149
+ /**
150
+ * Convert command objects to arrays of points, run de Casteljau's algorithm on it
151
+ * to split into to the desired number of segments.
152
+ *
153
+ * @param {Object} commandStart The start command object
154
+ * @param {Object} commandEnd The end command object
155
+ * @param {Number} segmentCount The number of segments to create
156
+ * @return {Object[]} An array of commands representing the segments in sequence
157
+ */
158
+
159
+
160
+ function splitCurve(commandStart, commandEnd, segmentCount) {
161
+ 'worklet';
162
+
163
+ const points = [[commandStart.x, commandStart.y]];
164
+
165
+ if (commandEnd.x1 != null) {
166
+ points.push([commandEnd.x1, commandEnd.y1]);
167
+ }
168
+
169
+ if (commandEnd.x2 != null) {
170
+ points.push([commandEnd.x2, commandEnd.y2]);
171
+ }
172
+
173
+ points.push([commandEnd.x, commandEnd.y]);
174
+ return splitCurveAsPoints(points, segmentCount).map(pointsToCommand);
175
+ }
176
+ /**
177
+ * List of params for each command type in a path `d` attribute
178
+ */
179
+
180
+
181
+ const typeMap = {
182
+ M: ['x', 'y'],
183
+ L: ['x', 'y'],
184
+ H: ['x'],
185
+ V: ['y'],
186
+ C: ['x1', 'y1', 'x2', 'y2', 'x', 'y'],
187
+ S: ['x2', 'y2', 'x', 'y'],
188
+ Q: ['x1', 'y1', 'x', 'y'],
189
+ T: ['x', 'y'],
190
+ A: ['rx', 'ry', 'xAxisRotation', 'largeArcFlag', 'sweepFlag', 'x', 'y'],
191
+ Z: []
192
+ }; // Add lower case entries too matching uppercase (e.g. 'm' == 'M')
193
+
194
+ Object.keys(typeMap).forEach(key => {
195
+ typeMap[key.toLowerCase()] = typeMap[key];
196
+ });
197
+
198
+ function arrayOfLength(length, value) {
199
+ 'worklet';
200
+
201
+ const array = Array(length);
202
+
203
+ for (let i = 0; i < length; i++) {
204
+ array[i] = value;
205
+ }
206
+
207
+ return array;
208
+ }
209
+ /**
210
+ * Converts a command object to a string to be used in a `d` attribute
211
+ * @param {Object} command A command object
212
+ * @return {String} The string for the `d` attribute
213
+ */
214
+
215
+
216
+ function commandToString(command) {
217
+ 'worklet';
218
+
219
+ return `${command.type}${typeMap[command.type].map(p => command[p]).join(',')}`;
220
+ }
221
+ /**
222
+ * Converts command A to have the same type as command B.
223
+ *
224
+ * e.g., L0,5 -> C0,5,0,5,0,5
225
+ *
226
+ * Uses these rules:
227
+ * x1 <- x
228
+ * x2 <- x
229
+ * y1 <- y
230
+ * y2 <- y
231
+ * rx <- 0
232
+ * ry <- 0
233
+ * xAxisRotation <- read from B
234
+ * largeArcFlag <- read from B
235
+ * sweepflag <- read from B
236
+ *
237
+ * @param {Object} aCommand Command object from path `d` attribute
238
+ * @param {Object} bCommand Command object from path `d` attribute to match against
239
+ * @return {Object} aCommand converted to type of bCommand
240
+ */
241
+
242
+
243
+ function convertToSameType(aCommand, bCommand) {
244
+ 'worklet';
245
+
246
+ const conversionMap = {
247
+ x1: 'x',
248
+ y1: 'y',
249
+ x2: 'x',
250
+ y2: 'y'
251
+ };
252
+ const readFromBKeys = ['xAxisRotation', 'largeArcFlag', 'sweepFlag']; // convert (but ignore M types)
253
+
254
+ if (aCommand.type !== bCommand.type && bCommand.type.toUpperCase() !== 'M') {
255
+ const aConverted = {};
256
+ Object.keys(bCommand).forEach(bKey => {
257
+ const bValue = bCommand[bKey]; // first read from the A command
258
+
259
+ let aValue = aCommand[bKey]; // if it is one of these values, read from B no matter what
260
+
261
+ if (aValue === undefined) {
262
+ if (readFromBKeys.includes(bKey)) {
263
+ aValue = bValue;
264
+ } else {
265
+ // if it wasn't in the A command, see if an equivalent was
266
+ if (aValue === undefined && conversionMap[bKey]) {
267
+ aValue = aCommand[conversionMap[bKey]];
268
+ } // if it doesn't have a converted value, use 0
269
+
270
+
271
+ if (aValue === undefined) {
272
+ aValue = 0;
273
+ }
274
+ }
275
+ }
276
+
277
+ aConverted[bKey] = aValue;
278
+ }); // update the type to match B
279
+
280
+ aConverted.type = bCommand.type;
281
+ aCommand = aConverted;
282
+ }
283
+
284
+ return aCommand;
285
+ }
286
+ /**
287
+ * Interpolate between command objects commandStart and commandEnd segmentCount times.
288
+ * If the types are L, Q, or C then the curves are split as per de Casteljau's algorithm.
289
+ * Otherwise we just copy commandStart segmentCount - 1 times, finally ending with commandEnd.
290
+ *
291
+ * @param {Object} commandStart Command object at the beginning of the segment
292
+ * @param {Object} commandEnd Command object at the end of the segment
293
+ * @param {Number} segmentCount The number of segments to split this into. If only 1
294
+ * Then [commandEnd] is returned.
295
+ * @return {Object[]} Array of ~segmentCount command objects between commandStart and
296
+ * commandEnd. (Can be segmentCount+1 objects if commandStart is type M).
297
+ */
298
+
299
+
300
+ function splitSegment(commandStart, commandEnd, segmentCount) {
301
+ 'worklet';
302
+
303
+ let segments = []; // line, quadratic bezier, or cubic bezier
304
+
305
+ if (commandEnd.type === 'L' || commandEnd.type === 'Q' || commandEnd.type === 'C') {
306
+ segments = segments.concat(splitCurve(commandStart, commandEnd, segmentCount)); // general case - just copy the same point
307
+ } else {
308
+ const copyCommand = Object.assign({}, commandStart); // convert M to L
309
+
310
+ if (copyCommand.type === 'M') {
311
+ copyCommand.type = 'L';
312
+ }
313
+
314
+ segments = segments.concat(arrayOfLength(segmentCount - 1).map(() => copyCommand));
315
+ segments.push(commandEnd);
316
+ }
317
+
318
+ return segments;
319
+ }
320
+ /**
321
+ * Extends an array of commandsToExtend to the length of the referenceCommands by
322
+ * splitting segments until the number of commands match. Ensures all the actual
323
+ * points of commandsToExtend are in the extended array.
324
+ *
325
+ * @param {Object[]} commandsToExtend The command object array to extend
326
+ * @param {Object[]} referenceCommands The command object array to match in length
327
+ * @param {Function} excludeSegment a function that takes a start command object and
328
+ * end command object and returns true if the segment should be excluded from splitting.
329
+ * @return {Object[]} The extended commandsToExtend array
330
+ */
331
+
332
+
333
+ function extend(commandsToExtend, referenceCommands, excludeSegment) {
334
+ 'worklet'; // compute insertion points:
335
+ // number of segments in the path to extend
336
+
337
+ const numSegmentsToExtend = commandsToExtend.length - 1; // number of segments in the reference path.
338
+
339
+ const numReferenceSegments = referenceCommands.length - 1; // this value is always between [0, 1].
340
+
341
+ const segmentRatio = numSegmentsToExtend / numReferenceSegments; // create a map, mapping segments in referenceCommands to how many points
342
+ // should be added in that segment (should always be >= 1 since we need each
343
+ // point itself).
344
+ // 0 = segment 0-1, 1 = segment 1-2, n-1 = last vertex
345
+
346
+ const countPointsPerSegment = arrayOfLength(numReferenceSegments).reduce((accum, d, i) => {
347
+ let insertIndex = Math.floor(segmentRatio * i); // handle excluding segments
348
+
349
+ if (excludeSegment && insertIndex < commandsToExtend.length - 1 && excludeSegment(commandsToExtend[insertIndex], commandsToExtend[insertIndex + 1])) {
350
+ // set the insertIndex to the segment that this point should be added to:
351
+ // round the insertIndex essentially so we split half and half on
352
+ // neighbouring segments. hence the segmentRatio * i < 0.5
353
+ const addToPriorSegment = segmentRatio * i % 1 < 0.5; // only skip segment if we already have 1 point in it (can't entirely remove a segment)
354
+
355
+ if (accum[insertIndex]) {
356
+ // TODO - Note this is a naive algorithm that should work for most d3-area use cases
357
+ // but if two adjacent segments are supposed to be skipped, this will not perform as
358
+ // expected. Could be updated to search for nearest segment to place the point in, but
359
+ // will only do that if necessary.
360
+ // add to the prior segment
361
+ if (addToPriorSegment) {
362
+ if (insertIndex > 0) {
363
+ insertIndex -= 1; // not possible to add to previous so adding to next
364
+ } else if (insertIndex < commandsToExtend.length - 1) {
365
+ insertIndex += 1;
366
+ } // add to next segment
367
+
368
+ } else if (insertIndex < commandsToExtend.length - 1) {
369
+ insertIndex += 1; // not possible to add to next so adding to previous
370
+ } else if (insertIndex > 0) {
371
+ insertIndex -= 1;
372
+ }
373
+ }
374
+ }
375
+
376
+ accum[insertIndex] = (accum[insertIndex] || 0) + 1;
377
+ return accum;
378
+ }, []); // extend each segment to have the correct number of points for a smooth interpolation
379
+
380
+ const extended = countPointsPerSegment.reduce((extended, segmentCount, i) => {
381
+ // if last command, just add `segmentCount` number of times
382
+ if (i === commandsToExtend.length - 1) {
383
+ const lastCommandCopies = arrayOfLength(segmentCount, Object.assign({}, commandsToExtend[commandsToExtend.length - 1])); // convert M to L
384
+
385
+ if (lastCommandCopies[0].type === 'M') {
386
+ lastCommandCopies.forEach(d => {
387
+ d.type = 'L';
388
+ });
389
+ }
390
+
391
+ return extended.concat(lastCommandCopies);
392
+ } // otherwise, split the segment segmentCount times.
393
+
394
+
395
+ return extended.concat(splitSegment(commandsToExtend[i], commandsToExtend[i + 1], segmentCount));
396
+ }, []); // add in the very first point since splitSegment only adds in the ones after it
397
+
398
+ extended.unshift(commandsToExtend[0]);
399
+ return extended;
400
+ }
401
+ /**
402
+ * Takes a path `d` string and converts it into an array of command
403
+ * objects. Drops the `Z` character.
404
+ *
405
+ * @param {String|null} d A path `d` string
406
+ */
407
+
408
+
409
+ function pathCommandsFromString(d) {
410
+ 'worklet'; // split into valid tokens
411
+
412
+ const tokens = (d || '').match(/[MLCSTQAHVZmlcstqahv]|-?[\d.e+-]+/g) || [];
413
+ const commands = [];
414
+ let commandArgs;
415
+ let command; // iterate over each token, checking if we are at a new command
416
+ // by presence in the typeMap
417
+
418
+ for (let i = 0; i < tokens.length; ++i) {
419
+ commandArgs = typeMap[tokens[i]]; // new command found:
420
+
421
+ if (commandArgs) {
422
+ command = {
423
+ type: tokens[i]
424
+ }; // add each of the expected args for this command:
425
+
426
+ for (let a = 0; a < commandArgs.length; ++a) {
427
+ command[commandArgs[a]] = +tokens[i + a + 1];
428
+ } // need to increment our token index appropriately since
429
+ // we consumed token args
430
+
431
+
432
+ i += commandArgs.length;
433
+ commands.push(command);
434
+ }
435
+ }
436
+
437
+ return commands;
438
+ }
439
+ /**
440
+ * Interpolate from A to B by extending A and B during interpolation to have
441
+ * the same number of points. This allows for a smooth transition when they
442
+ * have a different number of points.
443
+ *
444
+ * Ignores the `Z` command in paths unless both A and B end with it.
445
+ *
446
+ * This function works directly with arrays of command objects instead of with
447
+ * path `d` strings (see interpolatePath for working with `d` strings).
448
+ *
449
+ * @param {Object[]} aCommandsInput Array of path commands
450
+ * @param {Object[]} bCommandsInput Array of path commands
451
+ * @param {Function} excludeSegment a function that takes a start command object and
452
+ * end command object and returns true if the segment should be excluded from splitting.
453
+ * @returns {Function} Interpolation function that maps t ([0, 1]) to an array of path commands.
454
+ */
455
+
456
+
457
+ function interpolatePathCommands(aCommandsInput, bCommandsInput, excludeSegment) {
458
+ 'worklet'; // make a copy so we don't mess with the input arrays
459
+
460
+ let aCommands = aCommandsInput == null ? [] : aCommandsInput.slice();
461
+ let bCommands = bCommandsInput == null ? [] : bCommandsInput.slice(); // both input sets are empty, so we don't interpolate
462
+
463
+ if (!aCommands.length && !bCommands.length) {
464
+ return function nullInterpolator() {
465
+ 'worklet';
466
+
467
+ return [];
468
+ };
469
+ } // do we add Z during interpolation? yes if both have it. (we'd expect both to have it or not)
470
+
471
+
472
+ const addZ = (aCommands.length === 0 || aCommands[aCommands.length - 1].type === 'Z') && (bCommands.length === 0 || bCommands[bCommands.length - 1].type === 'Z'); // we temporarily remove Z
473
+
474
+ if (aCommands.length > 0 && aCommands[aCommands.length - 1].type === 'Z') {
475
+ aCommands.pop();
476
+ }
477
+
478
+ if (bCommands.length > 0 && bCommands[bCommands.length - 1].type === 'Z') {
479
+ bCommands.pop();
480
+ } // if A is empty, treat it as if it used to contain just the first point
481
+ // of B. This makes it so the line extends out of from that first point.
482
+
483
+
484
+ if (!aCommands.length) {
485
+ aCommands.push(bCommands[0]); // otherwise if B is empty, treat it as if it contains the first point
486
+ // of A. This makes it so the line retracts into the first point.
487
+ } else if (!bCommands.length) {
488
+ bCommands.push(aCommands[0]);
489
+ } // extend to match equal size
490
+
491
+
492
+ const numPointsToExtend = Math.abs(bCommands.length - aCommands.length);
493
+
494
+ if (numPointsToExtend !== 0) {
495
+ // B has more points than A, so add points to A before interpolating
496
+ if (bCommands.length > aCommands.length) {
497
+ aCommands = extend(aCommands, bCommands, excludeSegment); // else if A has more points than B, add more points to B
498
+ } else if (bCommands.length < aCommands.length) {
499
+ bCommands = extend(bCommands, aCommands, excludeSegment);
500
+ }
501
+ } // commands have same length now.
502
+ // convert commands in A to the same type as those in B
503
+
504
+
505
+ aCommands = aCommands.map((aCommand, i) => convertToSameType(aCommand, bCommands[i])); // create mutable interpolated command objects
506
+
507
+ const interpolatedCommands = aCommands.map(aCommand => ({ ...aCommand
508
+ }));
509
+
510
+ if (addZ) {
511
+ interpolatedCommands.push({
512
+ type: 'Z'
513
+ });
514
+ aCommands.push({
515
+ type: 'Z'
516
+ }); // required for when returning at t == 0
517
+ }
518
+
519
+ return function pathCommandInterpolator(t) {
520
+ 'worklet'; // at 1 return the final value without the extensions used during interpolation
521
+
522
+ if (t === 1) {
523
+ return bCommandsInput == null ? [] : bCommandsInput;
524
+ } // work with aCommands directly since interpolatedCommands are mutated
525
+
526
+
527
+ if (t === 0) {
528
+ return aCommands;
529
+ } // interpolate the commands using the mutable interpolated command objs
530
+
531
+
532
+ for (let i = 0; i < interpolatedCommands.length; ++i) {
533
+ // if (interpolatedCommands[i].type === 'Z') continue;
534
+ const aCommand = aCommands[i];
535
+ const bCommand = bCommands[i];
536
+ const interpolatedCommand = interpolatedCommands[i];
537
+
538
+ for (let j = 0; j < typeMap[interpolatedCommand.type].length; j++) {
539
+ const arg = typeMap[interpolatedCommand.type][j];
540
+ interpolatedCommand[arg] = (1 - t) * aCommand[arg] + t * bCommand[arg]; // do not use floats for flags (#27), round to integer
541
+
542
+ if (arg === 'largeArcFlag' || arg === 'sweepFlag') {
543
+ interpolatedCommand[arg] = Math.round(interpolatedCommand[arg]);
544
+ }
545
+ }
546
+ }
547
+
548
+ return interpolatedCommands;
549
+ };
550
+ }
551
+ /**
552
+ * Interpolate from A to B by extending A and B during interpolation to have
553
+ * the same number of points. This allows for a smooth transition when they
554
+ * have a different number of points.
555
+ *
556
+ * Ignores the `Z` character in paths unless both A and B end with it.
557
+ *
558
+ * @param {String} a The `d` attribute for a path
559
+ * @param {String} b The `d` attribute for a path
560
+ * @param {Function} excludeSegment a function that takes a start command object and
561
+ * end command object and returns true if the segment should be excluded from splitting.
562
+ * @returns {Function} Interpolation function that maps t ([0, 1]) to a path `d` string.
563
+ */
564
+
565
+
566
+ function interpolatePath(a, b, excludeSegment) {
567
+ 'worklet';
568
+
569
+ let aCommands = pathCommandsFromString(a);
570
+ let bCommands = pathCommandsFromString(b);
571
+
572
+ if (!aCommands.length && !bCommands.length) {
573
+ return function nullInterpolator() {
574
+ 'worklet';
575
+
576
+ return '';
577
+ };
578
+ }
579
+
580
+ const commandInterpolator = interpolatePathCommands(aCommands, bCommands, excludeSegment);
581
+ return function pathStringInterpolator(t) {
582
+ 'worklet'; // at 1 return the final value without the extensions used during interpolation
583
+
584
+ if (t === 1) {
585
+ return b == null ? '' : b;
586
+ }
587
+
588
+ const interpolatedCommands = commandInterpolator(t); // convert to a string (fastest concat: https://jsperf.com/join-concat/150)
589
+
590
+ let interpolatedString = '';
591
+
592
+ for (let i = 0; i < interpolatedCommands.length; i++) {
593
+ const interpolatedCommand = interpolatedCommands[i];
594
+ interpolatedString += commandToString(interpolatedCommand);
595
+ }
596
+
597
+ return interpolatedString;
598
+ };
599
+ }
600
+ //# sourceMappingURL=interpolatePath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["interpolatePath.ts"],"names":["decasteljau","points","t","left","right","decasteljauRecurse","length","push","newPoints","Array","i","reverse","pointsToCommand","command","x2","y2","x1","y1","x","y","type","splitCurveAsPoints","segmentCount","segments","remainingCurve","tIncrement","tRelative","split","splitCurve","commandStart","commandEnd","map","typeMap","M","L","H","V","C","S","Q","T","A","Z","Object","keys","forEach","key","toLowerCase","arrayOfLength","value","array","commandToString","p","join","convertToSameType","aCommand","bCommand","conversionMap","readFromBKeys","toUpperCase","aConverted","bKey","bValue","aValue","undefined","includes","splitSegment","concat","copyCommand","assign","extend","commandsToExtend","referenceCommands","excludeSegment","numSegmentsToExtend","numReferenceSegments","segmentRatio","countPointsPerSegment","reduce","accum","d","insertIndex","Math","floor","addToPriorSegment","extended","lastCommandCopies","unshift","pathCommandsFromString","tokens","match","commands","commandArgs","a","interpolatePathCommands","aCommandsInput","bCommandsInput","aCommands","slice","bCommands","nullInterpolator","addZ","pop","numPointsToExtend","abs","interpolatedCommands","pathCommandInterpolator","interpolatedCommand","j","arg","round","interpolatePath","b","commandInterpolator","pathStringInterpolator","interpolatedString"],"mappings":";;;;;;;;;;AAAA;;AAEA;AACA;AACA;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CAAqBC,MAArB,EAA6BC,CAA7B,EAAgC;AAC9B;;AAEA,QAAMC,IAAI,GAAG,EAAb;AACA,QAAMC,KAAK,GAAG,EAAd;;AAEA,WAASC,kBAAT,CAA4BJ,MAA5B,EAAoCC,CAApC,EAAuC;AACrC;;AAEA,QAAID,MAAM,CAACK,MAAP,KAAkB,CAAtB,EAAyB;AACvBH,MAAAA,IAAI,CAACI,IAAL,CAAUN,MAAM,CAAC,CAAD,CAAhB;AACAG,MAAAA,KAAK,CAACG,IAAN,CAAWN,MAAM,CAAC,CAAD,CAAjB;AACD,KAHD,MAGO;AACL,YAAMO,SAAS,GAAGC,KAAK,CAACR,MAAM,CAACK,MAAP,GAAgB,CAAjB,CAAvB;;AAEA,WAAK,IAAII,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,SAAS,CAACF,MAA9B,EAAsCI,CAAC,EAAvC,EAA2C;AACzC,YAAIA,CAAC,KAAK,CAAV,EAAa;AACXP,UAAAA,IAAI,CAACI,IAAL,CAAUN,MAAM,CAAC,CAAD,CAAhB;AACD;;AACD,YAAIS,CAAC,KAAKF,SAAS,CAACF,MAAV,GAAmB,CAA7B,EAAgC;AAC9BF,UAAAA,KAAK,CAACG,IAAN,CAAWN,MAAM,CAACS,CAAC,GAAG,CAAL,CAAjB;AACD;;AAEDF,QAAAA,SAAS,CAACE,CAAD,CAAT,GAAe,CACb,CAAC,IAAIR,CAAL,IAAUD,MAAM,CAACS,CAAD,CAAN,CAAU,CAAV,CAAV,GAAyBR,CAAC,GAAGD,MAAM,CAACS,CAAC,GAAG,CAAL,CAAN,CAAc,CAAd,CAD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Aa;AACX,aAAO8G,CAAC,IAAI,IAAL,GAAY,EAAZ,GAAiBA,CAAxB;AACD;;AAED,UAAMP,oBAAoB,GAAGQ,mBAAmB,CAAC/G,CAAD,CAAhD,CARwC,CAUxC;;AACA,QAAIiH,kBAAkB,GAAG,EAAzB;;AACA,SAAK,IAAIzG,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG+F,oBAAoB,CAACnG,MAAzC,EAAiDI,CAAC,EAAlD,EAAsD;AACpD,YAAMiG,mBAAmB,GAAGF,oBAAoB,CAAC/F,CAAD,CAAhD;AACAyG,MAAAA,kBAAkB,IAAIhE,eAAe,CAACwD,mBAAD,CAArC;AACD;;AAED,WAAOQ,kBAAP;AACD,GAlBD;AAmBD","sourcesContent":["// @ts-nocheck\n\n/**\n * Reanimated compatible fork of https://github.com/pbeshai/d3-interpolate-path\n */\n\n//////////////////////////////////////////////////////////////////////////////////////////////////////\n\n/**\n * de Casteljau's algorithm for drawing and splitting bezier curves.\n * Inspired by https://pomax.github.io/bezierinfo/\n *\n * @param {Number[][]} points Array of [x,y] points: [start, control1, control2, ..., end]\n * The original segment to split.\n * @param {Number} t Where to split the curve (value between [0, 1])\n * @return {Object} An object { left, right } where left is the segment from 0..t and\n * right is the segment from t..1.\n */\nfunction decasteljau(points, t) {\n 'worklet';\n\n const left = [];\n const right = [];\n\n function decasteljauRecurse(points, t) {\n 'worklet';\n\n if (points.length === 1) {\n left.push(points[0]);\n right.push(points[0]);\n } else {\n const newPoints = Array(points.length - 1);\n\n for (let i = 0; i < newPoints.length; i++) {\n if (i === 0) {\n left.push(points[0]);\n }\n if (i === newPoints.length - 1) {\n right.push(points[i + 1]);\n }\n\n newPoints[i] = [\n (1 - t) * points[i][0] + t * points[i + 1][0],\n (1 - t) * points[i][1] + t * points[i + 1][1],\n ];\n }\n\n decasteljauRecurse(newPoints, t);\n }\n }\n\n if (points.length) {\n decasteljauRecurse(points, t);\n }\n\n return { left, right: right.reverse() };\n}\n\n/**\n * Convert segments represented as points back into a command object\n *\n * @param {Number[][]} points Array of [x,y] points: [start, control1, control2, ..., end]\n * Represents a segment\n * @return {Object} A command object representing the segment.\n */\nfunction pointsToCommand(points) {\n 'worklet';\n\n const command = {};\n\n if (points.length === 4) {\n command.x2 = points[2][0];\n command.y2 = points[2][1];\n }\n if (points.length >= 3) {\n command.x1 = points[1][0];\n command.y1 = points[1][1];\n }\n\n command.x = points[points.length - 1][0];\n command.y = points[points.length - 1][1];\n\n if (points.length === 4) {\n // start, control1, control2, end\n command.type = 'C';\n } else if (points.length === 3) {\n // start, control, end\n command.type = 'Q';\n } else {\n // start, end\n command.type = 'L';\n }\n\n return command;\n}\n\n/**\n * Runs de Casteljau's algorithm enough times to produce the desired number of segments.\n *\n * @param {Number[][]} points Array of [x,y] points for de Casteljau (the initial segment to split)\n * @param {Number} segmentCount Number of segments to split the original into\n * @return {Number[][][]} Array of segments\n */\nfunction splitCurveAsPoints(points, segmentCount) {\n 'worklet';\n\n segmentCount = segmentCount || 2;\n\n const segments = [];\n let remainingCurve = points;\n const tIncrement = 1 / segmentCount;\n\n // x-----x-----x-----x\n // t= 0.33 0.66 1\n // x-----o-----------x\n // r= 0.33\n // x-----o-----x\n // r= 0.5 (0.33 / (1 - 0.33)) === tIncrement / (1 - (tIncrement * (i - 1))\n\n // x-----x-----x-----x----x\n // t= 0.25 0.5 0.75 1\n // x-----o----------------x\n // r= 0.25\n // x-----o----------x\n // r= 0.33 (0.25 / (1 - 0.25))\n // x-----o----x\n // r= 0.5 (0.25 / (1 - 0.5))\n\n for (let i = 0; i < segmentCount - 1; i++) {\n const tRelative = tIncrement / (1 - tIncrement * i);\n const split = decasteljau(remainingCurve, tRelative);\n segments.push(split.left);\n remainingCurve = split.right;\n }\n\n // last segment is just to the end from the last point\n segments.push(remainingCurve);\n\n return segments;\n}\n\n/**\n * Convert command objects to arrays of points, run de Casteljau's algorithm on it\n * to split into to the desired number of segments.\n *\n * @param {Object} commandStart The start command object\n * @param {Object} commandEnd The end command object\n * @param {Number} segmentCount The number of segments to create\n * @return {Object[]} An array of commands representing the segments in sequence\n */\nexport function splitCurve(commandStart, commandEnd, segmentCount) {\n 'worklet';\n\n const points = [[commandStart.x, commandStart.y]];\n if (commandEnd.x1 != null) {\n points.push([commandEnd.x1, commandEnd.y1]);\n }\n if (commandEnd.x2 != null) {\n points.push([commandEnd.x2, commandEnd.y2]);\n }\n points.push([commandEnd.x, commandEnd.y]);\n\n return splitCurveAsPoints(points, segmentCount).map(pointsToCommand);\n}\n\n/**\n * List of params for each command type in a path `d` attribute\n */\nconst typeMap = {\n M: ['x', 'y'],\n L: ['x', 'y'],\n H: ['x'],\n V: ['y'],\n C: ['x1', 'y1', 'x2', 'y2', 'x', 'y'],\n S: ['x2', 'y2', 'x', 'y'],\n Q: ['x1', 'y1', 'x', 'y'],\n T: ['x', 'y'],\n A: ['rx', 'ry', 'xAxisRotation', 'largeArcFlag', 'sweepFlag', 'x', 'y'],\n Z: [],\n};\n\n// Add lower case entries too matching uppercase (e.g. 'm' == 'M')\nObject.keys(typeMap).forEach((key) => {\n typeMap[key.toLowerCase()] = typeMap[key];\n});\n\nfunction arrayOfLength(length, value) {\n 'worklet';\n\n const array = Array(length);\n for (let i = 0; i < length; i++) {\n array[i] = value;\n }\n\n return array;\n}\n\n/**\n * Converts a command object to a string to be used in a `d` attribute\n * @param {Object} command A command object\n * @return {String} The string for the `d` attribute\n */\nfunction commandToString(command) {\n 'worklet';\n\n return `${command.type}${typeMap[command.type]\n .map((p) => command[p])\n .join(',')}`;\n}\n\n/**\n * Converts command A to have the same type as command B.\n *\n * e.g., L0,5 -> C0,5,0,5,0,5\n *\n * Uses these rules:\n * x1 <- x\n * x2 <- x\n * y1 <- y\n * y2 <- y\n * rx <- 0\n * ry <- 0\n * xAxisRotation <- read from B\n * largeArcFlag <- read from B\n * sweepflag <- read from B\n *\n * @param {Object} aCommand Command object from path `d` attribute\n * @param {Object} bCommand Command object from path `d` attribute to match against\n * @return {Object} aCommand converted to type of bCommand\n */\nfunction convertToSameType(aCommand, bCommand) {\n 'worklet';\n\n const conversionMap = {\n x1: 'x',\n y1: 'y',\n x2: 'x',\n y2: 'y',\n };\n\n const readFromBKeys = ['xAxisRotation', 'largeArcFlag', 'sweepFlag'];\n\n // convert (but ignore M types)\n if (aCommand.type !== bCommand.type && bCommand.type.toUpperCase() !== 'M') {\n const aConverted = {};\n Object.keys(bCommand).forEach((bKey) => {\n const bValue = bCommand[bKey];\n // first read from the A command\n let aValue = aCommand[bKey];\n\n // if it is one of these values, read from B no matter what\n if (aValue === undefined) {\n if (readFromBKeys.includes(bKey)) {\n aValue = bValue;\n } else {\n // if it wasn't in the A command, see if an equivalent was\n if (aValue === undefined && conversionMap[bKey]) {\n aValue = aCommand[conversionMap[bKey]];\n }\n\n // if it doesn't have a converted value, use 0\n if (aValue === undefined) {\n aValue = 0;\n }\n }\n }\n\n aConverted[bKey] = aValue;\n });\n\n // update the type to match B\n aConverted.type = bCommand.type;\n aCommand = aConverted;\n }\n\n return aCommand;\n}\n\n/**\n * Interpolate between command objects commandStart and commandEnd segmentCount times.\n * If the types are L, Q, or C then the curves are split as per de Casteljau's algorithm.\n * Otherwise we just copy commandStart segmentCount - 1 times, finally ending with commandEnd.\n *\n * @param {Object} commandStart Command object at the beginning of the segment\n * @param {Object} commandEnd Command object at the end of the segment\n * @param {Number} segmentCount The number of segments to split this into. If only 1\n * Then [commandEnd] is returned.\n * @return {Object[]} Array of ~segmentCount command objects between commandStart and\n * commandEnd. (Can be segmentCount+1 objects if commandStart is type M).\n */\nfunction splitSegment(commandStart, commandEnd, segmentCount) {\n 'worklet';\n\n let segments = [];\n\n // line, quadratic bezier, or cubic bezier\n if (\n commandEnd.type === 'L' ||\n commandEnd.type === 'Q' ||\n commandEnd.type === 'C'\n ) {\n segments = segments.concat(\n splitCurve(commandStart, commandEnd, segmentCount)\n );\n\n // general case - just copy the same point\n } else {\n const copyCommand = Object.assign({}, commandStart);\n\n // convert M to L\n if (copyCommand.type === 'M') {\n copyCommand.type = 'L';\n }\n\n segments = segments.concat(\n arrayOfLength(segmentCount - 1).map(() => copyCommand)\n );\n segments.push(commandEnd);\n }\n\n return segments;\n}\n/**\n * Extends an array of commandsToExtend to the length of the referenceCommands by\n * splitting segments until the number of commands match. Ensures all the actual\n * points of commandsToExtend are in the extended array.\n *\n * @param {Object[]} commandsToExtend The command object array to extend\n * @param {Object[]} referenceCommands The command object array to match in length\n * @param {Function} excludeSegment a function that takes a start command object and\n * end command object and returns true if the segment should be excluded from splitting.\n * @return {Object[]} The extended commandsToExtend array\n */\nfunction extend(commandsToExtend, referenceCommands, excludeSegment) {\n 'worklet';\n\n // compute insertion points:\n // number of segments in the path to extend\n const numSegmentsToExtend = commandsToExtend.length - 1;\n\n // number of segments in the reference path.\n const numReferenceSegments = referenceCommands.length - 1;\n\n // this value is always between [0, 1].\n const segmentRatio = numSegmentsToExtend / numReferenceSegments;\n\n // create a map, mapping segments in referenceCommands to how many points\n // should be added in that segment (should always be >= 1 since we need each\n // point itself).\n // 0 = segment 0-1, 1 = segment 1-2, n-1 = last vertex\n const countPointsPerSegment = arrayOfLength(numReferenceSegments).reduce(\n (accum, d, i) => {\n let insertIndex = Math.floor(segmentRatio * i);\n\n // handle excluding segments\n if (\n excludeSegment &&\n insertIndex < commandsToExtend.length - 1 &&\n excludeSegment(\n commandsToExtend[insertIndex],\n commandsToExtend[insertIndex + 1]\n )\n ) {\n // set the insertIndex to the segment that this point should be added to:\n\n // round the insertIndex essentially so we split half and half on\n // neighbouring segments. hence the segmentRatio * i < 0.5\n const addToPriorSegment = (segmentRatio * i) % 1 < 0.5;\n\n // only skip segment if we already have 1 point in it (can't entirely remove a segment)\n if (accum[insertIndex]) {\n // TODO - Note this is a naive algorithm that should work for most d3-area use cases\n // but if two adjacent segments are supposed to be skipped, this will not perform as\n // expected. Could be updated to search for nearest segment to place the point in, but\n // will only do that if necessary.\n\n // add to the prior segment\n if (addToPriorSegment) {\n if (insertIndex > 0) {\n insertIndex -= 1;\n\n // not possible to add to previous so adding to next\n } else if (insertIndex < commandsToExtend.length - 1) {\n insertIndex += 1;\n }\n // add to next segment\n } else if (insertIndex < commandsToExtend.length - 1) {\n insertIndex += 1;\n\n // not possible to add to next so adding to previous\n } else if (insertIndex > 0) {\n insertIndex -= 1;\n }\n }\n }\n\n accum[insertIndex] = (accum[insertIndex] || 0) + 1;\n\n return accum;\n },\n []\n );\n\n // extend each segment to have the correct number of points for a smooth interpolation\n const extended = countPointsPerSegment.reduce((extended, segmentCount, i) => {\n // if last command, just add `segmentCount` number of times\n if (i === commandsToExtend.length - 1) {\n const lastCommandCopies = arrayOfLength(\n segmentCount,\n Object.assign({}, commandsToExtend[commandsToExtend.length - 1])\n );\n\n // convert M to L\n if (lastCommandCopies[0].type === 'M') {\n lastCommandCopies.forEach((d) => {\n d.type = 'L';\n });\n }\n return extended.concat(lastCommandCopies);\n }\n\n // otherwise, split the segment segmentCount times.\n return extended.concat(\n splitSegment(commandsToExtend[i], commandsToExtend[i + 1], segmentCount)\n );\n }, []);\n\n // add in the very first point since splitSegment only adds in the ones after it\n extended.unshift(commandsToExtend[0]);\n\n return extended;\n}\n\n/**\n * Takes a path `d` string and converts it into an array of command\n * objects. Drops the `Z` character.\n *\n * @param {String|null} d A path `d` string\n */\nexport function pathCommandsFromString(d) {\n 'worklet';\n\n // split into valid tokens\n const tokens = (d || '').match(/[MLCSTQAHVZmlcstqahv]|-?[\\d.e+-]+/g) || [];\n const commands = [];\n let commandArgs;\n let command;\n\n // iterate over each token, checking if we are at a new command\n // by presence in the typeMap\n for (let i = 0; i < tokens.length; ++i) {\n commandArgs = typeMap[tokens[i]];\n\n // new command found:\n if (commandArgs) {\n command = {\n type: tokens[i],\n };\n\n // add each of the expected args for this command:\n for (let a = 0; a < commandArgs.length; ++a) {\n command[commandArgs[a]] = +tokens[i + a + 1];\n }\n\n // need to increment our token index appropriately since\n // we consumed token args\n i += commandArgs.length;\n\n commands.push(command);\n }\n }\n return commands;\n}\n\n/**\n * Interpolate from A to B by extending A and B during interpolation to have\n * the same number of points. This allows for a smooth transition when they\n * have a different number of points.\n *\n * Ignores the `Z` command in paths unless both A and B end with it.\n *\n * This function works directly with arrays of command objects instead of with\n * path `d` strings (see interpolatePath for working with `d` strings).\n *\n * @param {Object[]} aCommandsInput Array of path commands\n * @param {Object[]} bCommandsInput Array of path commands\n * @param {Function} excludeSegment a function that takes a start command object and\n * end command object and returns true if the segment should be excluded from splitting.\n * @returns {Function} Interpolation function that maps t ([0, 1]) to an array of path commands.\n */\nexport function interpolatePathCommands(\n aCommandsInput,\n bCommandsInput,\n excludeSegment\n) {\n 'worklet';\n\n // make a copy so we don't mess with the input arrays\n let aCommands = aCommandsInput == null ? [] : aCommandsInput.slice();\n let bCommands = bCommandsInput == null ? [] : bCommandsInput.slice();\n\n // both input sets are empty, so we don't interpolate\n if (!aCommands.length && !bCommands.length) {\n return function nullInterpolator() {\n 'worklet';\n\n return [];\n };\n }\n\n // do we add Z during interpolation? yes if both have it. (we'd expect both to have it or not)\n const addZ =\n (aCommands.length === 0 || aCommands[aCommands.length - 1].type === 'Z') &&\n (bCommands.length === 0 || bCommands[bCommands.length - 1].type === 'Z');\n\n // we temporarily remove Z\n if (aCommands.length > 0 && aCommands[aCommands.length - 1].type === 'Z') {\n aCommands.pop();\n }\n if (bCommands.length > 0 && bCommands[bCommands.length - 1].type === 'Z') {\n bCommands.pop();\n }\n\n // if A is empty, treat it as if it used to contain just the first point\n // of B. This makes it so the line extends out of from that first point.\n if (!aCommands.length) {\n aCommands.push(bCommands[0]);\n\n // otherwise if B is empty, treat it as if it contains the first point\n // of A. This makes it so the line retracts into the first point.\n } else if (!bCommands.length) {\n bCommands.push(aCommands[0]);\n }\n\n // extend to match equal size\n const numPointsToExtend = Math.abs(bCommands.length - aCommands.length);\n\n if (numPointsToExtend !== 0) {\n // B has more points than A, so add points to A before interpolating\n if (bCommands.length > aCommands.length) {\n aCommands = extend(aCommands, bCommands, excludeSegment);\n\n // else if A has more points than B, add more points to B\n } else if (bCommands.length < aCommands.length) {\n bCommands = extend(bCommands, aCommands, excludeSegment);\n }\n }\n\n // commands have same length now.\n // convert commands in A to the same type as those in B\n aCommands = aCommands.map((aCommand, i) =>\n convertToSameType(aCommand, bCommands[i])\n );\n\n // create mutable interpolated command objects\n const interpolatedCommands = aCommands.map((aCommand) => ({ ...aCommand }));\n\n if (addZ) {\n interpolatedCommands.push({ type: 'Z' });\n aCommands.push({ type: 'Z' }); // required for when returning at t == 0\n }\n\n return function pathCommandInterpolator(t) {\n 'worklet';\n\n // at 1 return the final value without the extensions used during interpolation\n if (t === 1) {\n return bCommandsInput == null ? [] : bCommandsInput;\n }\n\n // work with aCommands directly since interpolatedCommands are mutated\n if (t === 0) {\n return aCommands;\n }\n\n // interpolate the commands using the mutable interpolated command objs\n for (let i = 0; i < interpolatedCommands.length; ++i) {\n // if (interpolatedCommands[i].type === 'Z') continue;\n\n const aCommand = aCommands[i];\n const bCommand = bCommands[i];\n const interpolatedCommand = interpolatedCommands[i];\n for (let j = 0; j < typeMap[interpolatedCommand.type].length; j++) {\n const arg = typeMap[interpolatedCommand.type][j];\n interpolatedCommand[arg] = (1 - t) * aCommand[arg] + t * bCommand[arg];\n\n // do not use floats for flags (#27), round to integer\n if (arg === 'largeArcFlag' || arg === 'sweepFlag') {\n interpolatedCommand[arg] = Math.round(interpolatedCommand[arg]);\n }\n }\n }\n\n return interpolatedCommands;\n };\n}\n\n/**\n * Interpolate from A to B by extending A and B during interpolation to have\n * the same number of points. This allows for a smooth transition when they\n * have a different number of points.\n *\n * Ignores the `Z` character in paths unless both A and B end with it.\n *\n * @param {String} a The `d` attribute for a path\n * @param {String} b The `d` attribute for a path\n * @param {Function} excludeSegment a function that takes a start command object and\n * end command object and returns true if the segment should be excluded from splitting.\n * @returns {Function} Interpolation function that maps t ([0, 1]) to a path `d` string.\n */\nexport default function interpolatePath(a, b, excludeSegment) {\n 'worklet';\n\n let aCommands = pathCommandsFromString(a);\n let bCommands = pathCommandsFromString(b);\n\n if (!aCommands.length && !bCommands.length) {\n return function nullInterpolator() {\n 'worklet';\n\n return '';\n };\n }\n\n const commandInterpolator = interpolatePathCommands(\n aCommands,\n bCommands,\n excludeSegment\n );\n\n return function pathStringInterpolator(t) {\n 'worklet';\n\n // at 1 return the final value without the extensions used during interpolation\n if (t === 1) {\n return b == null ? '' : b;\n }\n\n const interpolatedCommands = commandInterpolator(t);\n\n // convert to a string (fastest concat: https://jsperf.com/join-concat/150)\n let interpolatedString = '';\n for (let i = 0; i < interpolatedCommands.length; i++) {\n const interpolatedCommand = interpolatedCommands[i];\n interpolatedString += commandToString(interpolatedCommand);\n }\n\n return interpolatedString;\n };\n}\n"]}