@remotion/animation-utils 4.0.503 → 4.0.505

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.
@@ -21,124 +21,122 @@ var MODERN_VALUE = "(?:none|[-+]?\\d*\\.?\\d+(?:%|deg|rad|grad|turn)?)";
21
21
  function modernColorCall(name) {
22
22
  return new RegExp(name + "\\(\\s*(" + MODERN_VALUE + ")\\s+(" + MODERN_VALUE + ")\\s+(" + MODERN_VALUE + ")(?:\\s*\\/\\s*(" + MODERN_VALUE + "))?\\s*\\)");
23
23
  }
24
- function getColorMatchers() {
25
- const cachedMatchers = {
26
- rgb: undefined,
27
- rgba: undefined,
28
- hsl: undefined,
29
- hsla: undefined,
30
- hex3: undefined,
31
- hex4: undefined,
32
- hex5: undefined,
33
- hex6: undefined,
34
- hex8: undefined,
35
- oklch: undefined,
36
- oklab: undefined,
37
- lab: undefined,
38
- lch: undefined,
39
- hwb: undefined
40
- };
41
- if (cachedMatchers.rgb === undefined) {
42
- cachedMatchers.rgb = new RegExp("rgb" + call(NUMBER, NUMBER, NUMBER));
43
- cachedMatchers.rgba = new RegExp("rgba" + call(NUMBER, NUMBER, NUMBER, NUMBER));
44
- cachedMatchers.hsl = new RegExp("hsl" + call(NUMBER, PERCENTAGE, PERCENTAGE));
45
- cachedMatchers.hsla = new RegExp("hsla" + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER));
46
- cachedMatchers.hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
47
- cachedMatchers.hex4 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
48
- cachedMatchers.hex6 = /^#([0-9a-fA-F]{6})$/;
49
- cachedMatchers.hex8 = /^#([0-9a-fA-F]{8})$/;
50
- cachedMatchers.oklch = modernColorCall("oklch");
51
- cachedMatchers.oklab = modernColorCall("oklab");
52
- cachedMatchers.lab = modernColorCall("lab");
53
- cachedMatchers.lch = modernColorCall("lch");
54
- cachedMatchers.hwb = modernColorCall("hwb");
55
- }
56
- return cachedMatchers;
57
- }
58
- var extractOrderedPartsOfValue = (value) => {
59
- const parts = [];
60
- let remainingValue = value;
61
- while (remainingValue.length > 0) {
62
- const functionMatch = remainingValue.match(/([a-zA-Z-]+)\(([^)]+)\)/);
63
- if (functionMatch) {
64
- const { index } = functionMatch;
65
- const matchedFunction = functionMatch[0];
66
- if ((index || 0) > 0) {
67
- parts.push(...remainingValue.substring(0, index).trim().split(/\s+/));
68
- }
69
- parts.push(matchedFunction);
70
- remainingValue = remainingValue.substring((index || 0) + matchedFunction.length);
71
- } else {
72
- parts.push(...remainingValue.trim().split(/\s+/));
73
- break;
24
+ var matchers = {
25
+ rgb: new RegExp("rgb" + call(NUMBER, NUMBER, NUMBER)),
26
+ rgba: new RegExp("rgba" + call(NUMBER, NUMBER, NUMBER, NUMBER)),
27
+ hsl: new RegExp("hsl" + call(NUMBER, PERCENTAGE, PERCENTAGE)),
28
+ hsla: new RegExp("hsla" + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER)),
29
+ hex3: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
30
+ hex4: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
31
+ hex5: undefined,
32
+ hex6: /^#([0-9a-fA-F]{6})$/,
33
+ hex8: /^#([0-9a-fA-F]{8})$/,
34
+ oklch: modernColorCall("oklch"),
35
+ oklab: modernColorCall("oklab"),
36
+ lab: modernColorCall("lab"),
37
+ lch: modernColorCall("lch"),
38
+ hwb: modernColorCall("hwb")
39
+ };
40
+ var namedColors = new Set(Object.keys(NoReactInternals.colorNames));
41
+ var numberUnitRegex = /^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/;
42
+ var functionGlobalRegex = /([a-zA-Z-]+)\(([^)]+)\)/g;
43
+ var isColorFunction = (name, fullValue) => {
44
+ const c0 = name.charCodeAt(0);
45
+ if (c0 === 114) {
46
+ if (name === "rgb")
47
+ return matchers.rgb.test(fullValue);
48
+ if (name === "rgba")
49
+ return matchers.rgba.test(fullValue);
50
+ } else if (c0 === 104) {
51
+ if (name === "hsl")
52
+ return matchers.hsl.test(fullValue);
53
+ if (name === "hsla")
54
+ return matchers.hsla.test(fullValue);
55
+ if (name === "hwb")
56
+ return matchers.hwb.test(fullValue);
57
+ } else if (c0 === 111) {
58
+ if (name === "oklch")
59
+ return matchers.oklch.test(fullValue);
60
+ if (name === "oklab")
61
+ return matchers.oklab.test(fullValue);
62
+ } else if (c0 === 108) {
63
+ if (name === "lab")
64
+ return matchers.lab.test(fullValue);
65
+ if (name === "lch")
66
+ return matchers.lch.test(fullValue);
67
+ }
68
+ return false;
69
+ };
70
+ var getTrimmed = (s, start, end) => {
71
+ while (start < end && s.charCodeAt(start) <= 32)
72
+ start++;
73
+ while (end > start && s.charCodeAt(end - 1) <= 32)
74
+ end--;
75
+ return s.substring(start, end);
76
+ };
77
+ var classifyArg = (val) => {
78
+ const c0 = val.charCodeAt(0);
79
+ if (c0 >= 48 && c0 <= 57 || c0 === 45) {
80
+ const match = numberUnitRegex.exec(val);
81
+ if (match) {
82
+ const number = Number(match[1]);
83
+ const unit = match[2];
84
+ return unit ? { number, unit } : { number };
74
85
  }
75
86
  }
76
- return parts.filter((part) => part !== "");
87
+ return { unit: val };
77
88
  };
