@remotion/paths 4.0.0-webhook.27 → 4.1.0-alpha2

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 (69) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +1 -2
  3. package/dist/evolve-path.d.ts +2 -2
  4. package/dist/evolve-path.js +2 -2
  5. package/dist/extend-viewbox.d.ts +2 -2
  6. package/dist/extend-viewbox.js +2 -2
  7. package/dist/get-bounding-box.d.ts +8 -0
  8. package/dist/get-bounding-box.js +185 -0
  9. package/dist/get-length.d.ts +2 -2
  10. package/dist/get-length.js +2 -2
  11. package/dist/get-point-at-length.d.ts +2 -2
  12. package/dist/get-point-at-length.js +2 -2
  13. package/dist/get-subpaths.d.ts +6 -0
  14. package/dist/get-subpaths.js +19 -0
  15. package/dist/get-tangent-at-length.d.ts +2 -2
  16. package/dist/get-tangent-at-length.js +2 -2
  17. package/dist/helpers/arc.d.ts +0 -0
  18. package/dist/helpers/arc.js +0 -0
  19. package/dist/helpers/bezier-functions.d.ts +0 -0
  20. package/dist/helpers/bezier-functions.js +0 -0
  21. package/dist/helpers/bezier-values.d.ts +0 -0
  22. package/dist/helpers/bezier-values.js +0 -0
  23. package/dist/helpers/bezier.d.ts +0 -0
  24. package/dist/helpers/bezier.js +0 -0
  25. package/dist/helpers/construct.d.ts +9 -1
  26. package/dist/helpers/construct.js +218 -128
  27. package/dist/helpers/get-part-at-length.d.ts +0 -0
  28. package/dist/helpers/get-part-at-length.js +0 -0
  29. package/dist/helpers/iterate.d.ts +14 -0
  30. package/dist/helpers/iterate.js +95 -0
  31. package/dist/helpers/linear.d.ts +6 -1
  32. package/dist/helpers/linear.js +1 -1
  33. package/dist/helpers/remove-a-s-t-curves.d.ts +2 -0
  34. package/dist/helpers/remove-a-s-t-curves.js +271 -0
  35. package/dist/helpers/split-curve.d.ts +1 -1
  36. package/dist/helpers/split-curve.js +0 -0
  37. package/dist/helpers/types.d.ts +109 -2
  38. package/dist/helpers/types.js +0 -0
  39. package/dist/index.d.ts +10 -2
  40. package/dist/index.js +19 -3
  41. package/dist/interpolate-path.d.ts +2 -2
  42. package/dist/interpolate-path.js +2 -2
  43. package/dist/normalize-path.d.ts +4 -2
  44. package/dist/normalize-path.js +141 -277
  45. package/dist/parse-path.d.ts +8 -0
  46. package/dist/parse-path.js +265 -0
  47. package/dist/reduce-instructions.d.ts +7 -0
  48. package/dist/reduce-instructions.js +15 -0
  49. package/dist/reset-path.d.ts +6 -0
  50. package/dist/reset-path.js +15 -0
  51. package/dist/reverse-path.d.ts +2 -2
  52. package/dist/reverse-path.js +73 -118
  53. package/dist/scale-path.d.ts +10 -0
  54. package/dist/scale-path.js +180 -0
  55. package/dist/serialize-instructions.d.ts +2 -0
  56. package/dist/serialize-instructions.js +78 -0
  57. package/dist/translate-path.d.ts +11 -0
  58. package/dist/translate-path.js +116 -0
  59. package/dist/warp-path/index.d.ts +10 -0
  60. package/dist/warp-path/index.js +26 -0
  61. package/dist/warp-path/warp-helpers.d.ts +14 -0
  62. package/dist/warp-path/warp-helpers.js +229 -0
  63. package/package.json +38 -38
  64. package/.prettierrc.js +0 -14
  65. package/dist/get-parts.d.ts +0 -7
  66. package/dist/get-parts.js +0 -31
  67. package/dist/helpers/parse.d.ts +0 -2
  68. package/dist/helpers/parse.js +0 -49
  69. package/tsconfig.json +0 -9
