@remotion/paths 4.0.0-newpaths.13 → 4.0.0-newpaths.40
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.
- package/dist/get-bounding-box.js +39 -37
- package/dist/get-subpaths.js +4 -5
- package/dist/helpers/construct.d.ts +1 -2
- package/dist/helpers/construct.js +199 -123
- package/dist/helpers/iterate.d.ts +10 -0
- package/dist/helpers/iterate.js +46 -0
- package/dist/helpers/linear.d.ts +6 -1
- package/dist/helpers/linear.js +1 -1
- package/dist/helpers/parse.d.ts +1 -1
- package/dist/helpers/parse.js +239 -24
- package/dist/helpers/remove-a-s-t-curves.d.ts +2 -0
- package/dist/helpers/remove-a-s-t-curves.js +254 -0
- package/dist/helpers/serialize.d.ts +2 -0
- package/dist/helpers/serialize.js +75 -0
- package/dist/helpers/types.d.ts +101 -1
- package/dist/helpers/unarc.d.ts +2 -0
- package/dist/helpers/unarc.js +254 -0
- package/dist/helpers/unshort.d.ts +2 -0
- package/dist/helpers/unshort.js +65 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/dist/parse-path.d.ts +2 -0
- package/dist/parse-path.js +266 -0
- package/dist/parse.d.ts +2 -0
- package/dist/parse.js +266 -0
- package/dist/serialize-instructions.d.ts +2 -0
- package/dist/serialize-instructions.js +75 -0
- package/dist/serialize.d.ts +2 -0
- package/dist/serialize.js +75 -0
- package/dist/translate-path.js +43 -25
- package/dist/unarc.js +27 -57
- package/dist/unshort.js +3 -4
- package/package.json +2 -2
package/dist/get-bounding-box.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBoundingBox = void 0;
|
|
4
|
+
const remove_a_s_t_curves_1 = require("./helpers/remove-a-s-t-curves");
|
|
4
5
|
const normalize_path_1 = require("./normalize-path");
|
|
5
|
-
const
|
|
6
|
-
const unshort_1 = require("./unshort");
|
|
6
|
+
const parse_path_1 = require("./parse-path");
|
|
7
7
|
// Precision for consider cubic polynom as quadratic one
|
|
8
8
|
const CBEZIER_MINMAX_EPSILON = 0.00000001;
|
|
9
9
|
// https://github.com/kpym/SVGPathy/blob/acd1a50c626b36d81969f6e98e8602e128ba4302/lib/box.js#L89
|
|
@@ -72,91 +72,93 @@ const getBoundingBox = (d) => {
|
|
|
72
72
|
let minY = Infinity;
|
|
73
73
|
let maxX = -Infinity;
|
|
74
74
|
let maxY = -Infinity;
|
|
75
|
-
const
|
|
76
|
-
const unarced = (0,
|
|
77
|
-
const unshortened = (0, unshort_1.unshort)(unarced);
|
|
75
|
+
const parsed = (0, parse_path_1.parsePath)((0, normalize_path_1.normalizePath)(d));
|
|
76
|
+
const unarced = (0, remove_a_s_t_curves_1.removeATSInstructions)(parsed);
|
|
78
77
|
let x = 0;
|
|
79
78
|
let y = 0;
|
|
80
|
-
for (const seg of
|
|
81
|
-
switch (seg
|
|
79
|
+
for (const seg of unarced) {
|
|
80
|
+
switch (seg.type) {
|
|
82
81
|
case 'M':
|
|
83
82
|
case 'L': {
|
|
84
|
-
if (minX > seg
|
|
85
|
-
minX = seg
|
|
83
|
+
if (minX > seg.x) {
|
|
84
|
+
minX = seg.x;
|
|
86
85
|
}
|
|
87
|
-
if (minY > seg
|
|
88
|
-
minY = seg
|
|
86
|
+
if (minY > seg.y) {
|
|
87
|
+
minY = seg.y;
|
|
89
88
|
}
|
|
90
|
-
if (maxX < seg
|
|
91
|
-
maxX = seg
|
|
89
|
+
if (maxX < seg.x) {
|
|
90
|
+
maxX = seg.x;
|
|
92
91
|
}
|
|
93
|
-
if (maxY < seg
|
|
94
|
-
maxY = seg
|
|
92
|
+
if (maxY < seg.y) {
|
|
93
|
+
maxY = seg.y;
|
|
95
94
|
}
|
|
96
|
-
x = seg
|
|
97
|
-
y = seg
|
|
95
|
+
x = seg.x;
|
|
96
|
+
y = seg.y;
|
|
98
97
|
break;
|
|
99
98
|
}
|
|
100
99
|
case 'V': {
|
|
101
|
-
if (minY > seg
|
|
102
|
-
minY = seg
|
|
100
|
+
if (minY > seg.y) {
|
|
101
|
+
minY = seg.y;
|
|
103
102
|
}
|
|
104
|
-
if (maxY < seg
|
|
105
|
-
maxY = seg
|
|
103
|
+
if (maxY < seg.y) {
|
|
104
|
+
maxY = seg.y;
|
|
106
105
|
}
|
|
107
|
-
y = seg
|
|
106
|
+
y = seg.y;
|
|
108
107
|
break;
|
|
109
108
|
}
|
|
110
109
|
case 'H': {
|
|
111
|
-
if (minX > seg
|
|
112
|
-
minX = seg
|
|
110
|
+
if (minX > seg.x) {
|
|
111
|
+
minX = seg.x;
|
|
113
112
|
}
|
|
114
|
-
if (maxX < seg
|
|
115
|
-
maxX = seg
|
|
113
|
+
if (maxX < seg.x) {
|
|
114
|
+
maxX = seg.x;
|
|
116
115
|
}
|
|
117
|
-
x = seg
|
|
116
|
+
x = seg.x;
|
|
118
117
|
break;
|
|
119
118
|
}
|
|
120
119
|
case 'C': {
|
|
121
|
-
const cxMinMax = minmaxC([x, seg
|
|
120
|
+
const cxMinMax = minmaxC([x, seg.cp1x, seg.cp2x, seg.x]);
|
|
122
121
|
if (minX > cxMinMax[0]) {
|
|
123
122
|
minX = cxMinMax[0];
|
|
124
123
|
}
|
|
125
124
|
if (maxX < cxMinMax[1]) {
|
|
126
125
|
maxX = cxMinMax[1];
|
|
127
126
|
}
|
|
128
|
-
const cyMinMax = minmaxC([y, seg
|
|
127
|
+
const cyMinMax = minmaxC([y, seg.cp1y, seg.cp2y, seg.y]);
|
|
129
128
|
if (minY > cyMinMax[0]) {
|
|
130
129
|
minY = cyMinMax[0];
|
|
131
130
|
}
|
|
132
131
|
if (maxY < cyMinMax[1]) {
|
|
133
132
|
maxY = cyMinMax[1];
|
|
134
133
|
}
|
|
135
|
-
x = seg
|
|
136
|
-
y = seg
|
|
134
|
+
x = seg.x;
|
|
135
|
+
y = seg.y;
|
|
137
136
|
break;
|
|
138
137
|
}
|
|
139
138
|
case 'Q': {
|
|
140
|
-
const qxMinMax = minmaxQ([x, seg
|
|
139
|
+
const qxMinMax = minmaxQ([x, seg.cpx, seg.x]);
|
|
141
140
|
if (minX > qxMinMax[0]) {
|
|
142
141
|
minX = qxMinMax[0];
|
|
143
142
|
}
|
|
144
143
|
if (maxX < qxMinMax[1]) {
|
|
145
144
|
maxX = qxMinMax[1];
|
|
146
145
|
}
|
|
147
|
-
const qyMinMax = minmaxQ([y, seg
|
|
146
|
+
const qyMinMax = minmaxQ([y, seg.cpy, seg.y]);
|
|
148
147
|
if (minY > qyMinMax[0]) {
|
|
149
148
|
minY = qyMinMax[0];
|
|
150
149
|
}
|
|
151
150
|
if (maxY < qyMinMax[1]) {
|
|
152
151
|
maxY = qyMinMax[1];
|
|
153
152
|
}
|
|
154
|
-
x = seg
|
|
155
|
-
y = seg
|
|
153
|
+
x = seg.x;
|
|
154
|
+
y = seg.y;
|
|
156
155
|
break;
|
|
157
156
|
}
|
|
157
|
+
case 'Z':
|
|
158
|
+
break;
|
|
158
159
|
default:
|
|
159
|
-
|
|
160
|
+
// @ts-expect-error
|
|
161
|
+
throw new Error(`Unknown instruction ${seg.type}`);
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
return { x1: minX, y1: minY, x2: maxX, y2: maxY };
|
package/dist/get-subpaths.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSubpaths = void 0;
|
|
4
4
|
const construct_1 = require("./helpers/construct");
|
|
5
|
+
const serialize_instructions_1 = require("./serialize-instructions");
|
|
5
6
|
/**
|
|
6
7
|
* Splits a valid SVG path into it's parts.
|
|
7
8
|
* @param {string} path A valid SVG path
|
|
@@ -9,10 +10,8 @@ const construct_1 = require("./helpers/construct");
|
|
|
9
10
|
*/
|
|
10
11
|
const getSubpaths = (path) => {
|
|
11
12
|
const { segments } = (0, construct_1.construct)(path);
|
|
12
|
-
return segments
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
})
|
|
16
|
-
.map((_s) => _s.join(' '));
|
|
13
|
+
return segments.map((seg) => {
|
|
14
|
+
return (0, serialize_instructions_1.serializeInstructions)(seg);
|
|
15
|
+
});
|
|
17
16
|
};
|
|
18
17
|
exports.getSubpaths = getSubpaths;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Instruction } from './
|
|
2
|
-
import type { Point, Properties } from './types';
|
|
1
|
+
import type { Instruction, Point, Properties } from './types';
|
|
3
2
|
export declare const construct: (string: string) => {
|
|
4
3
|
segments: Instruction[][];
|
|
5
4
|
initial_point: Point | null;
|