@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.
@@ -1,43 +1,61 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.translatePath = void 0;
4
- const parse_1 = require("./helpers/parse");
5
- const serialize = (path) => {
6
- return path.reduce((str, seg) => {
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 ('ACHLMRQSTVZ'.indexOf(cmd) === -1) {
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 (name === 'v') {
21
- segment[1] = segment[1] + y;
22
- return segment;
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 (name === 'a') {
27
- segment[6] = segment[6] + x;
28
- segment[7] = segment[7] + (y !== null && y !== void 0 ? y : 0);
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
- // All other commands have [cmd, x1, y1, x2, y2, x3, y3, ...] format
32
- return segment.map((val, i) => {
33
- if (!i) {
34
- return val;
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 serialize(translateSegments(path, x, y));
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
- 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
- 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.13+40cc970bd",
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": "40cc970bd20f2c9fde0c1644f1c9f33cd47f3dc7"
38
+ "gitHead": "09405cced148038402b72b568f349e0bc7bbb949"
39
39
  }