@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/translate-path.js
CHANGED
|
@@ -1,43 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.translatePath = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
return (str + ' ' + seg[0] + ' ' + seg.slice(1).join(' ')).trim();
|
|
8
|
-
}, '');
|
|
9
|
-
};
|
|
10
|
-
const translateSegments = (path, x, y) => {
|
|
11
|
-
const segments = (0, parse_1.parsePath)(path);
|
|
4
|
+
const parse_path_1 = require("./parse-path");
|
|
5
|
+
const serialize_instructions_1 = require("./serialize-instructions");
|
|
6
|
+
const translateSegments = (segments, x, y) => {
|
|
12
7
|
return segments.map((segment) => {
|
|
13
|
-
const cmd = segment[0];
|
|
14
8
|
// Shift coords only for commands with absolute values
|
|
15
|
-
if (
|
|
9
|
+
if (segment.type === 'a' ||
|
|
10
|
+
segment.type === 'c' ||
|
|
11
|
+
segment.type === 'v' ||
|
|
12
|
+
segment.type === 's' ||
|
|
13
|
+
segment.type === 'z' ||
|
|
14
|
+
segment.type === 'h' ||
|
|
15
|
+
segment.type === 'l' ||
|
|
16
|
+
segment.type === 'm' ||
|
|
17
|
+
segment.type === 'q' ||
|
|
18
|
+
segment.type === 't') {
|
|
16
19
|
return segment;
|
|
17
20
|
}
|
|
18
|
-
const name = cmd.toLowerCase();
|
|
19
21
|
// V is the only command, with shifted coords parity
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
if (segment.type === 'V') {
|
|
23
|
+
return {
|
|
24
|
+
type: 'V',
|
|
25
|
+
y: segment.y + y,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (segment.type === 'H') {
|
|
29
|
+
return {
|
|
30
|
+
type: 'H',
|
|
31
|
+
x: segment.x + x,
|
|
32
|
+
};
|
|
23
33
|
}
|
|
24
34
|
// ARC is: ['A', rx, ry, x-axis-rotation, large-arc-flag, sweep-flag, x, y]
|
|
25
35
|
// touch x, y only
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
if (segment.type === 'A') {
|
|
37
|
+
return {
|
|
38
|
+
type: 'A',
|
|
39
|
+
rx: segment.rx,
|
|
40
|
+
ry: segment.ry,
|
|
41
|
+
largeArcFlag: segment.largeArcFlag,
|
|
42
|
+
sweepFlag: segment.sweepFlag,
|
|
43
|
+
xAxisRotation: segment.xAxisRotation,
|
|
44
|
+
x: segment.x + x,
|
|
45
|
+
y: segment.y + y,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (segment.type === 'Z') {
|
|
29
49
|
return segment;
|
|
30
50
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return i % 2 ? val + x : val + (y !== null && y !== void 0 ? y : 0);
|
|
37
|
-
});
|
|
51
|
+
return {
|
|
52
|
+
...segment,
|
|
53
|
+
x: segment.x + x,
|
|
54
|
+
y: segment.y + y,
|
|
55
|
+
};
|
|
38
56
|
});
|
|
39
57
|
};
|
|
40
58
|
const translatePath = (path, x, y) => {
|
|
41
|
-
return
|
|
59
|
+
return (0, serialize_instructions_1.serializeInstructions)(translateSegments((0, parse_path_1.parsePath)(path), x, y));
|
|
42
60
|
};
|
|
43
61
|
exports.translatePath = translatePath;
|
package/dist/unarc.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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");
|
|
4
5
|
const parse_1 = require("./helpers/parse");
|
|
5
6
|
const TAU = Math.PI * 2;
|
|
6
7
|
function approximate_unit_arc(theta1, delta_theta) {
|
|
@@ -79,67 +80,36 @@ function a2c({ x1, y1, x2, y2, fa, fs, rx, ry, phi, }) {
|
|
|
79
80
|
return curve;
|
|
80
81
|
});
|
|
81
82
|
}
|
|
83
|
+
// Requires path to be normalized
|
|
82
84
|
const unarc = (d) => {
|
|
83
85
|
const segments = (0, parse_1.parsePath)(d);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
default:
|
|
138
|
-
throw new Error(`Unexpected instruction ${s[0]}`);
|
|
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]]];
|
|
139
106
|
}
|
|
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;
|
|
140
112
|
});
|
|
141
|
-
const flatted = newSegments.flat(1);
|
|
142
|
-
return flatted;
|
|
143
113
|
};
|
|
144
114
|
exports.unarc = unarc;
|
|
145
115
|
function get_arc_center({ x1, y1, x2, y2, fa, fs, rx, ry, sin_phi, cos_phi, }) {
|
package/dist/unshort.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
|
|
4
5
|
const unshort = function (segments) {
|
|
5
6
|
let prevControlX = 0;
|
|
6
7
|
let prevControlY = 0;
|
|
@@ -21,26 +22,24 @@ const unshort = function (segments) {
|
|
|
21
22
|
}
|
|
22
23
|
case 'V': {
|
|
23
24
|
y = s[1];
|
|
24
|
-
newSegments[i] = s;
|
|
25
25
|
break;
|
|
26
26
|
}
|
|
27
27
|
case 'H': {
|
|
28
28
|
x = s[1];
|
|
29
|
-
newSegments[i] = s;
|
|
30
29
|
break;
|
|
31
30
|
}
|
|
32
31
|
case 'C': {
|
|
33
32
|
x = s[5];
|
|
34
33
|
y = s[6];
|
|
35
|
-
newSegments[i] = s;
|
|
36
34
|
break;
|
|
37
35
|
}
|
|
38
36
|
case 'Q': {
|
|
39
37
|
x = s[3];
|
|
40
38
|
y = s[4];
|
|
41
|
-
newSegments[i] = s;
|
|
42
39
|
break;
|
|
43
40
|
}
|
|
41
|
+
case 'Z':
|
|
42
|
+
break;
|
|
44
43
|
default:
|
|
45
44
|
throw new Error('Unexpected command: ' + s[0]);
|
|
46
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remotion/paths",
|
|
3
|
-
"version": "4.0.0-newpaths.
|
|
3
|
+
"version": "4.0.0-newpaths.40+09405cced",
|
|
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": "
|
|
38
|
+
"gitHead": "09405cced148038402b72b568f349e0bc7bbb949"
|
|
39
39
|
}
|