78
89
  var classifyArgsOfFunction = (value) => {
90
+ const result = [];
79
91
  let nestedLevel = 0;
80
- const values = [];
81
- let currentValue = "";
82
- for (const char of value) {
83
- if (char === "(")
92
+ let start = 0;
93
+ const len = value.length;
94
+ for (let i = 0;i < len; i++) {
95
+ const code = value.charCodeAt(i);
96
+ if (code === 40) {
84
97
  nestedLevel++;
85
- else if (char === ")")
98
+ } else if (code === 41) {
86
99
  nestedLevel--;
87
- if (char === "," && nestedLevel === 0) {
88
- values.push(currentValue.trim());
89
- currentValue = "";
90
- } else {
91
- currentValue += char;
100
+ } else if (code === 44 && nestedLevel === 0) {
101
+ result.push(classifyArg(getTrimmed(value, start, i)));
102
+ start = i + 1;
92
103
  }
93
104
  }
94
- if (currentValue)
95
- values.push(currentValue.trim());
96
- return values.map((val) => {
97
- const numberUnitMatch = val.match(/^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
98
- if (numberUnitMatch) {
99
- const number = parseFloat(numberUnitMatch[1]);
100
- const unit = numberUnitMatch[2];
101
- return unit ? { number, unit } : { number };
102
- }
103
- const numberMatch = val.match(/^(\d+(?:\.\d+)?)$/);
104
- if (numberMatch) {
105
- const number = parseFloat(numberMatch[1]);
106
- return { number };
107
- }
108
- return { unit: val };
109
- });
110
- };
111
- var isColorValue = (value) => {
112
- if (Object.keys(NoReactInternals.colorNames).includes(value)) {
113
- return true;
105
+ const last = getTrimmed(value, start, len);
106
+ if (last) {
107
+ result.push(classifyArg(last));
114
108
  }
115
- const matchers = getColorMatchers();
116
- return matchers.rgb?.test(value) || matchers.rgba?.test(value) || matchers.hsl?.test(value) || matchers.hsla?.test(value) || matchers.hex3?.test(value) || matchers.hex4?.test(value) || matchers.hex5?.test(value) || matchers.hex6?.test(value) || matchers.hex8?.test(value) || matchers.oklch?.test(value) || matchers.oklab?.test(value) || matchers.lab?.test(value) || matchers.lch?.test(value) || matchers.hwb?.test(value);
109
+ return result;
117
110
  };
118
- var classifyParts = (parts) => {
119
- return parts.map((part) => {
120
- if (isColorValue(part)) {
121
- return { color: part };
122
- }
123
- const functionMatch = part.match(/([a-zA-Z-]+)\(([^)]+)\)/);
124
- if (functionMatch) {
125
- const functionName = functionMatch[1];
126
- const functionValues = classifyArgsOfFunction(functionMatch[2]);
127
- return { function: { name: functionName, values: functionValues } };
111
+ var classifyNonFunctionPart = (token) => {
112
+ const c0 = token.charCodeAt(0);
113
+ if (c0 === 35) {
114
+ const len = token.length;
115
+ if (len === 4 || len === 5 || len === 7 || len === 9) {
116
+ let valid = true;
117
+ for (let j = 1;j < len; j++) {
118
+ const c = token.charCodeAt(j);
119
+ if (!(c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102)) {
120
+ valid = false;
121
+ break;
122
+ }
123
+ }
124
+ if (valid)
125
+ return { color: token };
128
126
  }
129
- const numberUnitMatch = part.match(/^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
130
- if (numberUnitMatch) {
131
- const number = parseFloat(numberUnitMatch[1]);
132
- const unit = numberUnitMatch[2];
127
+ } else if (c0 >= 97 && c0 <= 122) {
128
+ if (namedColors.has(token))
129
+ return { color: token };
130
+ }
131
+ if (c0 >= 48 && c0 <= 57 || c0 === 45) {
132
+ const match = numberUnitRegex.exec(token);
133
+ if (match) {
134
+ const number = Number(match[1]);
135
+ const unit = match[2];
133
136
  return unit ? { number, unit } : { number };
134
137
  }
135
- const numberMatch = part.match(/^(-?\d+(?:\.\d+)?)$/);
136
- if (numberMatch) {
137
- const number = parseFloat(numberMatch[1]);
138
- return { number };
139
- }
140
- return { unit: part };
141
- });
138
+ }
139
+ return { unit: token };
142
140
  };
143
141
  var breakDownValueIntoUnitNumberAndFunctions = (value) => {
144
142
  if (typeof value === "number") {
@@ -147,8 +145,54 @@ var breakDownValueIntoUnitNumberAndFunctions = (value) => {
147
145
  if (typeof value !== "string") {
148
146
  return [];
149
147
  }
150
- const valueParts = extractOrderedPartsOfValue(value);
151
- return classifyParts(valueParts);
148
+ const result = [];
149
+ let lastIndex = 0;
150
+ functionGlobalRegex.lastIndex = 0;
151
+ let match;
152
+ while ((match = functionGlobalRegex.exec(value)) !== null) {
153
+ const { index } = match;
154
+ if (index > lastIndex) {
155
+ let cursor = lastIndex;
156
+ while (cursor < index) {
157
+ while (cursor < index && value.charCodeAt(cursor) <= 32)
158
+ cursor++;
159
+ if (cursor >= index)
160
+ break;
161
+ let end = cursor;
162
+ while (end < index && value.charCodeAt(end) > 32)
163
+ end++;
164
+ result.push(classifyNonFunctionPart(value.substring(cursor, end)));
165
+ cursor = end;
166
+ }
167
+ }
168
+ const fullFunction = match[0];
169
+ const name = match[1];
170
+ if (isColorFunction(name, fullFunction)) {
171
+ result.push({ color: fullFunction });
172
+ } else {
173
+ result.push({
174
+ function: {
175
+ name,
176
+ values: classifyArgsOfFunction(match[2])
177
+ }
178
+ });
179
+ }
180
+ lastIndex = functionGlobalRegex.lastIndex;
181
+ }
182
+ const len = value.length;
183
+ let i = lastIndex;
184
+ while (i < len) {
185
+ while (i < len && value.charCodeAt(i) <= 32)
186
+ i++;
187
+ if (i >= len)
188
+ break;
189
+ let end = i;
190
+ while (end < len && value.charCodeAt(end) > 32)
191
+ end++;
192
+ result.push(classifyNonFunctionPart(value.substring(i, end)));
193
+ i = end;
194
+ }
195
+ return result;
152
196
  };
153
197
 
154
198
  // src/transformation-helpers/interpolate-styles/index.tsx
@@ -1,41 +1,13 @@
1
1
  import type { ColorMatchers, CSSPropertiesValue } from '../../type';
2
- declare function getColorMatchers(): ColorMatchers;
3
- declare const breakDownValueIntoUnitNumberAndFunctions: (value: CSSPropertiesValue) => ({
4
- number?: undefined;
5
- unit?: undefined;
6
- color: string;
7
- function?: undefined;
8
- } | {
9
- number?: undefined;
10
- unit?: undefined;
11
- color?: undefined;
12
- function: {
2
+ declare const getColorMatchers: () => ColorMatchers;
3
+ type ClassifiedValue = {
4
+ color?: string;
5
+ number?: number;
6
+ unit?: string;
7
+ function?: {
13
8
  name: string;
14
- values: ({
15
- number: number;
16
- unit: string;
17
- } | {
18
- number: number;
19
- unit?: undefined;
20
- } | {
21
- number?: undefined;
22
- unit: string;
23
- })[];
9
+ values: ClassifiedValue[];
24
10
  };
25
- } | {
26
- color?: undefined;
27
- function?: undefined;
28
- number: number;
29
- unit: string;
30
- } | {
31
- unit?: undefined;
32
- color?: undefined;
33
- function?: undefined;
34
- number: number;
35
- } | {
36
- number?: undefined;
37
- color?: undefined;
38
- function?: undefined;
39
- unit: string;
40
- })[];
11
+ };
12
+ declare const breakDownValueIntoUnitNumberAndFunctions: (value: CSSPropertiesValue) => ClassifiedValue[];
41
13
  export { breakDownValueIntoUnitNumberAndFunctions, getColorMatchers };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.breakDownValueIntoUnitNumberAndFunctions = void 0;
4
- exports.getColorMatchers = getColorMatchers;
3
+ exports.getColorMatchers = exports.breakDownValueIntoUnitNumberAndFunctions = void 0;
5
4
  const no_react_1 = require("remotion/no-react");
6
5
  const constants_1 = require("./constants");
7
6
  function call(...args) {
@@ -20,150 +19,136 @@ function modernColorCall(name) {
20
19
  MODERN_VALUE +
21
20
  '))?\\s*\\)');
22
21
  }
23
- function getColorMatchers() {
24
- const cachedMatchers = {
25
- rgb: undefined,
26
- rgba: undefined,
27
- hsl: undefined,
28
- hsla: undefined,
29
- hex3: undefined,
30
- hex4: undefined,
31
- hex5: undefined,
32
- hex6: undefined,
33
- hex8: undefined,
34
- oklch: undefined,
35
- oklab: undefined,
36
- lab: undefined,
37
- lch: undefined,
38
- hwb: undefined,
39
- };
40
- if (cachedMatchers.rgb === undefined) {
41
- cachedMatchers.rgb = new RegExp('rgb' + call(constants_1.NUMBER, constants_1.NUMBER, constants_1.NUMBER));
42
- cachedMatchers.rgba = new RegExp('rgba' + call(constants_1.NUMBER, constants_1.NUMBER, constants_1.NUMBER, constants_1.NUMBER));
43
- cachedMatchers.hsl = new RegExp('hsl' + call(constants_1.NUMBER, constants_1.PERCENTAGE, constants_1.PERCENTAGE));
44
- cachedMatchers.hsla = new RegExp('hsla' + call(constants_1.NUMBER, constants_1.PERCENTAGE, constants_1.PERCENTAGE, constants_1.NUMBER));
45
- cachedMatchers.hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
46
- cachedMatchers.hex4 =
47
- /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
48
- cachedMatchers.hex6 = /^#([0-9a-fA-F]{6})$/;
49
- cachedMatchers.hex8 = /^#([0-9a-fA-F]{8})$/;
50
- cachedMatchers.oklch = modernColorCall('oklch');
51
- cachedMatchers.oklab = modernColorCall('oklab');
52
- cachedMatchers.lab = modernColorCall('lab');
53
- cachedMatchers.lch = modernColorCall('lch');
54
- cachedMatchers.hwb = modernColorCall('hwb');
22
+ const matchers = {
23
+ rgb: new RegExp('rgb' + call(constants_1.NUMBER, constants_1.NUMBER, constants_1.NUMBER)),
24
+ rgba: new RegExp('rgba' + call(constants_1.NUMBER, constants_1.NUMBER, constants_1.NUMBER, constants_1.NUMBER)),
25
+ hsl: new RegExp('hsl' + call(constants_1.NUMBER, constants_1.PERCENTAGE, constants_1.PERCENTAGE)),
26
+ hsla: new RegExp('hsla' + call(constants_1.NUMBER, constants_1.PERCENTAGE, constants_1.PERCENTAGE, constants_1.NUMBER)),
27
+ hex3: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
28
+ hex4: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
29
+ hex5: undefined,
30
+ hex6: /^#([0-9a-fA-F]{6})$/,
31
+ hex8: /^#([0-9a-fA-F]{8})$/,
32
+ oklch: modernColorCall('oklch'),
33
+ oklab: modernColorCall('oklab'),
34
+ lab: modernColorCall('lab'),
35
+ lch: modernColorCall('lch'),
36
+ hwb: modernColorCall('hwb'),
37
+ };
38
+ const namedColors = new Set(Object.keys(no_react_1.NoReactInternals.colorNames));
39
+ const numberUnitRegex = /^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/;
40
+ const functionGlobalRegex = /([a-zA-Z-]+)\(([^)]+)\)/g;
41
+ const getColorMatchers = () => matchers;
42
+ exports.getColorMatchers = getColorMatchers;
43
+ const isColorFunction = (name, fullValue) => {
44
+ const c0 = name.charCodeAt(0);
45
+ if (c0 === 114) {
46
+ // r
47
+ if (name === 'rgb')
48
+ return matchers.rgb.test(fullValue);
49
+ if (name === 'rgba')
50
+ return matchers.rgba.test(fullValue);
55
51
  }
56
- return cachedMatchers;
57
- }
58
- const extractOrderedPartsOfValue = (value) => {
59
- const parts = [];
60
- let remainingValue = value;
61
- while (remainingValue.length > 0) {
62
- const functionMatch = remainingValue.match(/([a-zA-Z-]+)\(([^)]+)\)/);
63
- // If there's a function, add it to the parts and remove it from the remaining value
64
- if (functionMatch) {
65
- const { index } = functionMatch;
66
- const matchedFunction = functionMatch[0];
67
- // Add any parts before the function
68
- if ((index || 0) > 0) {
69
- parts.push(...remainingValue.substring(0, index).trim().split(/\s+/));
70
- }
71
- parts.push(matchedFunction);
72
- remainingValue = remainingValue.substring((index || 0) + matchedFunction.length);
73
- }
74
- else {
75
- // If there's no function, add the remaining value to the parts
76
- parts.push(...remainingValue.trim().split(/\s+/));
77
- break;
52
+ else if (c0 === 104) {
53
+ // h
54
+ if (name === 'hsl')
55
+ return matchers.hsl.test(fullValue);
56
+ if (name === 'hsla')
57
+ return matchers.hsla.test(fullValue);
58
+ if (name === 'hwb')
59
+ return matchers.hwb.test(fullValue);
60
+ }
61
+ else if (c0 === 111) {
62
+ // o
63
+ if (name === 'oklch')
64
+ return matchers.oklch.test(fullValue);
65
+ if (name === 'oklab')
66
+ return matchers.oklab.test(fullValue);
67
+ }
68
+ else if (c0 === 108) {
69
+ // l
70
+ if (name === 'lab')
71
+ return matchers.lab.test(fullValue);
72
+ if (name === 'lch')
73
+ return matchers.lch.test(fullValue);
74
+ }
75
+ return false;
76
+ };
77
+ const getTrimmed = (s, start, end) => {
78
+ while (start < end && s.charCodeAt(start) <= 32)
79
+ start++;
80
+ while (end > start && s.charCodeAt(end - 1) <= 32)
81
+ end--;
82
+ return s.substring(start, end);
83
+ };
84
+ const classifyArg = (val) => {
85
+ const c0 = val.charCodeAt(0);
86
+ if ((c0 >= 48 && c0 <= 57) || c0 === 45) {
87
+ const match = numberUnitRegex.exec(val);
88
+ if (match) {
89
+ const number = Number(match[1]);
90
+ const unit = match[2];
91
+ return unit ? { number, unit } : { number };
78
92
  }
79
93
  }
80
- return parts.filter((part) => part !== ''); // Filter out any empty strings
94
+ return { unit: val };
81
95
  };
82
96
  const classifyArgsOfFunction = (value) => {
97
+ const result = [];
83
98
  let nestedLevel = 0;
84
- const values = [];
85
- let currentValue = '';
86
- for (const char of value) {
87
- if (char === '(')
99
+ let start = 0;
100
+ const len = value.length;
101
+ for (let i = 0; i < len; i++) {
102
+ const code = value.charCodeAt(i);
103
+ if (code === 40) {
88
104
  nestedLevel++;
89
- else if (char === ')')
105
+ }
106
+ else if (code === 41) {
90
107
  nestedLevel--;
91
- if (char === ',' && nestedLevel === 0) {
92
- values.push(currentValue.trim());
93
- currentValue = '';
94
108
  }
95
- else {
96
- currentValue += char;
109
+ else if (code === 44 && nestedLevel === 0) {
110
+ result.push(classifyArg(getTrimmed(value, start, i)));
111
+ start = i + 1;
97
112
  }
98
113
  }
99
- if (currentValue)
100
- values.push(currentValue.trim());
101
- // Classify each value
102
- return values.map((val) => {
103
- const numberUnitMatch = val.match(/^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
104
- if (numberUnitMatch) {
105
- const number = parseFloat(numberUnitMatch[1]);
106
- const unit = numberUnitMatch[2];
107
- return unit ? { number, unit } : { number };
108
- }
109
- const numberMatch = val.match(/^(\d+(?:\.\d+)?)$/);
110
- if (numberMatch) {
111
- const number = parseFloat(numberMatch[1]);
112
- return { number };
113
- }
114
- return { unit: val };
115
- });
116
- };
117
- const isColorValue = (value) => {
118
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
119
- if (Object.keys(no_react_1.NoReactInternals.colorNames).includes(value)) {
120
- return true;
114
+ const last = getTrimmed(value, start, len);
115
+ if (last) {
116
+ result.push(classifyArg(last));
121
117
  }
122
- const matchers = getColorMatchers();
123
- return (((_a = matchers.rgb) === null || _a === void 0 ? void 0 : _a.test(value)) ||
124
- ((_b = matchers.rgba) === null || _b === void 0 ? void 0 : _b.test(value)) ||
125
- ((_c = matchers.hsl) === null || _c === void 0 ? void 0 : _c.test(value)) ||
126
- ((_d = matchers.hsla) === null || _d === void 0 ? void 0 : _d.test(value)) ||
127
- ((_e = matchers.hex3) === null || _e === void 0 ? void 0 : _e.test(value)) ||
128
- ((_f = matchers.hex4) === null || _f === void 0 ? void 0 : _f.test(value)) ||
129
- ((_g = matchers.hex5) === null || _g === void 0 ? void 0 : _g.test(value)) ||
130
- ((_h = matchers.hex6) === null || _h === void 0 ? void 0 : _h.test(value)) ||
131
- ((_j = matchers.hex8) === null || _j === void 0 ? void 0 : _j.test(value)) ||
132
- ((_k = matchers.oklch) === null || _k === void 0 ? void 0 : _k.test(value)) ||
133
- ((_l = matchers.oklab) === null || _l === void 0 ? void 0 : _l.test(value)) ||
134
- ((_m = matchers.lab) === null || _m === void 0 ? void 0 : _m.test(value)) ||
135
- ((_o = matchers.lch) === null || _o === void 0 ? void 0 : _o.test(value)) ||
136
- ((_p = matchers.hwb) === null || _p === void 0 ? void 0 : _p.test(value)));
118
+ return result;
137
119
  };
138
- const classifyParts = (parts) => {
139
- return parts.map((part) => {
140
- // Check for a color value like 'red', 'rgba(0, 0, 0, 0)', '#fff', etc.
141
- if (isColorValue(part)) {
142
- return { color: part };
143
- }
144
- // Check for a function like 'translateX(10px)' or 'rotate(90deg)'
145
- const functionMatch = part.match(/([a-zA-Z-]+)\(([^)]+)\)/);
146
- if (functionMatch) {
147
- const functionName = functionMatch[1];
148
- const functionValues = classifyArgsOfFunction(functionMatch[2]);
149
- return { function: { name: functionName, values: functionValues } };
120
+ const classifyNonFunctionPart = (token) => {
121
+ const c0 = token.charCodeAt(0);
122
+ if (c0 === 35) {
123
+ const len = token.length;
124
+ if (len === 4 || len === 5 || len === 7 || len === 9) {
125
+ let valid = true;
126
+ for (let j = 1; j < len; j++) {
127
+ const c = token.charCodeAt(j);
128
+ if (!((c >= 48 && c <= 57) ||
129
+ (c >= 65 && c <= 70) ||
130
+ (c >= 97 && c <= 102))) {
131
+ valid = false;
132
+ break;
133
+ }
134
+ }
135
+ if (valid)
136
+ return { color: token };
150
137
  }
151
- // Check for a number possibly followed by a unit like '10px' or '10' or '-10px'
152
- const numberUnitMatch = part.match(/^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
153
- if (numberUnitMatch) {
154
- const number = parseFloat(numberUnitMatch[1]);
155
- const unit = numberUnitMatch[2];
138
+ }
139
+ else if (c0 >= 97 && c0 <= 122) {
140
+ if (namedColors.has(token))
141
+ return { color: token };
142
+ }
143
+ if ((c0 >= 48 && c0 <= 57) || c0 === 45) {
144
+ const match = numberUnitRegex.exec(token);
145
+ if (match) {
146
+ const number = Number(match[1]);
147
+ const unit = match[2];
156
148
  return unit ? { number, unit } : { number };
157
149
  }
158
- // Check for a number without a unit like '10' or '-10'
159
- const numberMatch = part.match(/^(-?\d+(?:\.\d+)?)$/);
160
- if (numberMatch) {
161
- const number = parseFloat(numberMatch[1]);
162
- return { number };
163
- }
164
- // If neither, treat as a unit (like 'solid', 'none', etc.)
165
- return { unit: part };
166
- });
150
+ }
151
+ return { unit: token };
167
152
  };
168
153
  const breakDownValueIntoUnitNumberAndFunctions = (value) => {
169
154
  if (typeof value === 'number') {
@@ -172,7 +157,54 @@ const breakDownValueIntoUnitNumberAndFunctions = (value) => {
172
157
  if (typeof value !== 'string') {
173
158
  return [];
174
159
  }
175
- const valueParts = extractOrderedPartsOfValue(value);
176
- return classifyParts(valueParts);
160
+ const result = [];
161
+ let lastIndex = 0;
162
+ functionGlobalRegex.lastIndex = 0;
163
+ let match;
164
+ while ((match = functionGlobalRegex.exec(value)) !== null) {
165
+ const { index } = match;
166
+ if (index > lastIndex) {
167
+ let cursor = lastIndex;
168
+ while (cursor < index) {
169
+ while (cursor < index && value.charCodeAt(cursor) <= 32)
170
+ cursor++;
171
+ if (cursor >= index)
172
+ break;
173
+ let end = cursor;
174
+ while (end < index && value.charCodeAt(end) > 32)
175
+ end++;
176
+ result.push(classifyNonFunctionPart(value.substring(cursor, end)));
177
+ cursor = end;
178
+ }
179
+ }
180
+ const fullFunction = match[0];
181
+ const name = match[1];
182
+ if (isColorFunction(name, fullFunction)) {
183
+ result.push({ color: fullFunction });
184
+ }
185
+ else {
186
+ result.push({
187
+ function: {
188
+ name,
189
+ values: classifyArgsOfFunction(match[2]),
190
+ },
191
+ });
192
+ }
193
+ lastIndex = functionGlobalRegex.lastIndex;
194
+ }
195
+ const len = value.length;
196
+ let i = lastIndex;
197
+ while (i < len) {
198
+ while (i < len && value.charCodeAt(i) <= 32)
199
+ i++;
200
+ if (i >= len)
201
+ break;
202
+ let end = i;
203
+ while (end < len && value.charCodeAt(end) > 32)
204
+ end++;
205
+ result.push(classifyNonFunctionPart(value.substring(i, end)));
206
+ i = end;
207
+ }
208
+ return result;
177
209
  };
178
210
  exports.breakDownValueIntoUnitNumberAndFunctions = breakDownValueIntoUnitNumberAndFunctions;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "name": "Chetan Karwa",
8
8
  "email": "cbkarwa@gmail.com"
9
9
  },
10
- "version": "4.0.503",
10
+ "version": "4.0.505",
11
11
  "description": "Helpers for animating CSS properties",
12
12
  "main": "./dist/index.js",
13
13
  "module": "./dist/index.mjs",
@@ -20,7 +20,7 @@
20
20
  "test": "bun test src"
21
21
  },
22
22
  "dependencies": {
23
- "remotion": "4.0.503"
23
+ "remotion": "4.0.505"
24
24
  },
25
25
  "files": [
26
26
  "dist",
@@ -31,7 +31,7 @@
31
31
  "react-dom": ">=16.8.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@remotion/eslint-config-internal": "4.0.503",
34
+ "@remotion/eslint-config-internal": "4.0.505",
35
35
  "eslint": "9.19.0",
36
36
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
37
37
  },