@remotion/paths 4.0.526 → 4.0.528

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.
@@ -1144,9 +1144,31 @@ var makeInstructions = (arr, instruction, cb) => {
1144
1144
  };
1145
1145
  var segmentRegExp = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
1146
1146
  var numberRegExp = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
1147
+ var arcNumberRegExp = /[\s,]*([-+]?(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:e[-+]?\d+)?)/iy;
1148
+ var arcFlagRegExp = /[\s,]*([01])/y;
1147
1149
  var parseValues = (args, instructionType) => {
1148
- const numbers = args.match(numberRegExp);
1149
- if (!numbers) {
1150
+ let numbers;
1151
+ if (instructionType === "A" || instructionType === "a") {
1152
+ numbers = [];
1153
+ let match;
1154
+ let lastIndex = 0;
1155
+ do {
1156
+ const regExp = numbers.length % 7 === 3 || numbers.length % 7 === 4 ? arcFlagRegExp : arcNumberRegExp;
1157
+ regExp.lastIndex = lastIndex;
1158
+ match = regExp.exec(args);
1159
+ if (match) {
1160
+ numbers.push(match[1]);
1161
+ lastIndex = regExp.lastIndex;
1162
+ }
1163
+ } while (match);
1164
+ const rest = args.slice(lastIndex);
1165
+ if (!/^[\s,]*$/.test(rest)) {
1166
+ throw new Error(`Malformed path data: ${instructionType} has an invalid value at "${rest.trim()}"`);
1167
+ }
1168
+ } else {
1169
+ numbers = args.match(numberRegExp);
1170
+ }
1171
+ if (!numbers || numbers.length === 0) {
1150
1172
  if (instructionType === "Z" || instructionType === "z") {
1151
1173
  return [];
1152
1174
  }
@@ -1788,8 +1810,8 @@ var normalizeInstructions = (instructions) => {
1788
1810
  moveX = instruction.x;
1789
1811
  moveY = instruction.y;
1790
1812
  } else if (instruction.type === "m") {
1791
- moveX += instruction.dx;
1792
- moveY += instruction.dy;
1813
+ moveX = x + instruction.dx;
1814
+ moveY = y + instruction.dy;
1793
1815
  }
1794
1816
  if (instruction.type === "A" || instruction.type === "C" || instruction.type === "L" || instruction.type === "M" || instruction.type === "Q" || instruction.type === "S" || instruction.type === "T") {
1795
1817
  normalized.push(instruction);
@@ -17,8 +17,8 @@ const normalizeInstructions = (instructions) => {
17
17
  moveY = instruction.y;
18
18
  }
19
19
  else if (instruction.type === 'm') {
20
- moveX += instruction.dx;
21
- moveY += instruction.dy;
20
+ moveX = x + instruction.dx;
21
+ moveY = y + instruction.dy;
22
22
  }
23
23
  if (instruction.type === 'A' ||
24
24
  instruction.type === 'C' ||
@@ -42,9 +42,36 @@ const makeInstructions = (arr, instruction, cb) => {
42
42
  };
43
43
  const segmentRegExp = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
44
44
  const numberRegExp = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
45
+ const arcNumberRegExp = /[\s,]*([-+]?(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:e[-+]?\d+)?)/iy;
46
+ const arcFlagRegExp = /[\s,]*([01])/y;
45
47
  const parseValues = (args, instructionType) => {
46
- const numbers = args.match(numberRegExp);
47
- if (!numbers) {
48
+ let numbers;
49
+ if (instructionType === 'A' || instructionType === 'a') {
50
+ // Arc flags are a single "0" or "1" and don't need a separator,
51
+ // e.g. "A1 1 0 011 1" (https://www.w3.org/TR/SVG2/paths.html#PathDataBNF)
52
+ numbers = [];
53
+ let match;
54
+ let lastIndex = 0;
55
+ do {
56
+ const regExp = numbers.length % 7 === 3 || numbers.length % 7 === 4
57
+ ? arcFlagRegExp
58
+ : arcNumberRegExp;
59
+ regExp.lastIndex = lastIndex;
60
+ match = regExp.exec(args);
61
+ if (match) {
62
+ numbers.push(match[1]);
63
+ lastIndex = regExp.lastIndex;
64
+ }
65
+ } while (match);
66
+ const rest = args.slice(lastIndex);
67
+ if (!/^[\s,]*$/.test(rest)) {
68
+ throw new Error(`Malformed path data: ${instructionType} has an invalid value at "${rest.trim()}"`);
69
+ }
70
+ }
71
+ else {
72
+ numbers = args.match(numberRegExp);
73
+ }
74
+ if (!numbers || numbers.length === 0) {
48
75
  if (instructionType === 'Z' || instructionType === 'z') {
49
76
  return [];
50
77
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/paths"
4
4
  },
5
5
  "name": "@remotion/paths",
6
- "version": "4.0.526",
6
+ "version": "4.0.528",
7
7
  "description": "Utilities for working with SVG paths",
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "utilities"
27
27
  ],
28
28
  "devDependencies": {
29
- "@remotion/eslint-config-internal": "4.0.526",
29
+ "@remotion/eslint-config-internal": "4.0.528",
30
30
  "eslint": "9.19.0",
31
31
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
32
32
  },