@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.
package/dist/esm/index.mjs
CHANGED
|
@@ -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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
87
|
+
return { unit: val };
|
|
77
88
|
};
|
|
78
89
|
var classifyArgsOfFunction = (value) => {
|
|
90
|
+
const result = [];
|
|
79
91
|
let nestedLevel = 0;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
for (
|
|
83
|
-
|
|
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 (
|
|
98
|
+
} else if (code === 41) {
|
|
86
99
|
nestedLevel--;
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
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
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
136
|
-
|
|
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
|
|
151
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function?:
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
94
|
+
return { unit: val };
|
|
81
95
|
};
|
|
82
96
|
const classifyArgsOfFunction = (value) => {
|
|
97
|
+
const result = [];
|
|
83
98
|
let nestedLevel = 0;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
for (
|
|
87
|
-
|
|
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
|
-
|
|
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
|
-
|
|
109
|
+
else if (code === 44 && nestedLevel === 0) {
|
|
110
|
+
result.push(classifyArg(getTrimmed(value, start, i)));
|
|
111
|
+
start = i + 1;
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
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
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
159
|
-
|
|
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
|
|
176
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
},
|