@remotion/captions 4.0.525 → 4.0.527
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 +11 -7
- package/dist/parse-srt.js +13 -7
- package/package.json +2 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -133,7 +133,7 @@ function toSeconds(time) {
|
|
|
133
133
|
if (!third) {
|
|
134
134
|
throw new Error(`Invalid timestamp:${time}`);
|
|
135
135
|
}
|
|
136
|
-
const [seconds, millis] = third.split(
|
|
136
|
+
const [seconds, millis] = third.trim().split(/[,.]/);
|
|
137
137
|
if (!seconds) {
|
|
138
138
|
throw new Error(`Invalid timestamp:${time}`);
|
|
139
139
|
}
|
|
@@ -143,16 +143,18 @@ function toSeconds(time) {
|
|
|
143
143
|
return parseInt(first, 10) * 3600 + parseInt(second, 10) * 60 + parseInt(seconds, 10) + parseInt(millis, 10) / 1000;
|
|
144
144
|
}
|
|
145
145
|
var parseSrt = ({ input }) => {
|
|
146
|
-
const inputLines = input.
|
|
146
|
+
const inputLines = input.replace(/^\uFEFF/, "").replace(/\r\n/g, `
|
|
147
|
+
`).replace(/\r/g, `
|
|
148
|
+
`).split(`
|
|
147
149
|
`);
|
|
148
150
|
const captions = [];
|
|
149
151
|
for (let i = 0;i < inputLines.length; i++) {
|
|
150
152
|
const line = inputLines[i];
|
|
151
153
|
const nextLine = inputLines[i + 1];
|
|
152
|
-
if (line?.match(
|
|
154
|
+
if (line?.match(/^\s*\d+\s*$/) && nextLine?.includes(" --> ")) {
|
|
153
155
|
const nextLineSplit = nextLine.split(" --> ");
|
|
154
|
-
const start = toSeconds(nextLineSplit[0]);
|
|
155
|
-
const end = toSeconds(nextLineSplit[1]);
|
|
156
|
+
const start = toSeconds(nextLineSplit[0].trim());
|
|
157
|
+
const end = toSeconds(nextLineSplit[1].trim());
|
|
156
158
|
captions.push({
|
|
157
159
|
text: "",
|
|
158
160
|
startMs: start * 1000,
|
|
@@ -163,8 +165,10 @@ var parseSrt = ({ input }) => {
|
|
|
163
165
|
} else if (line?.includes(" --> ")) {
|
|
164
166
|
continue;
|
|
165
167
|
} else if (line?.trim() === "") {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
if (captions.length > 0) {
|
|
169
|
+
captions[captions.length - 1].text = captions[captions.length - 1].text.trim();
|
|
170
|
+
}
|
|
171
|
+
} else if (captions.length > 0) {
|
|
168
172
|
captions[captions.length - 1].text += line + `
|
|
169
173
|
`;
|
|
170
174
|
}
|
package/dist/parse-srt.js
CHANGED
|
@@ -12,7 +12,7 @@ function toSeconds(time) {
|
|
|
12
12
|
if (!third) {
|
|
13
13
|
throw new Error(`Invalid timestamp:${time}`);
|
|
14
14
|
}
|
|
15
|
-
const [seconds, millis] = third.split(
|
|
15
|
+
const [seconds, millis] = third.trim().split(/[,.]/);
|
|
16
16
|
if (!seconds) {
|
|
17
17
|
throw new Error(`Invalid timestamp:${time}`);
|
|
18
18
|
}
|
|
@@ -25,15 +25,19 @@ function toSeconds(time) {
|
|
|
25
25
|
parseInt(millis, 10) / 1000);
|
|
26
26
|
}
|
|
27
27
|
const parseSrt = ({ input }) => {
|
|
28
|
-
const inputLines = input
|
|
28
|
+
const inputLines = input
|
|
29
|
+
.replace(/^\uFEFF/, '')
|
|
30
|
+
.replace(/\r\n/g, '\n')
|
|
31
|
+
.replace(/\r/g, '\n')
|
|
32
|
+
.split('\n');
|
|
29
33
|
const captions = [];
|
|
30
34
|
for (let i = 0; i < inputLines.length; i++) {
|
|
31
35
|
const line = inputLines[i];
|
|
32
36
|
const nextLine = inputLines[i + 1];
|
|
33
|
-
if ((line === null || line === void 0 ? void 0 : line.match(
|
|
37
|
+
if ((line === null || line === void 0 ? void 0 : line.match(/^\s*\d+\s*$/)) && (nextLine === null || nextLine === void 0 ? void 0 : nextLine.includes(' --> '))) {
|
|
34
38
|
const nextLineSplit = nextLine.split(' --> ');
|
|
35
|
-
const start = toSeconds(nextLineSplit[0]);
|
|
36
|
-
const end = toSeconds(nextLineSplit[1]);
|
|
39
|
+
const start = toSeconds(nextLineSplit[0].trim());
|
|
40
|
+
const end = toSeconds(nextLineSplit[1].trim());
|
|
37
41
|
captions.push({
|
|
38
42
|
text: '',
|
|
39
43
|
startMs: start * 1000,
|
|
@@ -46,9 +50,11 @@ const parseSrt = ({ input }) => {
|
|
|
46
50
|
continue;
|
|
47
51
|
}
|
|
48
52
|
else if ((line === null || line === void 0 ? void 0 : line.trim()) === '') {
|
|
49
|
-
|
|
53
|
+
if (captions.length > 0) {
|
|
54
|
+
captions[captions.length - 1].text = captions[captions.length - 1].text.trim();
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
|
-
else {
|
|
57
|
+
else if (captions.length > 0) {
|
|
52
58
|
captions[captions.length - 1].text += line + '\n';
|
|
53
59
|
}
|
|
54
60
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/captions"
|
|
4
4
|
},
|
|
5
5
|
"name": "@remotion/captions",
|
|
6
|
-
"version": "4.0.
|
|
6
|
+
"version": "4.0.527",
|
|
7
7
|
"description": "Primitives for dealing with captions",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {},
|
|
24
24
|
"peerDependencies": {},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
26
|
+
"@remotion/eslint-config-internal": "4.0.527",
|
|
27
27
|
"eslint": "9.19.0",
|
|
28
28
|
"@typescript/native-preview": "7.0.0-dev.20260217.1"
|
|
29
29
|
},
|