@remotion/captions 4.0.277 → 4.0.279

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.
@@ -8,6 +8,7 @@ export type TikTokPage = {
8
8
  text: string;
9
9
  startMs: number;
10
10
  tokens: TikTokToken[];
11
+ durationMs: number;
11
12
  };
12
13
  export type CreateTikTokStyleCaptionsInput = {
13
14
  captions: Caption[];
@@ -7,17 +7,26 @@ const createTikTokStyleCaptions = ({ captions, combineTokensWithinMilliseconds,
7
7
  let currentTokens = [];
8
8
  let currentFrom = 0;
9
9
  let currentTo = 0;
10
+ const add = () => {
11
+ tikTokStyleCaptions.push({
12
+ text: currentText.trimStart(),
13
+ startMs: currentFrom,
14
+ tokens: currentTokens,
15
+ durationMs: Infinity,
16
+ });
17
+ if (tikTokStyleCaptions.length > 1) {
18
+ tikTokStyleCaptions[tikTokStyleCaptions.length - 2].durationMs =
19
+ currentFrom -
20
+ tikTokStyleCaptions[tikTokStyleCaptions.length - 2].startMs;
21
+ }
22
+ };
10
23
  captions.forEach((item, index) => {
11
24
  const { text } = item;
12
25
  // If text starts with a space, push the currentText (if it exists) and start a new one
13
26
  if (text.startsWith(' ') &&
14
27
  currentTo - currentFrom > combineTokensWithinMilliseconds) {
15
28
  if (currentText !== '') {
16
- tikTokStyleCaptions.push({
17
- text: currentText.trimStart(),
18
- startMs: currentFrom,
19
- tokens: currentTokens,
20
- });
29
+ add();
21
30
  }
22
31
  // Start a new sentence
23
32
  currentText = text.trimStart();
@@ -46,11 +55,9 @@ const createTikTokStyleCaptions = ({ captions, combineTokensWithinMilliseconds,
46
55
  }
47
56
  // Ensure the last sentence is added
48
57
  if (index === captions.length - 1 && currentText !== '') {
49
- tikTokStyleCaptions.push({
50
- text: currentText,
51
- startMs: currentFrom,
52
- tokens: currentTokens,
53
- });
58
+ add();
59
+ tikTokStyleCaptions[tikTokStyleCaptions.length - 1].durationMs =
60
+ currentTo - tikTokStyleCaptions[tikTokStyleCaptions.length - 1].startMs;
54
61
  }
55
62
  });
56
63
  return { pages: tikTokStyleCaptions };
@@ -39,6 +39,7 @@ const captions = [
39
39
  });
40
40
  (0, bun_test_1.expect)(tikTokStyleCaptions).toEqual([
41
41
  {
42
+ durationMs: 860,
42
43
  text: "Using Remotion's",
43
44
  startMs: 40,
44
45
  tokens: [
@@ -57,6 +58,7 @@ const captions = [
57
58
  {
58
59
  text: 'TikTok template,',
59
60
  startMs: 900,
61
+ durationMs: 1050,
60
62
  tokens: [
61
63
  {
62
64
  text: 'TikTok',
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.277",
6
+ "version": "4.0.279",
7
7
  "description": "Primitives for dealing with captions",
8
8
  "main": "dist/index.js",
9
9
  "sideEffects": false,
@@ -19,7 +19,7 @@
19
19
  "peerDependencies": {},
20
20
  "devDependencies": {
21
21
  "eslint": "9.19.0",
22
- "@remotion/eslint-config-internal": "4.0.277"
22
+ "@remotion/eslint-config-internal": "4.0.279"
23
23
  },
24
24
  "keywords": [
25
25
  "remotion"