package/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2022 JonnyBurger
1
+ Copyright (c) 2023 JonnyBurger
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -9,10 +9,9 @@ A package providing utility functions for dealing with SVG paths. This package c
9
9
 
10
10
  No dependencies are needed, meaning this package can be used independently of Remotion.
11
11
 
12
- ## API
12
+ ## API
13
13
 
14
14
  - [`getLength()`](https://remotion.dev/docs/paths/get-length)
15
- - [`getParts()`](https://remotion.dev/docs/paths/get-parts)
16
15
  - [`getPointAtLength()`](https://remotion.dev/docs/paths/get-point-at-length)
17
16
  - [`getTangentAtLength()`](https://remotion.dev/docs/paths/get-tangent-at-length)
18
17
  - [`reversePath()`](https://remotion.dev/docs/paths/reverse-path)
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Animates an SVG from being invisible to it's full length.
2
+ * @description Animates an SVG from being invisible to it's full length.
3
3
  * @param {string} path A valid SVG path
4
4
  * @param {number} progress The first valid SVG path
5
- * @link https://remotion.dev/docs/paths/evolve-path
5
+ * @see [Documentation](https://remotion.dev/docs/paths/evolve-path)
6
6
  */
7
7
  export declare const evolvePath: (progress: number, path: string) => {
8
8
  strokeDasharray: string;
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.evolvePath = void 0;
4
4
  const get_length_1 = require("./get-length");
5
5
  /**
6
- * Animates an SVG from being invisible to it's full length.
6
+ * @description Animates an SVG from being invisible to it's full length.
7
7
  * @param {string} path A valid SVG path
8
8
  * @param {number} progress The first valid SVG path
9
- * @link https://remotion.dev/docs/paths/evolve-path
9
+ * @see [Documentation](https://remotion.dev/docs/paths/evolve-path)
10
10
  */
11
11
  const evolvePath = (progress, path) => {
12
12
  const length = (0, get_length_1.getLength)(path);
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Extends a viewbox in all directions by a scale factor.
2
+ * @description Extends a viewbox in all directions by a scale factor.
3
3
  * @param {string} currentViewBox A valid SVG viewBox
4
- * @link https://remotion.dev/docs/paths/extend-viewbox
4
+ * @see [Documentation](https://remotion.dev/docs/paths/extend-viewbox)
5
5
  */
6
6
  export declare const extendViewBox: (currentViewBox: string, scale: number) => string;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extendViewBox = void 0;
4
4
  /**
5
- * Extends a viewbox in all directions by a scale factor.
5
+ * @description Extends a viewbox in all directions by a scale factor.
6
6
  * @param {string} currentViewBox A valid SVG viewBox
7
- * @link https://remotion.dev/docs/paths/extend-viewbox
7
+ * @see [Documentation](https://remotion.dev/docs/paths/extend-viewbox)
8
8
  */
9
9
  const extendViewBox = (currentViewBox, scale) => {
10
10
  const relativeScale = scale - 1;
@@ -0,0 +1,8 @@
1
+ import type { BoundingBox, ReducedInstruction } from './helpers/types';
2
+ /**
3
+ * @description Returns the bounding box of the given path, suitable for calculating the viewBox value that you need to pass to an SVG.
4
+ * @param {string} d
5
+ * @see [Documentation](https://www.remotion.dev/docs/paths/get-bounding-box)
6
+ */
7
+ export declare const getBoundingBox: (d: string) => BoundingBox;
8
+ export declare const getBoundingBoxFromInstructions: (instructions: ReducedInstruction[]) => BoundingBox;
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBoundingBoxFromInstructions = exports.getBoundingBox = void 0;
4
+ const remove_a_s_t_curves_1 = require("./helpers/remove-a-s-t-curves");
5
+ const normalize_path_1 = require("./normalize-path");
6
+ const parse_path_1 = require("./parse-path");
7
+ // Precision for consider cubic polynom as quadratic one
8
+ const CBEZIER_MINMAX_EPSILON = 0.00000001;
9
+ // https://github.com/kpym/SVGPathy/blob/acd1a50c626b36d81969f6e98e8602e128ba4302/lib/box.js#L89
10
+ function minmaxQ(A) {
11
+ const min = Math.min(A[0], A[2]);
12
+ const max = Math.max(A[0], A[2]);
13
+ if (A[1] > A[0] ? A[2] >= A[1] : A[2] <= A[1]) {
14
+ // if no extremum in ]0,1[
15
+ return [min, max];
16
+ }
17
+ // check if the extremum E is min or max
18
+ const E = (A[0] * A[2] - A[1] * A[1]) / (A[0] - 2 * A[1] + A[2]);
19
+ return E < min ? [E, max] : [min, E];
20
+ }
21
+ // https://github.com/kpym/SVGPathy/blob/acd1a50c626b36d81969f6e98e8602e128ba4302/lib/box.js#L127
22
+ function minmaxC(A) {
23
+ const K = A[0] - 3 * A[1] + 3 * A[2] - A[3];
24
+ // if the polynomial is (almost) quadratic and not cubic
25
+ if (Math.abs(K) < CBEZIER_MINMAX_EPSILON) {
26
+ if (A[0] === A[3] && A[0] === A[1]) {
27
+ // no curve, point targeting same location
28
+ return [A[0], A[3]];
29
+ }
30
+ return minmaxQ([
31
+ A[0],
32
+ -0.5 * A[0] + 1.5 * A[1],
33
+ A[0] - 3 * A[1] + 3 * A[2],
34
+ ]);
35
+ }
36
+ // the reduced discriminant of the derivative
37
+ const T = -A[0] * A[2] +
38
+ A[0] * A[3] -
39
+ A[1] * A[2] -
40
+ A[1] * A[3] +
41
+ A[1] * A[1] +
42
+ A[2] * A[2];
43
+ // if the polynomial is monotone in [0,1]
44
+ if (T <= 0) {
45
+ return [Math.min(A[0], A[3]), Math.max(A[0], A[3])];
46
+ }
47
+ const S = Math.sqrt(T);
48
+ // potential extrema
49
+ let min = Math.min(A[0], A[3]);
50
+ let max = Math.max(A[0], A[3]);
51
+ const L = A[0] - 2 * A[1] + A[2];
52
+ // check local extrema
53
+ for (let R = (L + S) / K, i = 1; i <= 2; R = (L - S) / K, i++) {
54
+ if (R > 0 && R < 1) {
55
+ // if the extrema is for R in [0,1]
56
+ const Q = A[0] * (1 - R) * (1 - R) * (1 - R) +
57
+ A[1] * 3 * (1 - R) * (1 - R) * R +
58
+ A[2] * 3 * (1 - R) * R * R +
59
+ A[3] * R * R * R;
60
+ if (Q < min) {
61
+ min = Q;
62
+ }
63
+ if (Q > max) {
64
+ max = Q;
65
+ }
66
+ }
67
+ }
68
+ return [min, max];
69
+ }
70
+ /**
71
+ * @description Returns the bounding box of the given path, suitable for calculating the viewBox value that you need to pass to an SVG.
72
+ * @param {string} d
73
+ * @see [Documentation](https://www.remotion.dev/docs/paths/get-bounding-box)
74
+ */
75
+ const getBoundingBox = (d) => {
76
+ const parsed = (0, parse_path_1.parsePath)(d);
77
+ const unarced = (0, remove_a_s_t_curves_1.removeATSHVInstructions)((0, normalize_path_1.normalizeInstructions)(parsed));
78
+ return (0, exports.getBoundingBoxFromInstructions)(unarced);
79
+ };
80
+ exports.getBoundingBox = getBoundingBox;
81
+ const getBoundingBoxFromInstructions = (instructions) => {
82
+ let minX = Infinity;
83
+ let minY = Infinity;
84
+ let maxX = -Infinity;
85
+ let maxY = -Infinity;
86
+ let x = 0;
87
+ let y = 0;
88
+ let lastMoveX = 0;
89
+ let lastMoveY = 0;
90
+ for (const seg of instructions) {
91
+ switch (seg.type) {
92
+ case 'M': {
93
+ lastMoveX = seg.x;
94
+ lastMoveY = seg.y;
95
+ if (minX > seg.x) {
96
+ minX = seg.x;
97
+ }
98
+ if (minY > seg.y) {
99
+ minY = seg.y;
100
+ }
101
+ if (maxX < seg.x) {
102
+ maxX = seg.x;
103
+ }
104
+ if (maxY < seg.y) {
105
+ maxY = seg.y;
106
+ }
107
+ x = seg.x;
108
+ y = seg.y;
109
+ break;
110
+ }
111
+ case 'L': {
112
+ if (minX > seg.x) {
113
+ minX = seg.x;
114
+ }
115
+ if (minY > seg.y) {
116
+ minY = seg.y;
117
+ }
118
+ if (maxX < seg.x) {
119
+ maxX = seg.x;
120
+ }
121
+ if (maxY < seg.y) {
122
+ maxY = seg.y;
123
+ }
124
+ x = seg.x;
125
+ y = seg.y;
126
+ break;
127
+ }
128
+ case 'C': {
129
+ const cxMinMax = minmaxC([x, seg.cp1x, seg.cp2x, seg.x]);
130
+ if (minX > cxMinMax[0]) {
131
+ minX = cxMinMax[0];
132
+ }
133
+ if (maxX < cxMinMax[1]) {
134
+ maxX = cxMinMax[1];
135
+ }
136
+ const cyMinMax = minmaxC([y, seg.cp1y, seg.cp2y, seg.y]);
137
+ if (minY > cyMinMax[0]) {
138
+ minY = cyMinMax[0];
139
+ }
140
+ if (maxY < cyMinMax[1]) {
141
+ maxY = cyMinMax[1];
142
+ }
143
+ x = seg.x;
144
+ y = seg.y;
145
+ break;
146
+ }
147
+ case 'Q': {
148
+ const qxMinMax = minmaxQ([x, seg.cpx, seg.x]);
149
+ if (minX > qxMinMax[0]) {
150
+ minX = qxMinMax[0];
151
+ }
152
+ if (maxX < qxMinMax[1]) {
153
+ maxX = qxMinMax[1];
154
+ }
155
+ const qyMinMax = minmaxQ([y, seg.cpy, seg.y]);
156
+ if (minY > qyMinMax[0]) {
157
+ minY = qyMinMax[0];
158
+ }
159
+ if (maxY < qyMinMax[1]) {
160
+ maxY = qyMinMax[1];
161
+ }
162
+ x = seg.x;
163
+ y = seg.y;
164
+ break;
165
+ }
166
+ case 'Z':
167
+ x = lastMoveX;
168
+ y = lastMoveY;
169
+ break;
170
+ default:
171
+ // @ts-expect-error
172
+ throw new Error(`Unknown instruction ${seg.type}`);
173
+ }
174
+ }
175
+ return {
176
+ x1: minX,
177
+ y1: minY,
178
+ x2: maxX,
179
+ y2: maxY,
180
+ viewBox: `${minX} ${minY} ${maxX - minX} ${maxY - minY}`,
181
+ width: maxX - minX,
182
+ height: maxY - minY,
183
+ };
184
+ };
185
+ exports.getBoundingBoxFromInstructions = getBoundingBoxFromInstructions;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Gets the length of an SVG path.
2
+ * @description Gets the length of an SVG path.
3
3
  * @param {string} path A valid SVG path
4
- * @link https://remotion.dev/docs/paths/get-length
4
+ * @see [Documentation](https://remotion.dev/docs/paths/get-length)
5
5
  */
6
6
  export declare const getLength: (path: string) => number;
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.getLength = void 0;
5
5
  const construct_1 = require("./helpers/construct");
6
6
  /**
7
- * Gets the length of an SVG path.
7
+ * @description Gets the length of an SVG path.
8
8
  * @param {string} path A valid SVG path
9
- * @link https://remotion.dev/docs/paths/get-length
9
+ * @see [Documentation](https://remotion.dev/docs/paths/get-length)
10
10
  */
11
11
  const getLength = (path) => {
12
12
  const constructucted = (0, construct_1.construct)(path);
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Gets the coordinates of a point which is on an SVG path.
2
+ * @description Gets the coordinates of a point which is on an SVG path.
3
3
  * @param {string} path A valid SVG path
4
4
  * @param {number} length The length at which the point should be sampled
5
- * @link https://remotion.dev/docs/paths/get-point-at-length
5
+ * @see [Documentation](https://remotion.dev/docs/paths/get-point-at-length)
6
6
  */
7
7
  export declare const getPointAtLength: (path: string, length: number) => import("./helpers/types").Point;
@@ -4,10 +4,10 @@ exports.getPointAtLength = void 0;
4
4
  const construct_1 = require("./helpers/construct");
5
5
  const get_part_at_length_1 = require("./helpers/get-part-at-length");
6
6
  /**
7
- * Gets the coordinates of a point which is on an SVG path.
7
+ * @description Gets the coordinates of a point which is on an SVG path.
8
8
  * @param {string} path A valid SVG path
9
9
  * @param {number} length The length at which the point should be sampled
10
- * @link https://remotion.dev/docs/paths/get-point-at-length
10
+ * @see [Documentation](https://remotion.dev/docs/paths/get-point-at-length)
11
11
  */
12
12
  const getPointAtLength = (path, length) => {
13
13
  const constructed = (0, construct_1.construct)(path);
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @description Splits a valid SVG path into it's parts.
3
+ * @param {string} path A valid SVG path
4
+ * @see [Documentation](https://remotion.dev/docs/paths/get-subpaths)
5
+ */
6
+ export declare const getSubpaths: (path: string) => string[];
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSubpaths = void 0;
4
+ const construct_1 = require("./helpers/construct");
5
+ const parse_path_1 = require("./parse-path");
6
+ const serialize_instructions_1 = require("./serialize-instructions");
7
+ /**
8
+ * @description Splits a valid SVG path into it's parts.
9
+ * @param {string} path A valid SVG path
10
+ * @see [Documentation](https://remotion.dev/docs/paths/get-subpaths)
11
+ */
12
+ const getSubpaths = (path) => {
13
+ const parsed = (0, parse_path_1.parsePath)(path);
14
+ const { segments } = (0, construct_1.constructFromInstructions)(parsed);
15
+ return segments.map((seg) => {
16
+ return (0, serialize_instructions_1.serializeInstructions)(seg);
17
+ });
18
+ };
19
+ exports.getSubpaths = getSubpaths;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Gets tangent values x and y of a point which is on an SVG path
2
+ * @description Gets tangent values x and y of a point which is on an SVG path
3
3
  * @param {string} path A valid SVG path
4
4
  * @param {number} length The length at which the tangent should be sampled
5
- * @link https://remotion.dev/docs/paths/get-tangent-at-length
5
+ * @see [Documentation](https://remotion.dev/docs/paths/get-tangent-at-length)
6
6
  */
7
7
  export declare const getTangentAtLength: (path: string, length: number) => import("./helpers/types").Point;
@@ -4,10 +4,10 @@ exports.getTangentAtLength = void 0;
4
4
  const construct_1 = require("./helpers/construct");
5
5
  const get_part_at_length_1 = require("./helpers/get-part-at-length");
6
6
  /**
7
- * Gets tangent values x and y of a point which is on an SVG path
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
9
9
  * @param {number} length The length at which the tangent should be sampled
10
- * @link https://remotion.dev/docs/paths/get-tangent-at-length
10
+ * @see [Documentation](https://remotion.dev/docs/paths/get-tangent-at-length)
11
11
  */
12
12
  const getTangentAtLength = (path, length) => {
13
13
  const constructed = (0, construct_1.construct)(path);
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,5 +1,13 @@
1
- import type { Point, Properties } from './types';
1
+ import type { Instruction, Point, Properties } from './types';
2
+ export declare const constructFromInstructions: (instructions: Instruction[]) => {
3
+ segments: Instruction[][];
4
+ initial_point: Point | null;
5
+ length: number;
6
+ partial_lengths: number[];
7
+ functions: (Properties | null)[];
8
+ };
2
9
  export declare const construct: (string: string) => {
10
+ segments: Instruction[][];
3
11
  initial_point: Point | null;
4
12
  length: number;
5
13
  partial_lengths: number[];