@remotion/paths 3.3.42 → 3.3.43

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.
@@ -1,2 +1,3 @@
1
- import type { BoundingBox } from './helpers/types';
1
+ import type { BoundingBox, ReducedInstruction } from './helpers/types';
2
2
  export declare const getBoundingBox: (d: string) => BoundingBox;
3
+ export declare const getBoundingBoxFromInstructions: (instructions: ReducedInstruction[]) => BoundingBox;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBoundingBox = void 0;
3
+ exports.getBoundingBoxFromInstructions = exports.getBoundingBox = void 0;
4
4
  const remove_a_s_t_curves_1 = require("./helpers/remove-a-s-t-curves");
5
5
  const normalize_path_1 = require("./normalize-path");
6
6
  const parse_path_1 = require("./parse-path");
@@ -68,15 +68,19 @@ function minmaxC(A) {
68
68
  return [min, max];
69
69
  }
70
70
  const getBoundingBox = (d) => {
71
+ const parsed = (0, parse_path_1.parsePath)(d);
72
+ const unarced = (0, remove_a_s_t_curves_1.removeATSHVInstructions)((0, normalize_path_1.normalizeInstructions)(parsed));
73
+ return (0, exports.getBoundingBoxFromInstructions)(unarced);
74
+ };
75
+ exports.getBoundingBox = getBoundingBox;
76
+ const getBoundingBoxFromInstructions = (instructions) => {
71
77
  let minX = Infinity;
72
78
  let minY = Infinity;
73
79
  let maxX = -Infinity;
74
80
  let maxY = -Infinity;
75
- const parsed = (0, parse_path_1.parsePath)((0, normalize_path_1.normalizePath)(d));
76
- const unarced = (0, remove_a_s_t_curves_1.removeATSHVInstructions)(parsed);
77
81
  let x = 0;
78
82
  let y = 0;
79
- for (const seg of unarced) {
83
+ for (const seg of instructions) {
80
84
  switch (seg.type) {
81
85
  case 'M':
82
86
  case 'L': {
@@ -143,4 +147,4 @@ const getBoundingBox = (d) => {
143
147
  }
144
148
  return { x1: minX, y1: minY, x2: maxX, y2: maxY };
145
149
  };
146
- exports.getBoundingBox = getBoundingBox;
150
+ exports.getBoundingBoxFromInstructions = getBoundingBoxFromInstructions;
package/dist/index.d.ts CHANGED
@@ -13,5 +13,7 @@ export { parsePath } from './parse-path';
13
13
  export { reduceInstructions } from './reduce-instructions';
14
14
  export { resetPath } from './reset-path';
15
15
  export { reversePath } from './reverse-path';
16
+ export { scalePath } from './scale-path';
16
17
  export { serializeInstructions } from './serialize-instructions';
17
18
  export { translatePath } from './translate-path';
19
+ export { warpPath, WarpPathFn } from './warp-path';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.translatePath = exports.serializeInstructions = exports.reversePath = exports.resetPath = exports.reduceInstructions = exports.parsePath = exports.normalizePath = exports.interpolatePath = exports.getTangentAtLength = exports.getSubpaths = exports.getPointAtLength = exports.getParts = 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.getParts = exports.getLength = 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");
@@ -29,7 +29,11 @@ var reset_path_1 = require("./reset-path");
29
29
  Object.defineProperty(exports, "resetPath", { enumerable: true, get: function () { return reset_path_1.resetPath; } });
30
30
  var reverse_path_1 = require("./reverse-path");
31
31
  Object.defineProperty(exports, "reversePath", { enumerable: true, get: function () { return reverse_path_1.reversePath; } });
32
+ var scale_path_1 = require("./scale-path");
33
+ Object.defineProperty(exports, "scalePath", { enumerable: true, get: function () { return scale_path_1.scalePath; } });
32
34
  var serialize_instructions_1 = require("./serialize-instructions");
33
35
  Object.defineProperty(exports, "serializeInstructions", { enumerable: true, get: function () { return serialize_instructions_1.serializeInstructions; } });
34
36
  var translate_path_1 = require("./translate-path");
35
37
  Object.defineProperty(exports, "translatePath", { enumerable: true, get: function () { return translate_path_1.translatePath; } });
38
+ var warp_path_1 = require("./warp-path");
39
+ Object.defineProperty(exports, "warpPath", { enumerable: true, get: function () { return warp_path_1.warpPath; } });
@@ -0,0 +1 @@
1
+ export declare const scalePath: (d: string, scaleX: number, scaleY: number) => string;
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scalePath = void 0;
4
+ const get_bounding_box_1 = require("./get-bounding-box");
5
+ const parse_path_1 = require("./parse-path");
6
+ const reduce_instructions_1 = require("./reduce-instructions");
7
+ const serialize_instructions_1 = require("./serialize-instructions");
8
+ const translate_path_1 = require("./translate-path");
9
+ const scalePath = (d, scaleX, scaleY) => {
10
+ const reduced = (0, reduce_instructions_1.reduceInstructions)((0, parse_path_1.parsePath)(d));
11
+ const bounded = (0, get_bounding_box_1.getBoundingBoxFromInstructions)(reduced);
12
+ const zeroed = (0, translate_path_1.translateSegments)(reduced, -bounded.x1, -bounded.y1);
13
+ const mapped = zeroed.map((instruction) => {
14
+ if (instruction.type === 'L') {
15
+ return {
16
+ type: 'L',
17
+ x: scaleX * instruction.x,
18
+ y: scaleY * instruction.y,
19
+ };
20
+ }
21
+ if (instruction.type === 'C') {
22
+ return {
23
+ type: 'C',
24
+ x: scaleX * instruction.x,
25
+ y: scaleY * instruction.y,
26
+ cp1x: scaleX * instruction.cp1x,
27
+ cp1y: scaleY * instruction.cp1y,
28
+ cp2x: scaleX * instruction.cp2x,
29
+ cp2y: scaleY * instruction.cp2y,
30
+ };
31
+ }
32
+ if (instruction.type === 'M') {
33
+ return {
34
+ type: 'M',
35
+ x: scaleX * instruction.x,
36
+ y: scaleY * instruction.y,
37
+ };
38
+ }
39
+ if (instruction.type === 'Q') {
40
+ return {
41
+ type: 'Q',
42
+ x: scaleX * instruction.x,
43
+ y: scaleY * instruction.y,
44
+ cpx: scaleX * instruction.cpx,
45
+ cpy: scaleY * instruction.cpy,
46
+ };
47
+ }
48
+ if (instruction.type === 'Z') {
49
+ return {
50
+ type: 'Z',
51
+ };
52
+ }
53
+ if (instruction.type === 'A') {
54
+ return {
55
+ type: 'A',
56
+ largeArcFlag: instruction.largeArcFlag,
57
+ rx: scaleX * instruction.rx,
58
+ ry: scaleY * instruction.ry,
59
+ sweepFlag: instruction.sweepFlag,
60
+ xAxisRotation: instruction.xAxisRotation,
61
+ x: scaleX * instruction.x,
62
+ y: scaleY * instruction.y,
63
+ };
64
+ }
65
+ if (instruction.type === 'H') {
66
+ return {
67
+ type: 'H',
68
+ x: scaleX * instruction.x,
69
+ };
70
+ }
71
+ if (instruction.type === 'S') {
72
+ return {
73
+ type: 'S',
74
+ cpx: scaleX * instruction.cpx,
75
+ cpy: scaleY * instruction.cpy,
76
+ x: scaleX * instruction.x,
77
+ y: scaleY * instruction.y,
78
+ };
79
+ }
80
+ if (instruction.type === 'T') {
81
+ return {
82
+ type: 'T',
83
+ x: scaleX * instruction.x,
84
+ y: scaleY * instruction.y,
85
+ };
86
+ }
87
+ if (instruction.type === 'V') {
88
+ return {
89
+ type: 'V',
90
+ y: scaleY * instruction.y,
91
+ };
92
+ }
93
+ if (instruction.type === 'a') {
94
+ return {
95
+ type: 'a',
96
+ dx: scaleX * instruction.dx,
97
+ dy: scaleY * instruction.dy,
98
+ largeArcFlag: instruction.largeArcFlag,
99
+ rx: scaleX * instruction.rx,
100
+ ry: scaleY * instruction.ry,
101
+ sweepFlag: instruction.sweepFlag,
102
+ xAxisRotation: instruction.xAxisRotation,
103
+ };
104
+ }
105
+ if (instruction.type === 'c') {
106
+ return {
107
+ type: 'c',
108
+ cp1dx: scaleX * instruction.cp1dx,
109
+ cp1dy: scaleY * instruction.cp1dy,
110
+ cp2dx: scaleX * instruction.cp2dx,
111
+ cp2dy: scaleY * instruction.cp2dy,
112
+ dx: scaleX * instruction.dx,
113
+ dy: scaleY * instruction.dy,
114
+ };
115
+ }
116
+ if (instruction.type === 'h') {
117
+ return {
118
+ type: 'h',
119
+ dx: scaleX * instruction.dx,
120
+ };
121
+ }
122
+ if (instruction.type === 'l') {
123
+ return {
124
+ type: 'l',
125
+ dx: scaleX * instruction.dx,
126
+ dy: scaleY * instruction.dy,
127
+ };
128
+ }
129
+ if (instruction.type === 'm') {
130
+ return {
131
+ type: 'm',
132
+ dx: scaleX * instruction.dx,
133
+ dy: scaleY * instruction.dy,
134
+ };
135
+ }
136
+ if (instruction.type === 'q') {
137
+ return {
138
+ type: 'q',
139
+ cpdx: scaleX * instruction.cpdx,
140
+ cpdy: scaleY * instruction.cpdy,
141
+ dx: scaleX * instruction.dx,
142
+ dy: scaleY * instruction.dy,
143
+ };
144
+ }
145
+ if (instruction.type === 's') {
146
+ return {
147
+ type: 's',
148
+ cpdx: scaleX * instruction.cpdx,
149
+ cpdy: scaleY * instruction.cpdy,
150
+ dx: scaleX * instruction.dx,
151
+ dy: scaleY * instruction.dy,
152
+ };
153
+ }
154
+ if (instruction.type === 't') {
155
+ return {
156
+ type: 't',
157
+ dx: scaleX * instruction.dx,
158
+ dy: scaleY * instruction.dy,
159
+ };
160
+ }
161
+ if (instruction.type === 'v') {
162
+ return {
163
+ type: 'v',
164
+ dy: scaleY * instruction.dy,
165
+ };
166
+ }
167
+ throw new Error('unexpected function');
168
+ });
169
+ return (0, serialize_instructions_1.serializeInstructions)((0, translate_path_1.translateSegments)(mapped, bounded.x1, bounded.y1));
170
+ };
171
+ exports.scalePath = scalePath;
@@ -1 +1,3 @@
1
+ import type { Instruction } from './helpers/types';
2
+ export declare const translateSegments: (segments: Instruction[], x: number, y: number) => Instruction[];
1
3
  export declare const translatePath: (path: string, x: number, y: number) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.translatePath = void 0;
3
+ exports.translatePath = exports.translateSegments = void 0;
4
4
  const parse_path_1 = require("./parse-path");
5
5
  const serialize_instructions_1 = require("./serialize-instructions");
6
6
  const translateSegments = (segments, x, y) => {
@@ -101,7 +101,8 @@ const translateSegments = (segments, x, y) => {
101
101
  throw new Error(`Unknown segment type: ${segment.type}`);
102
102
  });
103
103
  };
104
+ exports.translateSegments = translateSegments;
104
105
  const translatePath = (path, x, y) => {
105
- return (0, serialize_instructions_1.serializeInstructions)(translateSegments((0, parse_path_1.parsePath)(path), x, y));
106
+ return (0, serialize_instructions_1.serializeInstructions)((0, exports.translateSegments)((0, parse_path_1.parsePath)(path), x, y));
106
107
  };
107
108
  exports.translatePath = translatePath;
package/dist/unarc.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unarc = void 0;
4
- const iterate_1 = require("./helpers/iterate");
5
4
  const parse_1 = require("./helpers/parse");
6
5
  const TAU = Math.PI * 2;
7
6
  function approximate_unit_arc(theta1, delta_theta) {
@@ -80,36 +79,70 @@ function a2c({ x1, y1, x2, y2, fa, fs, rx, ry, phi, }) {
80
79
  return curve;
81
80
  });
82
81
  }
83
- // Requires path to be normalized
84
82
  const unarc = (d) => {
85
83
  const segments = (0, parse_1.parsePath)(d);
86
- const x = 0;
87
- const y = 0;
88
- return (0, iterate_1.iterateOverSegments)(segments, ({ segment }) => {
89
- const nextX = segment[6];
90
- const nextY = segment[7];
91
- const new_segments = a2c({
92
- x1: x,
93
- y1: y,
94
- x2: nextX,
95
- y2: nextY,
96
- fa: segment[4],
97
- fs: segment[5],
98
- rx: segment[1],
99
- ry: segment[2],
100
- phi: segment[3],
101
- });
102
- // Degenerated arcs can be ignored by renderer, but should not be dropped
103
- // to avoid collisions with `S A S` and so on. Replace with empty line.
104
- if (new_segments.length === 0) {
105
- return [['L', segment[6], segment[7]]];
84
+ let x = 0;
85
+ let y = 0;
86
+ const newSegments = segments.map((s) => {
87
+ switch (s[0]) {
88
+ case 'M':
89
+ case 'L': {
90
+ x = s[1];
91
+ y = s[2];
92
+ return [s];
93
+ }
94
+ case 'A': {
95
+ const nextX = s[6];
96
+ const nextY = s[7];
97
+ const new_segments = a2c({
98
+ x1: x,
99
+ y1: y,
100
+ x2: nextX,
101
+ y2: nextY,
102
+ fa: s[4],
103
+ fs: s[5],
104
+ rx: s[1],
105
+ ry: s[2],
106
+ phi: s[3],
107
+ });
108
+ // Degenerated arcs can be ignored by renderer, but should not be dropped
109
+ // to avoid collisions with `S A S` and so on. Replace with empty line.
110
+ if (new_segments.length === 0) {
111
+ return [['L', s[6], s[7]]];
112
+ }
113
+ const result = [];
114
+ new_segments.forEach((_s) => {
115
+ result.push(['C', _s[2], _s[3], _s[4], _s[5], _s[6], _s[7]]);
116
+ });
117
+ return result;
118
+ }
119
+ case 'V': {
120
+ y = s[1];
121
+ return [s];
122
+ }
123
+ case 'H': {
124
+ x = s[1];
125
+ return [s];
126
+ }
127
+ case 'C': {
128
+ x = s[5];
129
+ y = s[6];
130
+ return [s];
131
+ }
132
+ case 'Q': {
133
+ x = s[3];
134
+ y = s[4];
135
+ return [s];
136
+ }
137
+ case 'Z': {
138
+ return [s];
139
+ }
140
+ default:
141
+ throw new Error(`Unexpected instruction ${s[0]}`);
106
142
  }
107
- const result = [];
108
- new_segments.forEach((_s) => {
109
- result.push(['C', _s[2], _s[3], _s[4], _s[5], _s[6], _s[7]]);
110
- });
111
- return result;
112
143
  });
144
+ const flatted = newSegments.flat(1);
145
+ return flatted;
113
146
  };
114
147
  exports.unarc = unarc;
115
148
  function get_arc_center({ x1, y1, x2, y2, fa, fs, rx, ry, sin_phi, cos_phi, }) {
package/dist/unshort.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unshort = void 0;
4
- // Requires that the path is already normalized
5
4
  const unshort = function (segments) {
6
5
  let prevControlX = 0;
7
6
  let prevControlY = 0;
@@ -0,0 +1,5 @@
1
+ import type { WarpPathFn } from './warp-helpers';
2
+ export declare const warpPath: (path: string, transformer: WarpPathFn, options?: {
3
+ interpolationThreshold?: number;
4
+ }) => string;
5
+ export type { WarpPathFn } from './warp-helpers';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.warpPath = void 0;
4
+ const get_bounding_box_1 = require("../get-bounding-box");
5
+ const parse_path_1 = require("../parse-path");
6
+ const reduce_instructions_1 = require("../reduce-instructions");
7
+ const serialize_instructions_1 = require("../serialize-instructions");
8
+ const warp_helpers_1 = require("./warp-helpers");
9
+ const getDefaultInterpolationThreshold = (instructions) => {
10
+ const boundingBox = (0, get_bounding_box_1.getBoundingBoxFromInstructions)(instructions);
11
+ const longer = Math.max(boundingBox.y2 - boundingBox.y1, boundingBox.x2 - boundingBox.x1);
12
+ return longer * 0.01;
13
+ };
14
+ const warpPath = (path, transformer, options) => {
15
+ var _a;
16
+ const reduced = (0, reduce_instructions_1.reduceInstructions)((0, parse_path_1.parsePath)(path));
17
+ const withZFix = (0, warp_helpers_1.fixZInstruction)(reduced);
18
+ const interpolated = (0, warp_helpers_1.svgPathInterpolate)(withZFix, (_a = options === null || options === void 0 ? void 0 : options.interpolationThreshold) !== null && _a !== void 0 ? _a : getDefaultInterpolationThreshold(withZFix));
19
+ return (0, serialize_instructions_1.serializeInstructions)((0, warp_helpers_1.warpTransform)(interpolated, transformer));
20
+ };
21
+ exports.warpPath = warpPath;
@@ -0,0 +1,14 @@
1
+ import type { ReducedInstruction } from '../helpers/types';
2
+ export declare type WarpPathFn = (point: {
3
+ x: number;
4
+ y: number;
5
+ }) => {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ export declare function svgPathInterpolate(path: ReducedInstruction[], threshold: number): ReducedInstruction[];
10
+ export declare const warpTransform: (path: ReducedInstruction[], transformer: WarpPathFn) => ReducedInstruction[];
11
+ export declare const fixZInstruction: (instructions: ReducedInstruction[]) => ReducedInstruction[];
12
+ export declare function interpolateUntil(points: [number, number][], threshold: number, deltaFunction?: (points: [number, number][]) => number): [number, number][][];
13
+ export declare function split(p: number[][], t?: number): number[][][];
14
+ export declare function createLineSegment(points: number[][]): ReducedInstruction;
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLineSegment = exports.split = exports.interpolateUntil = exports.fixZInstruction = exports.warpTransform = exports.svgPathInterpolate = void 0;
4
+ function svgPathInterpolate(path, threshold) {
5
+ let didWork = false;
6
+ const deltaFunction = (points) => {
7
+ const linearPoints = [
8
+ points[0].slice(0, 2),
9
+ points[points.length - 1].slice(0, 2),
10
+ ];
11
+ const delta = euclideanDistance(linearPoints);
12
+ didWork = didWork || delta > threshold;
13
+ return delta;
14
+ };
15
+ return warpInterpolate(path, threshold, deltaFunction);
16
+ }
17
+ exports.svgPathInterpolate = svgPathInterpolate;
18
+ function warpInterpolate(path, threshold, deltaFunction) {
19
+ let prexX = 0;
20
+ let prexY = 0;
21
+ return path
22
+ .map((segment) => {
23
+ const points = [[prexX, prexY]];
24
+ if (segment.type !== 'Z') {
25
+ prexX = segment.x;
26
+ prexY = segment.y;
27
+ }
28
+ if (segment.type === 'C') {
29
+ points.push([segment.cp1x, segment.cp1y]);
30
+ points.push([segment.cp2x, segment.cp2y]);
31
+ points.push([segment.x, segment.y]);
32
+ }
33
+ if (segment.type === 'L') {
34
+ points.push([segment.x, segment.y]);
35
+ }
36
+ if (segment.type === 'Q') {
37
+ points.push([segment.cpx, segment.cpy]);
38
+ points.push([segment.x, segment.y]);
39
+ }
40
+ if (segment.type === 'C' ||
41
+ segment.type === 'Q' ||
42
+ segment.type === 'L') {
43
+ return interpolateUntil(points, threshold, deltaFunction).map((rawSegment) => createLineSegment(rawSegment));
44
+ }
45
+ return [segment];
46
+ })
47
+ .flat(1);
48
+ }
49
+ const warpTransform = (path, transformer) => {
50
+ return path
51
+ .map((segment) => {
52
+ if (segment.type === 'L') {
53
+ const { x, y } = transformer({ x: segment.x, y: segment.y });
54
+ return [
55
+ {
56
+ type: 'L',
57
+ x,
58
+ y,
59
+ },
60
+ ];
61
+ }
62
+ if (segment.type === 'Q') {
63
+ const { x, y } = transformer({ x: segment.x, y: segment.y });
64
+ const { x: cpx, y: cpy } = transformer({
65
+ x: segment.cpx,
66
+ y: segment.cpy,
67
+ });
68
+ return [
69
+ {
70
+ type: 'Q',
71
+ x,
72
+ y,
73
+ cpx,
74
+ cpy,
75
+ },
76
+ ];
77
+ }
78
+ if (segment.type === 'C') {
79
+ const { x, y } = transformer({ x: segment.x, y: segment.y });
80
+ const { x: cp1x, y: cp1y } = transformer({
81
+ x: segment.cp1x,
82
+ y: segment.cp1y,
83
+ });
84
+ const { x: cp2x, y: cp2y } = transformer({
85
+ x: segment.cp2x,
86
+ y: segment.cp2y,
87
+ });
88
+ return [
89
+ {
90
+ type: 'C',
91
+ x,
92
+ y,
93
+ cp1x,
94
+ cp1y,
95
+ cp2x,
96
+ cp2y,
97
+ },
98
+ ];
99
+ }
100
+ if (segment.type === 'M') {
101
+ const { x, y } = transformer({ x: segment.x, y: segment.y });
102
+ return [
103
+ {
104
+ type: 'M',
105
+ x,
106
+ y,
107
+ },
108
+ ];
109
+ }
110
+ return [segment];
111
+ })
112
+ .flat(1);
113
+ };
114
+ exports.warpTransform = warpTransform;
115
+ // Add a line from second to last point to last point and then keep Z so it can be transformed as well
116
+ const fixZInstruction = (instructions) => {
117
+ let prevX = 0;
118
+ let prevY = 0;
119
+ return instructions
120
+ .map((instruction) => {
121
+ if (instruction.type === 'Z') {
122
+ return [
123
+ {
124
+ type: 'L',
125
+ x: prevX,
126
+ y: prevY,
127
+ },
128
+ {
129
+ type: 'Z',
130
+ },
131
+ ];
132
+ }
133
+ if (instruction.type === 'M') {
134
+ prevX = instruction.x;
135
+ prevY = instruction.y;
136
+ }
137
+ return [instruction];
138
+ })
139
+ .flat(1);
140
+ };
141
+ exports.fixZInstruction = fixZInstruction;
142
+ const euclideanDistance = (points) => {
143
+ const startPoint = points[0];
144
+ const endPoint = points[points.length - 1];
145
+ let d2 = 0;
146
+ for (let i = 0; i < startPoint.length; i++) {
147
+ const d = endPoint[i] - startPoint[i];
148
+ d2 += d ** 2;
149
+ }
150
+ return Math.sqrt(d2);
151
+ };
152
+ function interpolateUntil(points, threshold, deltaFunction = euclideanDistance) {
153
+ const stack = [points];
154
+ const segments = [];
155
+ while (stack.length > 0) {
156
+ const currentPoints = stack.pop();
157
+ if (deltaFunction(currentPoints) > threshold) {
158
+ const newPoints = split(currentPoints);
159
+ // Add new segments backwards so they end up in correct order
160
+ for (let i = newPoints.length - 1; i >= 0; i--) {
161
+ stack.push(newPoints[i]);
162
+ }
163
+ }
164
+ else {
165
+ segments.push(currentPoints);
166
+ }
167
+ }
168
+ return segments;
169
+ }
170
+ exports.interpolateUntil = interpolateUntil;
171
+ function split(p, t = 0.5) {
172
+ const seg0 = [];
173
+ const seg1 = [];
174
+ const orders = [p];
175
+ while (orders.length < p.length) {
176
+ const q = orders[orders.length - 1];
177
+ const r = [];
178
+ for (let i = 1; i < q.length; i++) {
179
+ const q0 = q[i - 1];
180
+ const q1 = q[i];
181
+ const s = [];
182
+ const dim = Math.max(q0.length, q1.length);
183
+ for (let j = 0; j < dim; j++) {
184
+ const s0 = q0[j] || 0;
185
+ const s1 = q1[j] || 0;
186
+ s.push(s0 + (s1 - s0) * t);
187
+ }
188
+ r.push(s);
189
+ }
190
+ orders.push(r);
191
+ }
192
+ for (let i = 0; i < orders.length; i++) {
193
+ seg0.push(orders[i][0]);
194
+ seg1.push(orders[orders.length - 1 - i][i]);
195
+ }
196
+ return [seg0, seg1];
197
+ }
198
+ exports.split = split;
199
+ function createLineSegment(points) {
200
+ switch (points.length) {
201
+ case 2:
202
+ return {
203
+ type: 'L',
204
+ x: points[1][0],
205
+ y: points[1][1],
206
+ };
207
+ case 3:
208
+ return {
209
+ type: 'Q',
210
+ cpx: points[1][0],
211
+ cpy: points[1][1],
212
+ x: points[2][0],
213
+ y: points[2][1],
214
+ };
215
+ case 4:
216
+ return {
217
+ type: 'C',
218
+ cp1x: points[1][0],
219
+ cp1y: points[1][1],
220
+ cp2x: points[2][0],
221
+ cp2y: points[2][1],
222
+ x: points[3][0],
223
+ y: points[3][1],
224
+ };
225
+ default:
226
+ throw new Error('Expected 2, 3 or 4 points for a line segment, got ' + points.length);
227
+ }
228
+ }
229
+ exports.createLineSegment = createLineSegment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/paths",
3
- "version": "3.3.42",
3
+ "version": "3.3.43",
4
4
  "description": "Utility functions for SVG paths",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "bfb8098300fb75d4c27220eead954c2dc8e5b4ce"
38
+ "gitHead": "3585e437a30ba001e983539728eb1914172b729c"
39
39
  }
@@ -1,2 +0,0 @@
1
- import type { Instruction } from './types';
2
- export declare const serializeInstructions: (path: Instruction[]) => string;