@remotion/paths 4.0.83 → 4.0.84

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.
@@ -0,0 +1,8 @@
1
+ import type { Constructed } from './helpers/construct';
2
+ type InstructionAtLength = {
3
+ index: number;
4
+ lengthIntoInstruction: number;
5
+ };
6
+ export declare const getInstructionIndexAtLengthFromConstructed: (constructed: Constructed, fractionLength: number) => InstructionAtLength;
7
+ export declare const getInstructionIndexAtLength: (path: string, length: number) => InstructionAtLength;
8
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInstructionIndexAtLength = exports.getInstructionIndexAtLengthFromConstructed = void 0;
4
+ const construct_1 = require("./helpers/construct");
5
+ const getInstructionIndexAtLengthFromConstructed = (constructed, fractionLength) => {
6
+ if (fractionLength < 0) {
7
+ throw new Error('Length less than 0 was passed');
8
+ }
9
+ if (fractionLength > constructed.totalLength) {
10
+ fractionLength = constructed.totalLength;
11
+ }
12
+ let index = constructed.partialLengths.length - 1;
13
+ while (constructed.partialLengths[index] >= fractionLength && index > 0) {
14
+ index--;
15
+ }
16
+ return {
17
+ lengthIntoInstruction: fractionLength - constructed.partialLengths[index],
18
+ index,
19
+ };
20
+ };
21
+ exports.getInstructionIndexAtLengthFromConstructed = getInstructionIndexAtLengthFromConstructed;
22
+ const getInstructionIndexAtLength = (path, length) => {
23
+ const constructed = (0, construct_1.construct)(path);
24
+ if (length > constructed.totalLength) {
25
+ throw new Error(`A length of ${length} was passed to getInstructionIndexAtLength() but the total length of the path is only ${constructed.totalLength}`);
26
+ }
27
+ return (0, exports.getInstructionIndexAtLengthFromConstructed)(constructed, length);
28
+ };
29
+ exports.getInstructionIndexAtLength = getInstructionIndexAtLength;
@@ -10,6 +10,6 @@ const construct_1 = require("./helpers/construct");
10
10
  */
11
11
  const getLength = (path) => {
12
12
  const constructucted = (0, construct_1.construct)(path);
13
- return constructucted.length;
13
+ return constructucted.totalLength;
14
14
  };
15
15
  exports.getLength = getLength;
@@ -0,0 +1,8 @@
1
+ import type { Constructed } from './helpers/construct';
2
+ type SegmentAtLength = {
3
+ index: number;
4
+ fraction: number;
5
+ };
6
+ export declare const getInstructionIndexAtLengthFromConstructed: (constructed: Constructed, fractionLength: number) => SegmentAtLength;
7
+ export declare const getInstructionIndexAtLength: (path: string, length: number) => SegmentAtLength;
8
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInstructionIndexAtLength = exports.getInstructionIndexAtLengthFromConstructed = void 0;
4
+ const construct_1 = require("./helpers/construct");
5
+ const getInstructionIndexAtLengthFromConstructed = (constructed, fractionLength) => {
6
+ if (fractionLength < 0) {
7
+ fractionLength = 0;
8
+ }
9
+ else if (fractionLength > constructed.length) {
10
+ fractionLength = constructed.length;
11
+ }
12
+ let index = constructed.partialLengths.length - 1;
13
+ while (constructed.partialLengths[index] >= fractionLength && index > 0) {
14
+ index--;
15
+ }
16
+ index++;
17
+ return {
18
+ fraction: fractionLength - constructed.partialLengths[index - 1],
19
+ index,
20
+ };
21
+ };
22
+ exports.getInstructionIndexAtLengthFromConstructed = getInstructionIndexAtLengthFromConstructed;
23
+ const getInstructionIndexAtLength = (path, length) => {
24
+ const constructed = (0, construct_1.construct)(path);
25
+ return (0, exports.getInstructionIndexAtLengthFromConstructed)(constructed, length);
26
+ };
27
+ exports.getInstructionIndexAtLength = getInstructionIndexAtLength;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPointAtLength = void 0;
4
+ const get_instruction_index_at_length_1 = require("./get-instruction-index-at-length");
4
5
  const construct_1 = require("./helpers/construct");
