@remotion/captions 4.0.512 → 4.0.514

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.
@@ -13,8 +13,9 @@ export type TikTokPage = {
13
13
  export type CreateTikTokStyleCaptionsInput = {
14
14
  captions: Caption[];
15
15
  combineTokensWithinMilliseconds: number;
16
+ breakOnSilenceAfterMilliseconds?: number;
16
17
  };
17
18
  export type CreateTikTokStyleCaptionsOutput = {
18
19
  pages: TikTokPage[];
19
20
  };
20
- export declare const createTikTokStyleCaptions: ({ captions, combineTokensWithinMilliseconds, }: CreateTikTokStyleCaptionsInput) => CreateTikTokStyleCaptionsOutput;
21
+ export declare const createTikTokStyleCaptions: ({ captions, combineTokensWithinMilliseconds, breakOnSilenceAfterMilliseconds, }: CreateTikTokStyleCaptionsInput) => CreateTikTokStyleCaptionsOutput;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTikTokStyleCaptions = void 0;
4
- const createTikTokStyleCaptions = ({ captions, combineTokensWithinMilliseconds, }) => {
4
+ const createTikTokStyleCaptions = ({ captions, combineTokensWithinMilliseconds, breakOnSilenceAfterMilliseconds, }) => {
5
5
  const tikTokStyleCaptions = [];
6
6
  let currentText = '';
7
7
  let currentTokens = [];
@@ -22,9 +22,13 @@ const createTikTokStyleCaptions = ({ captions, combineTokensWithinMilliseconds,
22
22
  };
23
23
  captions.forEach((item, index) => {
24
24
  const { text } = item;
25
+ const exceedsDuration = currentTo - currentFrom > combineTokensWithinMilliseconds;
26
+ // A pause between the previous caption and this one
27
+ const shouldBreakOnSilence = breakOnSilenceAfterMilliseconds !== undefined &&
28
+ currentText !== '' &&
29
+ item.startMs - currentTo >= breakOnSilenceAfterMilliseconds;
25
30
  // If text starts with a space, push the currentText (if it exists) and start a new one
26
- if (text.startsWith(' ') &&
27
- currentTo - currentFrom > combineTokensWithinMilliseconds) {
31
+ if (text.startsWith(' ') && (exceedsDuration || shouldBreakOnSilence)) {
28
32
  if (currentText !== '') {
29
33
  add();
30
34
  }
@@ -60,6 +64,10 @@ const createTikTokStyleCaptions = ({ captions, combineTokensWithinMilliseconds,
60
64
  currentTo - tikTokStyleCaptions[tikTokStyleCaptions.length - 1].startMs;
61
65
  }
62
66
  });
67
+ const lastPage = tikTokStyleCaptions[tikTokStyleCaptions.length - 1];
68
+ if (lastPage && lastPage.durationMs === Infinity) {
69
+ lastPage.durationMs = currentTo - lastPage.startMs;
70
+ }
63
71
  return { pages: tikTokStyleCaptions };
64
72
  };
65
73
  exports.createTikTokStyleCaptions = createTikTokStyleCaptions;
@@ -5,7 +5,7 @@ const splitWords = (inputCaptions) => {
5
5
  const captions = [];
6
6
  for (let i = 0; i < inputCaptions.length; i++) {
7
7
  const w = inputCaptions[i];
8
- const words = w.text.split(' ');
8
+ const words = w.text.split(' ').filter(Boolean);
9
9
  for (let j = 0; j < words.length; j++) {
10
10
  const word = words[j];
11
11
  captions.push({
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.512",
6
+ "version": "4.0.514",
7
7
  "description": "Primitives for dealing with captions",
8
8
  "main": "dist/index.js",
9
9
  "bugs": {
@@ -21,7 +21,7 @@
21
21
  "dependencies": {},
22
22
  "peerDependencies": {},
23
23
  "devDependencies": {
24
- "@remotion/eslint-config-internal": "4.0.512",
24
+ "@remotion/eslint-config-internal": "4.0.514",
25
25
  "eslint": "9.19.0",
26
26
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
27
27
  },