@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,9 +1,9 @@
1
- 'use strict';
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 unarc_1 = require("./unarc");
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 abs = (0, normalize_path_1.normalizePath)(d);
76
- const unarced = (0, unarc_1.unarc)(abs);
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 unshortened) {
81
- switch (seg[0]) {
79
+ for (const seg of unarced) {
80
+ switch (seg.type) {
82
81
  case 'M':
83
82
  case 'L': {
84
- if (minX > seg[1]) {
85
- minX = seg[1];
83
+ if (minX > seg.x) {
84
+ minX = seg.x;
86
85
  }
87
- if (minY > seg[2]) {
88
- minY = seg[2];
86
+ if (minY > seg.y) {
87
+ minY = seg.y;
89
88
  }
90
- if (maxX < seg[1]) {
91
- maxX = seg[1];
89
+ if (maxX < seg.x) {
90
+ maxX = seg.x;
92
91
  }
93
- if (maxY < seg[2]) {
94
- maxY = seg[2];
92
+ if (maxY < seg.y) {
93
+ maxY = seg.y;
95
94
  }
96
- x = seg[1];
97
- y = seg[2];
95
+ x = seg.x;
96
+ y = seg.y;
98
97
  break;
99
98
  }
100
99
  case 'V': {
101
- if (minY > seg[1]) {
102
- minY = seg[1];
100
+ if (minY > seg.y) {
101
+ minY = seg.y;
103
102
  }
104
- if (maxY < seg[1]) {
105
- maxY = seg[1];
103
+ if (maxY < seg.y) {
104
+ maxY = seg.y;
106
105
  }
107
- y = seg[1];
106
+ y = seg.y;
108
107
  break;
109
108
  }
110
109
  case 'H': {
111
- if (minX > seg[1]) {
112
- minX = seg[1];
110
+ if (minX > seg.x) {
111
+ minX = seg.x;
113
112
  }
114
- if (maxX < seg[1]) {
115
- maxX = seg[1];
113
+ if (maxX < seg.x) {
114
+ maxX = seg.x;
116
115
  }
117
- x = seg[1];
116
+ x = seg.x;
118
117
  break;
119
118
  }
120
119
  case 'C': {
121
- const cxMinMax = minmaxC([x, seg[1], seg[3], seg[5]]);
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[2], seg[4], seg[6]]);
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[5];
136
- y = seg[6];
134
+ x = seg.x;
135
+ y = seg.y;
137
136
  break;
138
137
  }
139
138
  case 'Q': {
140
- const qxMinMax = minmaxQ([x, seg[1], seg[3]]);
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[2], seg[4]]);
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[3];
155
- y = seg[4];
153
+ x = seg.x;
154
+ y = seg.y;
156
155
  break;
157
156
  }
157
+ case 'Z':
158
+ break;
158
159
  default:
159
- throw new Error(`Unknown instruction ${seg[0]}`);
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 };
@@ -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
- .map((seg) => {
14
- return seg.map((s) => s.join(' '));
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 './parse';
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;