5
- const get_part_at_length_1 = require("./helpers/get-part-at-length");
6
6
  /**
7
7
  * @description Gets the coordinates of a point which is on an SVG path.
8
8
  * @param {string} path A valid SVG path
@@ -11,13 +11,13 @@ const get_part_at_length_1 = require("./helpers/get-part-at-length");
11
11
  */
12
12
  const getPointAtLength = (path, length) => {
13
13
  const constructed = (0, construct_1.construct)(path);
14
- const fractionPart = (0, get_part_at_length_1.getPartAtLength)(path, length);
15
- const functionAtPart = constructed.functions[fractionPart.i];
14
+ const fractionPart = (0, get_instruction_index_at_length_1.getInstructionIndexAtLengthFromConstructed)(constructed, length);
15
+ const functionAtPart = constructed.functions[fractionPart.index + 1];
16
16
  if (functionAtPart) {
17
- return functionAtPart.getPointAtLength(fractionPart.fraction);
17
+ return functionAtPart.getPointAtLength(fractionPart.lengthIntoInstruction);
18
18
  }
19
- if (constructed.initial_point) {
20
- return constructed.initial_point;
19
+ if (constructed.initialPoint) {
20
+ return constructed.initialPoint;
21
21
  }
22
22
  throw new Error('Wrong function at this part.');
23
23
  };
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTangentAtLength = void 0;
4
+ const get_instruction_index_at_length_1 = require("./get-instruction-index-at-length");
4
5
  const construct_1 = require("./helpers/construct");
5
- const get_part_at_length_1 = require("./helpers/get-part-at-length");
6
6
  /**
7
7
  * @description Gets tangent values x and y of a point which is on an SVG path
8
8
  * @param {string} path A valid SVG path
@@ -11,12 +11,12 @@ const get_part_at_length_1 = require("./helpers/get-part-at-length");
11
11
  */
12
12
  const getTangentAtLength = (path, length) => {
13
13
  const constructed = (0, construct_1.construct)(path);
14
- const fractionPart = (0, get_part_at_length_1.getPartAtLength)(path, length);
15
- const functionAtPart = constructed.functions[fractionPart.i];
14
+ const fractionPart = (0, get_instruction_index_at_length_1.getInstructionIndexAtLengthFromConstructed)(constructed, length);
15
+ const functionAtPart = constructed.functions[fractionPart.index + 1];
16
16
  if (functionAtPart) {
17
- return functionAtPart.getTangentAtLength(fractionPart.fraction);
17
+ return functionAtPart.getTangentAtLength(fractionPart.lengthIntoInstruction);
18
18
  }
19
- if (constructed.initial_point) {
19
+ if (constructed.initialPoint) {
20
20
  return { x: 0, y: 0 };
21
21
  }
22
22
  throw new Error('Wrong function at this part.');
@@ -165,9 +165,6 @@ const makeArc = ({ x0, y0, rx, ry, xAxisRotate, LargeArcFlag, SweepFlag, x1, y1,
165
165
  });
166
166
  });
167
167
  const length = lengthProperties.arcLength;
168
- const getTotalLength = () => {
169
- return length;
170
- };
171
168
  const getPointAtLength = (fractionLength) => {
172
169
  if (fractionLength < 0) {
173
170
  fractionLength = 0;
@@ -187,40 +184,41 @@ const makeArc = ({ x0, y0, rx, ry, xAxisRotate, LargeArcFlag, SweepFlag, x1, y1,
187
184
  });
188
185
  return { x: position.x, y: position.y };
189
186
  };
190
- const getTangentAtLength = (fractionLength) => {
191
- if (fractionLength < 0) {
192
- fractionLength = 0;
193
- }
194
- else if (fractionLength > length) {
195
- fractionLength = length;
196
- }
197
- const point_dist = 0.05; // needs testing
198
- const p1 = getPointAtLength(fractionLength);
199
- let p2;
200
- if (fractionLength < 0) {
201
- fractionLength = 0;
202
- }
203
- else if (fractionLength > length) {
204
- fractionLength = length;
205
- }
206
- if (fractionLength < length - point_dist) {
207
- p2 = getPointAtLength(fractionLength + point_dist);
208
- }
209
- else {
210
- p2 = getPointAtLength(fractionLength - point_dist);
211
- }
212
- const xDist = p2.x - p1.x;
213
- const yDist = p2.y - p1.y;
214
- const dist = Math.sqrt(xDist * xDist + yDist * yDist);
215
- if (fractionLength < length - point_dist) {
216
- return { x: -xDist / dist, y: -yDist / dist };
217
- }
218
- return { x: xDist / dist, y: yDist / dist };
219
- };
220
187
  return {
221
188
  getPointAtLength,
222
- getTangentAtLength,
223
- getTotalLength,
189
+ getTangentAtLength: (fractionLength) => {
190
+ if (fractionLength < 0) {
191
+ fractionLength = 0;
192
+ }
193
+ else if (fractionLength > length) {
194
+ fractionLength = length;
195
+ }
196
+ const point_dist = 0.05; // needs testing
197
+ const p1 = getPointAtLength(fractionLength);
198
+ let p2;
199
+ if (fractionLength < 0) {
200
+ fractionLength = 0;
201
+ }
202
+ else if (fractionLength > length) {
203
+ fractionLength = length;
204
+ }
205
+ if (fractionLength < length - point_dist) {
206
+ p2 = getPointAtLength(fractionLength + point_dist);
207
+ }
208
+ else {
209
+ p2 = getPointAtLength(fractionLength - point_dist);
210
+ }
211
+ const xDist = p2.x - p1.x;
212
+ const yDist = p2.y - p1.y;
213
+ const dist = Math.sqrt(xDist * xDist + yDist * yDist);
214
+ if (fractionLength < length - point_dist) {
215
+ return { x: -xDist / dist, y: -yDist / dist };
216
+ }
217
+ return { x: xDist / dist, y: yDist / dist };
218
+ },
219
+ getTotalLength: () => {
220
+ return length;
221
+ },
224
222
  type: 'arc',
225
223
  };
226
224
  };
@@ -1,15 +1,10 @@
1
1
  import type { Instruction, Point, Properties } from './types';
2
- export declare const constructFromInstructions: (instructions: Instruction[]) => {
2
+ export type Constructed = {
3
3
  segments: Instruction[][];
4
- initial_point: Point | null;
5
- length: number;
6
- partial_lengths: number[];
7
- functions: (Properties | null)[];
8
- };
9
- export declare const construct: (string: string) => {
10
- segments: Instruction[][];
11
- initial_point: Point | null;
12
- length: number;
13
- partial_lengths: number[];
4
+ initialPoint: Point | null;
5
+ totalLength: number;
6
+ partialLengths: number[];
14
7
  functions: (Properties | null)[];
15
8
  };
9
+ export declare const constructFromInstructions: (instructions: Instruction[]) => Constructed;
10
+ export declare const construct: (string: string) => Constructed;
@@ -7,10 +7,10 @@ const arc_1 = require("./arc");
7
7
  const bezier_1 = require("./bezier");
8
8
  const linear_1 = require("./linear");
9
9
  const constructFromInstructions = (instructions) => {
10
- let length = 0;
11
- const partial_lengths = [];
10
+ let totalLength = 0;
11
+ const partialLengths = [];
12
12
  const functions = [];
13
- let initial_point = null;
13
+ let initialPoint = null;
14
14
  let cur = [0, 0];
15
15
  let prev_point = [0, 0];
16
16
  let curve;
@@ -30,18 +30,18 @@ const constructFromInstructions = (instructions) => {
30
30
  segments.push([instruction]);
31
31
  functions.push(null);
32
32
  if (i === 0) {
33
- initial_point = { x: instruction.x, y: instruction.y };
33
+ initialPoint = { x: instruction.x, y: instruction.y };
34
34
  }
35
35
  }
36
- else if (instruction.type === 'm') {
36
+ if (instruction.type === 'm') {
37
37
  cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
38
38
  ringStart = [cur[0], cur[1]];
39
39
  segments.push([{ type: 'M', x: cur[0], y: cur[1] }]);
40
40
  functions.push(null);
41
41
  // lineTo
42
42
  }
43
- else if (instruction.type === 'L') {
44
- length += Math.sqrt((cur[0] - instruction.x) ** 2 + (cur[1] - instruction.y) ** 2);
43
+ if (instruction.type === 'L') {
44
+ totalLength += Math.sqrt((cur[0] - instruction.x) ** 2 + (cur[1] - instruction.y) ** 2);
45
45
  functions.push((0, linear_1.makeLinearPosition)({
46
46
  x0: cur[0],
47
47
  x1: instruction.x,
@@ -50,8 +50,8 @@ const constructFromInstructions = (instructions) => {
50
50
  }));
51
51
  cur = [instruction.x, instruction.y];
52
52
  }
53
- else if (instruction.type === 'l') {
54
- length += Math.sqrt(instruction.dx ** 2 + instruction.dy ** 2);
53
+ if (instruction.type === 'l') {
54
+ totalLength += Math.sqrt(instruction.dx ** 2 + instruction.dy ** 2);
55
55
  functions.push((0, linear_1.makeLinearPosition)({
56
56
  x0: cur[0],
57
57
  x1: instruction.dx + cur[0],
@@ -60,8 +60,8 @@ const constructFromInstructions = (instructions) => {
60
60
  }));
61
61
  cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
62
62
  }
63
- else if (instruction.type === 'H') {
64
- length += Math.abs(cur[0] - instruction.x);
63
+ if (instruction.type === 'H') {
64
+ totalLength += Math.abs(cur[0] - instruction.x);
65
65
  functions.push((0, linear_1.makeLinearPosition)({
66
66
  x0: cur[0],
67
67
  x1: instruction.x,
@@ -70,8 +70,8 @@ const constructFromInstructions = (instructions) => {
70
70
  }));
71
71
  cur[0] = instruction.x;
72
72
  }
73
- else if (instruction.type === 'h') {
74
- length += Math.abs(instruction.dx);
73
+ if (instruction.type === 'h') {
74
+ totalLength += Math.abs(instruction.dx);
75
75
  functions.push((0, linear_1.makeLinearPosition)({
76
76
  x0: cur[0],
77
77
  x1: cur[0] + instruction.dx,
@@ -81,7 +81,7 @@ const constructFromInstructions = (instructions) => {
81
81
  cur[0] = instruction.dx + cur[0];
82
82
  }
83
83
  else if (instruction.type === 'V') {
84
- length += Math.abs(cur[1] - instruction.y);
84
+ totalLength += Math.abs(cur[1] - instruction.y);
85
85
  functions.push((0, linear_1.makeLinearPosition)({
86
86
  x0: cur[0],
87
87
  x1: cur[0],
@@ -90,8 +90,8 @@ const constructFromInstructions = (instructions) => {
90
90
  }));
91
91
  cur[1] = instruction.y;
92
92
  }
93
- else if (instruction.type === 'v') {
94
- length += Math.abs(instruction.dy);
93
+ if (instruction.type === 'v') {
94
+ totalLength += Math.abs(instruction.dy);
95
95
  functions.push((0, linear_1.makeLinearPosition)({
96
96
  x0: cur[0],
97
97
  x1: cur[0],
@@ -102,7 +102,7 @@ const constructFromInstructions = (instructions) => {
102
102
  // Close path
103
103
  }
104
104
  else if (instruction.type === 'Z') {
105
- length += Math.sqrt((ringStart[0] - cur[0]) ** 2 + (ringStart[1] - cur[1]) ** 2);
105
+ totalLength += Math.sqrt((ringStart[0] - cur[0]) ** 2 + (ringStart[1] - cur[1]) ** 2);
106
106
  functions.push((0, linear_1.makeLinearPosition)({
107
107
  x0: cur[0],
108
108
  x1: ringStart[0],
@@ -112,7 +112,7 @@ const constructFromInstructions = (instructions) => {
112
112
  cur = [ringStart[0], ringStart[1]];
113
113
  // Cubic Bezier curves
114
114
  }
115
- else if (instruction.type === 'C') {
115
+ if (instruction.type === 'C') {
116
116
  curve = (0, bezier_1.makeCubic)({
117
117
  startX: cur[0],
118
118
  startY: cur[1],
@@ -123,7 +123,7 @@ const constructFromInstructions = (instructions) => {
123
123
  x: instruction.x,
124
124
  y: instruction.y,
125
125
  });
126
- length += curve.getTotalLength();
126
+ totalLength += curve.getTotalLength();
127
127
  cur = [instruction.x, instruction.y];
128
128
  functions.push(curve);
129
129
  }
@@ -139,7 +139,7 @@ const constructFromInstructions = (instructions) => {
139
139
  y: cur[1] + instruction.dy,
140
140
  });
141
141
  if (curve.getTotalLength() > 0) {
142
- length += curve.getTotalLength();
142
+ totalLength += curve.getTotalLength();
143
143
  functions.push(curve);
144
144
  cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
145
145
  }
@@ -147,7 +147,7 @@ const constructFromInstructions = (instructions) => {
147
147
  functions.push((0, linear_1.makeLinearPosition)({ x0: cur[0], x1: cur[0], y0: cur[1], y1: cur[1] }));
148
148
  }
149
149
  }
150
- else if (instruction.type === 'S') {
150
+ if (instruction.type === 'S') {
151
151
  const prev = instructions[i - 1];
152
152
  const prevWasCurve = prev.type === 'C' ||
153
153
  prev.type === 'c' ||
@@ -181,12 +181,12 @@ const constructFromInstructions = (instructions) => {
181
181
  });
182
182
  }
183
183
  if (curve) {
184
- length += curve.getTotalLength();
184
+ totalLength += curve.getTotalLength();
185
185
  cur = [instruction.x, instruction.y];
186
186
  functions.push(curve);
187
187
  }
188
188
  }
189
- else if (instruction.type === 's') {
189
+ if (instruction.type === 's') {
190
190
  const prev = instructions[i - 1];
191
191
  const prevWasCurve = prev.type === 'C' ||
192
192
  prev.type === 'c' ||
@@ -221,13 +221,13 @@ const constructFromInstructions = (instructions) => {
221
221
  });
222
222
  }
223
223
  if (curve) {
224
- length += curve.getTotalLength();
224
+ totalLength += curve.getTotalLength();
225
225
  cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
226
226
  functions.push(curve);
227
227
  }
228
228
  }
229
229
  // Quadratic Bezier curves
230
- else if (instruction.type === 'Q') {
230
+ if (instruction.type === 'Q') {
231
231
  if (cur[0] === instruction.cpx && cur[1] === instruction.cpy) {
232
232
  const linearCurve = (0, linear_1.makeLinearPosition)({
233
233
  x0: instruction.cpx,
@@ -235,7 +235,7 @@ const constructFromInstructions = (instructions) => {
235
235
  y0: instruction.cpy,
236
236
  y1: instruction.y,
237
237
  });
238
- length += linearCurve.getTotalLength();
238
+ totalLength += linearCurve.getTotalLength();
239
239
  functions.push(linearCurve);
240
240
  }
241
241
  else {
@@ -247,13 +247,13 @@ const constructFromInstructions = (instructions) => {
247
247
  x: instruction.x,
248
248
  y: instruction.y,
249
249
  });
250
- length += curve.getTotalLength();
250
+ totalLength += curve.getTotalLength();
251
251
  functions.push(curve);
252
252
  }
253
253
  cur = [instruction.x, instruction.y];
254
254
  prev_point = [instruction.cpx, instruction.cpy];
255
255
  }
256
- else if (instruction.type === 'q') {
256
+ if (instruction.type === 'q') {
257
257
  if (instruction.cpdx === 0 && instruction.cpdy === 0) {
258
258
  const linearCurve = (0, linear_1.makeLinearPosition)({
259
259
  x0: cur[0] + instruction.cpdx,
@@ -261,7 +261,7 @@ const constructFromInstructions = (instructions) => {
261
261
  y0: cur[1] + instruction.dx,
262
262
  y1: cur[1] + instruction.dy,
263
263
  });
264
- length += linearCurve.getTotalLength();
264
+ totalLength += linearCurve.getTotalLength();
265
265
  functions.push(linearCurve);
266
266
  }
267
267
  else {
@@ -273,13 +273,13 @@ const constructFromInstructions = (instructions) => {
273
273
  x: cur[0] + instruction.dx,
274
274
  y: cur[1] + instruction.dy,
275
275
  });
276
- length += curve.getTotalLength();
276
+ totalLength += curve.getTotalLength();
277
277
  functions.push(curve);
278
278
  }
279
279
  prev_point = [cur[0] + instruction.cpdx, cur[1] + instruction.cpdy];
280
280
  cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
281
281
  }
282
- else if (instruction.type === 'T') {
282
+ if (instruction.type === 'T') {
283
283
  const prev = instructions[i - 1];
284
284
  const prevWasQ = prev.type === 'Q' ||
285
285
  prev.type === 'q' ||
@@ -295,7 +295,7 @@ const constructFromInstructions = (instructions) => {
295
295
  y: instruction.y,
296
296
  });
297
297
  functions.push(curve);
298
- length += curve.getTotalLength();
298
+ totalLength += curve.getTotalLength();
299
299
  }
300
300
  else {
301
301
  const linearCurve = (0, linear_1.makeLinearPosition)({
@@ -305,12 +305,12 @@ const constructFromInstructions = (instructions) => {
305
305
  y1: instruction.y,
306
306
  });
307
307
  functions.push(linearCurve);
308
- length += linearCurve.getTotalLength();
308
+ totalLength += linearCurve.getTotalLength();
309
309
  }
310
310
  prev_point = [2 * cur[0] - prev_point[0], 2 * cur[1] - prev_point[1]];
311
311
  cur = [instruction.x, instruction.y];
312
312
  }
313
- else if (instruction.type === 't') {
313
+ if (instruction.type === 't') {
314
314
  const prev = instructions[i - 1];
315
315
  const prevWasQ = prev.type === 'Q' ||
316
316
  prev.type === 'q' ||
@@ -325,7 +325,7 @@ const constructFromInstructions = (instructions) => {
325
325
  x: cur[0] + instruction.dx,
326
326
  y: cur[1] + instruction.dy,
327
327
  });
328
- length += curve.getTotalLength();
328
+ totalLength += curve.getTotalLength();
329
329
  functions.push(curve);
330
330
  }
331
331
  else {
@@ -335,13 +335,13 @@ const constructFromInstructions = (instructions) => {
335
335
  y0: cur[1],
336
336
  y1: cur[1] + instruction.dy,
337
337
  });
338
- length += linearCurve.getTotalLength();
338
+ totalLength += linearCurve.getTotalLength();
339
339
  functions.push(linearCurve);
340
340
  }
341
341
  prev_point = [2 * cur[0] - prev_point[0], 2 * cur[1] - prev_point[1]];
342
342
  cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
343
343
  }
344
- else if (instruction.type === 'A') {
344
+ if (instruction.type === 'A') {
345
345
  const arcCurve = (0, arc_1.makeArc)({
346
346
  x0: cur[0],
347
347
  y0: cur[1],
@@ -353,11 +353,11 @@ const constructFromInstructions = (instructions) => {
353
353
  x1: instruction.x,
354
354
  y1: instruction.y,
355
355
  });
356
- length += arcCurve.getTotalLength();
356
+ totalLength += arcCurve.getTotalLength();
357
357
  cur = [instruction.x, instruction.y];
358
358
  functions.push(arcCurve);
359
359
  }
360
- else if (instruction.type === 'a') {
360
+ if (instruction.type === 'a') {
361
361
  const arcCurve = (0, arc_1.makeArc)({
362
362
  x0: cur[0],
363
363
  y0: cur[1],
@@ -369,17 +369,17 @@ const constructFromInstructions = (instructions) => {
369
369
  x1: cur[0] + instruction.dx,
370
370
  y1: cur[1] + instruction.dy,
371
371
  });
372
- length += arcCurve.getTotalLength();
372
+ totalLength += arcCurve.getTotalLength();
373
373
  cur = [cur[0] + instruction.dx, cur[1] + instruction.dy];
374
374
  functions.push(arcCurve);
375
375
  }
376
- partial_lengths.push(length);
376
+ partialLengths.push(totalLength);
377
377
  }
378
378
  return {
379
379
  segments,
380
- initial_point,
381
- length,
382
- partial_lengths,
380
+ initialPoint,
381
+ totalLength,
382
+ partialLengths,
383
383
  functions,
384
384
  };
385
385
  };
@@ -2,24 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeLinearPosition = void 0;
4
4
  const makeLinearPosition = ({ x0, x1, y0, y1, }) => {
5
- const getTotalLength = () => {
6
- return Math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2);
7
- };
8
- const getPointAtLength = (pos) => {
9
- let fraction = pos / Math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2);
10
- fraction = Number.isNaN(fraction) ? 1 : fraction;
11
- const newDeltaX = (x1 - x0) * fraction;
12
- const newDeltaY = (y1 - y0) * fraction;
13
- return { x: x0 + newDeltaX, y: y0 + newDeltaY };
14
- };
15
- const getTangentAtLength = () => {
16
- const module = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
17
- return { x: (x1 - x0) / module, y: (y1 - y0) / module };
18
- };
19
5
  return {
20
- getTotalLength,
21
- getPointAtLength,
22
- getTangentAtLength,
6
+ getTotalLength: () => {
7
+ return Math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2);
8
+ },
9
+ getPointAtLength: (pos) => {
10
+ let fraction = pos / Math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2);
11
+ fraction = Number.isNaN(fraction) ? 1 : fraction;
12
+ const newDeltaX = (x1 - x0) * fraction;
13
+ const newDeltaY = (y1 - y0) * fraction;
14
+ return { x: x0 + newDeltaX, y: y0 + newDeltaY };
15
+ },
16
+ getTangentAtLength: () => {
17
+ const module = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
18
+ return { x: (x1 - x0) / module, y: (y1 - y0) / module };
19
+ },
23
20
  type: 'linear',
24
21
  };
25
22
  };
@@ -2,7 +2,7 @@ export interface Properties {
2
2
  getTotalLength(): number;
3
3
  getPointAtLength(pos: number): Point;
4
4
  getTangentAtLength(pos: number): Point;
5
- type: string;
5
+ type: 'linear' | 'cubic-bezier' | 'quadratic-bezier' | 'arc';
6
6
  }
7
7
  export interface Part {
8
8
  start: Point;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { evolvePath } from './evolve-path';
2
2
  export { extendViewBox } from './extend-viewbox';
3
3
  export { getBoundingBox } from './get-bounding-box';
4
+ export { getInstructionIndexAtLength } from './get-instruction-index-at-length';
4
5
  export { getLength } from './get-length';
5
6
  export { getPointAtLength } from './get-point-at-length';
6
7
  export { getSubpaths } from './get-subpaths';
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.warpPath = exports.translatePath = exports.serializeInstructions = exports.scalePath = exports.reversePath = exports.resetPath = exports.reduceInstructions = exports.parsePath = exports.normalizePath = exports.interpolatePath = exports.getTangentAtLength = exports.getSubpaths = exports.getPointAtLength = exports.getLength = exports.getBoundingBox = exports.extendViewBox = exports.evolvePath = void 0;
3
+ exports.warpPath = exports.translatePath = exports.serializeInstructions = exports.scalePath = exports.reversePath = exports.resetPath = exports.reduceInstructions = exports.parsePath = exports.normalizePath = exports.interpolatePath = exports.getTangentAtLength = exports.getSubpaths = exports.getPointAtLength = exports.getLength = exports.getInstructionIndexAtLength = exports.getBoundingBox = exports.extendViewBox = exports.evolvePath = void 0;
4
4
  var evolve_path_1 = require("./evolve-path");
5
5
  Object.defineProperty(exports, "evolvePath", { enumerable: true, get: function () { return evolve_path_1.evolvePath; } });
6
6
  var extend_viewbox_1 = require("./extend-viewbox");
7
7
  Object.defineProperty(exports, "extendViewBox", { enumerable: true, get: function () { return extend_viewbox_1.extendViewBox; } });
8
8
  var get_bounding_box_1 = require("./get-bounding-box");
9
9
  Object.defineProperty(exports, "getBoundingBox", { enumerable: true, get: function () { return get_bounding_box_1.getBoundingBox; } });
10
+ var get_instruction_index_at_length_1 = require("./get-instruction-index-at-length");
11
+ Object.defineProperty(exports, "getInstructionIndexAtLength", { enumerable: true, get: function () { return get_instruction_index_at_length_1.getInstructionIndexAtLength; } });
10
12
  var get_length_1 = require("./get-length");
11
13
  Object.defineProperty(exports, "getLength", { enumerable: true, get: function () { return get_length_1.getLength; } });
12
14
  var get_point_at_length_1 = require("./get-point-at-length");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/paths",
3
- "version": "4.0.83",
3
+ "version": "4.0.84",
4
4
  "description": "Utility functions for SVG paths",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -16,8 +16,8 @@
16
16
  "@jonny/eslint-config": "3.0.276",
17
17
  "@types/node": "18.14.6",
18
18
  "eslint": "8.42.0",
19
- "prettier": "3.0.2",
20
- "prettier-plugin-organize-imports": "^3.2.2",
19
+ "prettier": "3.1.1",
20
+ "prettier-plugin-organize-imports": "3.2.4",
21
21
  "vitest": "0.31.1"
22
22
  },
23
23
  "keywords": [