@remotion/captions 4.0.527 → 4.0.529

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.
@@ -9,7 +9,7 @@ const splitWords = (inputCaptions) => {
9
9
  for (let j = 0; j < words.length; j++) {
10
10
  const word = words[j];
11
11
  captions.push({
12
- text: j === 0 ? ` ${word}` : word,
12
+ text: ` ${word}`,
13
13
  startMs: w.startMs,
14
14
  endMs: w.endMs,
15
15
  confidence: w.confidence,
@@ -35,8 +35,9 @@ const ensureMaxCharactersPerLine = ({ captions, maxCharsPerLine, }) => {
35
35
  const preventOrphanWord = remainingWords.length < 4 &&
36
36
  remainingWords.length > 1 &&
37
37
  filledCharactersInLine > maxCharsPerLine / 2;
38
- if (filledCharactersInLine + w.text.length > maxCharsPerLine ||
39
- preventOrphanWord) {
38
+ if (currentSegment.length > 0 &&
39
+ (filledCharactersInLine + w.text.length > maxCharsPerLine ||
40
+ preventOrphanWord)) {
40
41
  segments.push(currentSegment);
41
42
  currentSegment = [];
42
43
  }
@@ -7,7 +7,7 @@ var splitWords = (inputCaptions) => {
7
7
  for (let j = 0;j < words.length; j++) {
8
8
  const word = words[j];
9
9
  captions.push({
10
- text: j === 0 ? ` ${word}` : word,
10
+ text: ` ${word}`,
11
11
  startMs: w.startMs,
12
12
  endMs: w.endMs,
13
13
  confidence: w.confidence,
@@ -30,7 +30,7 @@ var ensureMaxCharactersPerLine = ({
30
30
  const remainingWords = splitted.slice(i + 1);
31
31
  const filledCharactersInLine = currentSegment.map((s) => s.text.length).reduce((a, b) => a + b, 0);
32
32
  const preventOrphanWord = remainingWords.length < 4 && remainingWords.length > 1 && filledCharactersInLine > maxCharsPerLine / 2;
33
- if (filledCharactersInLine + w.text.length > maxCharsPerLine || preventOrphanWord) {
33
+ if (currentSegment.length > 0 && (filledCharactersInLine + w.text.length > maxCharsPerLine || preventOrphanWord)) {
34
34
  segments.push(currentSegment);
35
35
  currentSegment = [];
36
36
  }
@@ -122,7 +122,7 @@ var createTikTokStyleCaptions = ({
122
122
  return { pages: tikTokStyleCaptions };
123
123
  };
124
124
  // src/parse-srt.ts
125
- function toSeconds(time) {
125
+ function toMilliseconds(time) {
126
126
  const [first, second, third] = time.split(":");
127
127
  if (!first) {
128
128
  throw new Error(`Invalid timestamp:${time}`);
@@ -140,7 +140,7 @@ function toSeconds(time) {
140
140
  if (!millis) {
141
141
  throw new Error(`Invalid timestamp:${time}`);
142
142
  }
143
- return parseInt(first, 10) * 3600 + parseInt(second, 10) * 60 + parseInt(seconds, 10) + parseInt(millis, 10) / 1000;
143
+ return parseInt(first, 10) * 3600000 + parseInt(second, 10) * 60000 + parseInt(seconds, 10) * 1000 + parseInt(millis, 10);
144
144
  }
145
145
  var parseSrt = ({ input }) => {
146
146
  const inputLines = input.replace(/^\uFEFF/, "").replace(/\r\n/g, `
@@ -153,17 +153,16 @@ var parseSrt = ({ input }) => {
153
153
  const nextLine = inputLines[i + 1];
154
154
  if (line?.match(/^\s*\d+\s*$/) && nextLine?.includes(" --> ")) {
155
155
  const nextLineSplit = nextLine.split(" --> ");
156
- const start = toSeconds(nextLineSplit[0].trim());
157
- const end = toSeconds(nextLineSplit[1].trim());
156
+ const start = toMilliseconds(nextLineSplit[0].trim());
157
+ const end = toMilliseconds(nextLineSplit[1].trim());
158
158
  captions.push({
159
159
  text: "",
160
- startMs: start * 1000,
161
- endMs: end * 1000,
160
+ startMs: start,
161
+ endMs: end,
162
162
  confidence: 1,
163
- timestampMs: (start + end) / 2 * 1000
163
+ timestampMs: (start + end) / 2
164
164
  });
165
- } else if (line?.includes(" --> ")) {
166
- continue;
165
+ i++;
167
166
  } else if (line?.trim() === "") {
168
167
  if (captions.length > 0) {
169
168
  captions[captions.length - 1].text = captions[captions.length - 1].text.trim();
package/dist/parse-srt.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseSrt = void 0;
4
- function toSeconds(time) {
4
+ function toMilliseconds(time) {
5
5
  const [first, second, third] = time.split(':');
6
6
  if (!first) {
7
7
  throw new Error(`Invalid timestamp:${time}`);
@@ -19,10 +19,10 @@ function toSeconds(time) {
19
19
  if (!millis) {
20
20
  throw new Error(`Invalid timestamp:${time}`);
21
21
  }
22
- return (parseInt(first, 10) * 3600 +
23
- parseInt(second, 10) * 60 +
24
- parseInt(seconds, 10) +
25
- parseInt(millis, 10) / 1000);
22
+ return (parseInt(first, 10) * 3600000 +
23
+ parseInt(second, 10) * 60000 +
24
+ parseInt(seconds, 10) * 1000 +
25
+ parseInt(millis, 10));
26
26
  }
27
27
  const parseSrt = ({ input }) => {
28
28
  const inputLines = input
@@ -36,18 +36,16 @@ const parseSrt = ({ input }) => {
36
36
  const nextLine = inputLines[i + 1];
37
37
  if ((line === null || line === void 0 ? void 0 : line.match(/^\s*\d+\s*$/)) && (nextLine === null || nextLine === void 0 ? void 0 : nextLine.includes(' --> '))) {
38
38
  const nextLineSplit = nextLine.split(' --> ');
39
- const start = toSeconds(nextLineSplit[0].trim());
40
- const end = toSeconds(nextLineSplit[1].trim());
39
+ const start = toMilliseconds(nextLineSplit[0].trim());
40
+ const end = toMilliseconds(nextLineSplit[1].trim());
41
41
  captions.push({
42
42
  text: '',
43
- startMs: start * 1000,
44
- endMs: end * 1000,
43
+ startMs: start,
44
+ endMs: end,
45
45
  confidence: 1,
46
- timestampMs: ((start + end) / 2) * 1000,
46
+ timestampMs: (start + end) / 2,
47
47
  });
48
- }
49
- else if (line === null || line === void 0 ? void 0 : line.includes(' --> ')) {
50
- continue;
48
+ i++;
51
49
  }
52
50
  else if ((line === null || line === void 0 ? void 0 : line.trim()) === '') {
53
51
  if (captions.length > 0) {
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.527",
6
+ "version": "4.0.529",
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.527",
26
+ "@remotion/eslint-config-internal": "4.0.529",
27
27
  "eslint": "9.19.0",
28
28
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
29
29
  },