@softure-ai/marketing-kit 0.21.2 → 0.23.0
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/CHANGELOG.md +32 -0
- package/NOTICE +11 -0
- package/README.md +39 -5
- package/dist/cli/failure.d.ts.map +1 -1
- package/dist/cli/failure.js.map +1 -1
- package/dist/cli/films.js.map +1 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/options.d.ts.map +1 -1
- package/dist/compose/timeline.d.ts +22 -1
- package/dist/compose/timeline.d.ts.map +1 -1
- package/dist/compose/timeline.js +52 -14
- package/dist/compose/timeline.js.map +1 -1
- package/dist/config/actions-schema.d.ts +57 -57
- package/dist/config/actions-schema.d.ts.map +1 -1
- package/dist/config/brand.d.ts.map +1 -1
- package/dist/config/brand.js +22 -1
- package/dist/config/brand.js.map +1 -1
- package/dist/config/colors.d.ts +35 -3
- package/dist/config/colors.d.ts.map +1 -1
- package/dist/config/colors.js +32 -0
- package/dist/config/colors.js.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +5 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/placeholders.d.ts.map +1 -1
- package/dist/config/placeholders.js.map +1 -1
- package/dist/config/schema.d.ts +340 -328
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +31 -4
- package/dist/config/schema.js.map +1 -1
- package/dist/config/shot-steps.d.ts +64 -64
- package/dist/film.d.ts.map +1 -1
- package/dist/footage/audio.js.map +1 -1
- package/dist/footage/caption-highlight.d.ts +44 -0
- package/dist/footage/caption-highlight.d.ts.map +1 -0
- package/dist/footage/caption-highlight.js +29 -0
- package/dist/footage/caption-highlight.js.map +1 -0
- package/dist/footage/captions.d.ts +14 -5
- package/dist/footage/captions.d.ts.map +1 -1
- package/dist/footage/captions.js +19 -11
- package/dist/footage/captions.js.map +1 -1
- package/dist/footage/clip-sound.d.ts.map +1 -1
- package/dist/footage/clip-sound.js.map +1 -1
- package/dist/footage/compose.d.ts +3 -0
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +33 -6
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/cuts.d.ts.map +1 -1
- package/dist/footage/cuts.js.map +1 -1
- package/dist/footage/declick.d.ts.map +1 -1
- package/dist/footage/disk.js.map +1 -1
- package/dist/footage/draft-color.d.ts +6 -0
- package/dist/footage/draft-color.d.ts.map +1 -0
- package/dist/footage/draft-color.js +14 -0
- package/dist/footage/draft-color.js.map +1 -0
- package/dist/footage/draft-font.js.map +1 -1
- package/dist/footage/draft-overlays.d.ts +12 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -0
- package/dist/footage/draft-overlays.js +83 -0
- package/dist/footage/draft-overlays.js.map +1 -0
- package/dist/footage/draft.d.ts +27 -9
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +99 -37
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/edl.d.ts +54 -13
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +10 -0
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/elevenlabs.d.ts.map +1 -1
- package/dist/footage/failure.js.map +1 -1
- package/dist/footage/fake.js.map +1 -1
- package/dist/footage/ffmpeg-failure.d.ts.map +1 -1
- package/dist/footage/ffmpeg-failure.js.map +1 -1
- package/dist/footage/film.d.ts +23 -0
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.js +2 -0
- package/dist/footage/film.js.map +1 -1
- package/dist/footage/hyperframes-capture.d.ts.map +1 -1
- package/dist/footage/keyterms.d.ts.map +1 -1
- package/dist/footage/loudness.d.ts.map +1 -1
- package/dist/footage/loudness.js.map +1 -1
- package/dist/footage/mouth-clicks.d.ts.map +1 -1
- package/dist/footage/normalize.d.ts.map +1 -1
- package/dist/footage/normalize.js.map +1 -1
- package/dist/footage/overlay-html.d.ts +29 -0
- package/dist/footage/overlay-html.d.ts.map +1 -0
- package/dist/footage/overlay-html.js +112 -0
- package/dist/footage/overlay-html.js.map +1 -0
- package/dist/footage/overlay-schema.d.ts +97 -0
- package/dist/footage/overlay-schema.d.ts.map +1 -0
- package/dist/footage/overlay-schema.js +104 -0
- package/dist/footage/overlay-schema.js.map +1 -0
- package/dist/footage/overlays.d.ts +112 -0
- package/dist/footage/overlays.d.ts.map +1 -0
- package/dist/footage/overlays.js +222 -0
- package/dist/footage/overlays.js.map +1 -0
- package/dist/footage/paid.d.ts.map +1 -1
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +10 -1
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/footage/probe.js.map +1 -1
- package/dist/footage/process.js.map +1 -1
- package/dist/footage/publish.js.map +1 -1
- package/dist/footage/render.js.map +1 -1
- package/dist/footage/sound-analysis.d.ts.map +1 -1
- package/dist/footage/speech-ranges.js.map +1 -1
- package/dist/footage/tonemap-lut.d.ts.map +1 -1
- package/dist/footage/tonemap-lut.js.map +1 -1
- package/dist/footage/tools.d.ts.map +1 -1
- package/dist/footage/tools.js.map +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/messages/en.d.ts.map +1 -1
- package/dist/messages/index.js.map +1 -1
- package/dist/og/font-file.d.ts.map +1 -1
- package/dist/og/fonts.d.ts.map +1 -1
- package/dist/og/fonts.js.map +1 -1
- package/dist/og/index.d.ts +1 -1
- package/dist/og/index.d.ts.map +1 -1
- package/dist/og/index.js +1 -1
- package/dist/og/index.js.map +1 -1
- package/dist/og/photo-cover.d.ts +18 -1
- package/dist/og/photo-cover.d.ts.map +1 -1
- package/dist/og/photo-cover.js +56 -28
- package/dist/og/photo-cover.js.map +1 -1
- package/dist/og/result.d.ts.map +1 -1
- package/dist/og/templates/schemas.d.ts.map +1 -1
- package/dist/platforms.d.ts.map +1 -1
- package/dist/render/hyperframes.d.ts +1 -1
- package/dist/render/hyperframes.d.ts.map +1 -1
- package/dist/render/hyperframes.js +1 -1
- package/dist/render/hyperframes.js.map +1 -1
- package/dist/render/render.js.map +1 -1
- package/dist/screenshot/gates.d.ts.map +1 -1
- package/dist/voice/fake.js.map +1 -1
- package/dist/voice/provider.d.ts.map +1 -1
- package/package.json +4 -3
- package/schema/edl.schema.json +130 -0
- package/schema/marketing.schema.json +51 -0
- package/src/compose/timeline.ts +62 -13
- package/src/config/brand.ts +20 -1
- package/src/config/colors.ts +39 -2
- package/src/config/config.ts +5 -0
- package/src/config/schema.ts +34 -7
- package/src/footage/caption-highlight.ts +52 -0
- package/src/footage/captions.ts +26 -12
- package/src/footage/compose.ts +40 -6
- package/src/footage/draft-color.ts +12 -0
- package/src/footage/draft-overlays.ts +91 -0
- package/src/footage/draft.ts +117 -39
- package/src/footage/edl.ts +17 -0
- package/src/footage/film.ts +25 -0
- package/src/footage/overlay-html.ts +127 -0
- package/src/footage/overlay-schema.ts +146 -0
- package/src/footage/overlays.ts +272 -0
- package/src/footage/pipeline.ts +8 -1
- package/src/index.ts +58 -1
- package/src/og/index.ts +2 -0
- package/src/og/photo-cover.ts +83 -33
- package/src/render/hyperframes.ts +1 -1
package/schema/edl.schema.json
CHANGED
|
@@ -119,6 +119,136 @@
|
|
|
119
119
|
"additionalProperties": false
|
|
120
120
|
},
|
|
121
121
|
"description": "The kept parts of the clips, in film order."
|
|
122
|
+
},
|
|
123
|
+
"overlays": {
|
|
124
|
+
"description": "Small graphics and emphasis zooms placed on a word of the transcript (at_word) or a film second (at), one at a time, each inside one segment: punch_in, keyword, lower_third, list, arrow, highlight. Without it, none.",
|
|
125
|
+
"maxItems": 40,
|
|
126
|
+
"type": "array",
|
|
127
|
+
"items": {
|
|
128
|
+
"type": "object",
|
|
129
|
+
"properties": {
|
|
130
|
+
"kind": {
|
|
131
|
+
"type": "string",
|
|
132
|
+
"enum": [
|
|
133
|
+
"punch_in",
|
|
134
|
+
"keyword",
|
|
135
|
+
"lower_third",
|
|
136
|
+
"list",
|
|
137
|
+
"arrow",
|
|
138
|
+
"highlight"
|
|
139
|
+
],
|
|
140
|
+
"description": "punch_in (an emphasis zoom on a word), keyword, lower_third, list, arrow or highlight."
|
|
141
|
+
},
|
|
142
|
+
"at_word": {
|
|
143
|
+
"description": "The transcript word the overlay starts on (its start after the cut); give this or at.",
|
|
144
|
+
"type": "object",
|
|
145
|
+
"properties": {
|
|
146
|
+
"text": {
|
|
147
|
+
"type": "string",
|
|
148
|
+
"minLength": 1,
|
|
149
|
+
"description": "The word as the transcript has it; compared without case and punctuation."
|
|
150
|
+
},
|
|
151
|
+
"occurrence": {
|
|
152
|
+
"description": "Which time the film says it (1 the first, the default).",
|
|
153
|
+
"type": "integer",
|
|
154
|
+
"minimum": 1,
|
|
155
|
+
"maximum": 9007199254740991
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
"required": [
|
|
159
|
+
"text"
|
|
160
|
+
],
|
|
161
|
+
"additionalProperties": false
|
|
162
|
+
},
|
|
163
|
+
"at": {
|
|
164
|
+
"description": "The film second the overlay starts at; give this or at_word.",
|
|
165
|
+
"type": "number",
|
|
166
|
+
"minimum": 0
|
|
167
|
+
},
|
|
168
|
+
"duration": {
|
|
169
|
+
"type": "number",
|
|
170
|
+
"minimum": 1,
|
|
171
|
+
"maximum": 8,
|
|
172
|
+
"description": "Seconds on screen (1-8)."
|
|
173
|
+
},
|
|
174
|
+
"text": {
|
|
175
|
+
"description": "The keyword (up to 24 characters) or the lower third (up to 40).",
|
|
176
|
+
"type": "string",
|
|
177
|
+
"minLength": 1
|
|
178
|
+
},
|
|
179
|
+
"items": {
|
|
180
|
+
"description": "The list's points: 2 to 4, up to 32 characters each.",
|
|
181
|
+
"minItems": 2,
|
|
182
|
+
"maxItems": 4,
|
|
183
|
+
"type": "array",
|
|
184
|
+
"items": {
|
|
185
|
+
"type": "string",
|
|
186
|
+
"minLength": 1,
|
|
187
|
+
"maxLength": 32
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
"anchor": {
|
|
191
|
+
"description": "The point an arrow points at, or the rectangle a highlight marks (x, y its top left), in px of the film's frame.",
|
|
192
|
+
"type": "object",
|
|
193
|
+
"properties": {
|
|
194
|
+
"x": {
|
|
195
|
+
"type": "number",
|
|
196
|
+
"minimum": 0,
|
|
197
|
+
"description": "Px from the frame's left edge."
|
|
198
|
+
},
|
|
199
|
+
"y": {
|
|
200
|
+
"type": "number",
|
|
201
|
+
"minimum": 0,
|
|
202
|
+
"description": "Px from the frame's top edge."
|
|
203
|
+
},
|
|
204
|
+
"width": {
|
|
205
|
+
"description": "The highlight's width in px.",
|
|
206
|
+
"type": "number",
|
|
207
|
+
"exclusiveMinimum": 0
|
|
208
|
+
},
|
|
209
|
+
"height": {
|
|
210
|
+
"description": "The highlight's height in px.",
|
|
211
|
+
"type": "number",
|
|
212
|
+
"exclusiveMinimum": 0
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
"required": [
|
|
216
|
+
"x",
|
|
217
|
+
"y"
|
|
218
|
+
],
|
|
219
|
+
"additionalProperties": false
|
|
220
|
+
},
|
|
221
|
+
"style": {
|
|
222
|
+
"description": "The overlay's size step and side; colours and fonts are the brand's.",
|
|
223
|
+
"type": "object",
|
|
224
|
+
"properties": {
|
|
225
|
+
"size": {
|
|
226
|
+
"description": "s, m (the default) or l: the punch-in's zoom (108, 112, 115 %) or the type size.",
|
|
227
|
+
"type": "string",
|
|
228
|
+
"enum": [
|
|
229
|
+
"s",
|
|
230
|
+
"m",
|
|
231
|
+
"l"
|
|
232
|
+
]
|
|
233
|
+
},
|
|
234
|
+
"side": {
|
|
235
|
+
"description": "The side a keyword, lower third or list sits on.",
|
|
236
|
+
"type": "string",
|
|
237
|
+
"enum": [
|
|
238
|
+
"left",
|
|
239
|
+
"right"
|
|
240
|
+
]
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
"additionalProperties": false
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
"required": [
|
|
247
|
+
"kind",
|
|
248
|
+
"duration"
|
|
249
|
+
],
|
|
250
|
+
"additionalProperties": false
|
|
251
|
+
}
|
|
122
252
|
}
|
|
123
253
|
},
|
|
124
254
|
"required": [
|
|
@@ -164,6 +164,14 @@
|
|
|
164
164
|
"captionHighlight": {
|
|
165
165
|
"description": "The word being spoken. A hex colour; without it, the colour comes from tokensFrom.",
|
|
166
166
|
"type": "string"
|
|
167
|
+
},
|
|
168
|
+
"captionHighlightBox": {
|
|
169
|
+
"description": "The box behind the word being spoken, with captionHighlightStyle \"box\"; optional otherwise. A hex colour; without it, the colour comes from tokensFrom.",
|
|
170
|
+
"type": "string"
|
|
171
|
+
},
|
|
172
|
+
"captionHighlightText": {
|
|
173
|
+
"description": "The text of the word being spoken on its box, with captionHighlightStyle \"box\"; optional otherwise. A hex colour; without it, the colour comes from tokensFrom.",
|
|
174
|
+
"type": "string"
|
|
167
175
|
}
|
|
168
176
|
},
|
|
169
177
|
"additionalProperties": false
|
|
@@ -240,6 +248,16 @@
|
|
|
240
248
|
"description": "The source token for the captionHighlight role (The word being spoken.) Default: the role's name in kebab case.",
|
|
241
249
|
"type": "string",
|
|
242
250
|
"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
|
|
251
|
+
},
|
|
252
|
+
"captionHighlightBox": {
|
|
253
|
+
"description": "The source token for the captionHighlightBox role (The box behind the word being spoken, with captionHighlightStyle \"box\"; optional otherwise.) Default: the role's name in kebab case.",
|
|
254
|
+
"type": "string",
|
|
255
|
+
"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
|
|
256
|
+
},
|
|
257
|
+
"captionHighlightText": {
|
|
258
|
+
"description": "The source token for the captionHighlightText role (The text of the word being spoken on its box, with captionHighlightStyle \"box\"; optional otherwise.) Default: the role's name in kebab case.",
|
|
259
|
+
"type": "string",
|
|
260
|
+
"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
|
|
243
261
|
}
|
|
244
262
|
},
|
|
245
263
|
"additionalProperties": false
|
|
@@ -2860,6 +2878,21 @@
|
|
|
2860
2878
|
"highlight"
|
|
2861
2879
|
]
|
|
2862
2880
|
},
|
|
2881
|
+
"captionHighlightStyle": {
|
|
2882
|
+
"default": "text",
|
|
2883
|
+
"description": "How a highlight caption lights the word being said: text (the default) colours it captionHighlight; box puts it on a rounded box of brand.colors.captionHighlightBox with its text in captionHighlightText (both then required).",
|
|
2884
|
+
"type": "string",
|
|
2885
|
+
"enum": [
|
|
2886
|
+
"text",
|
|
2887
|
+
"box"
|
|
2888
|
+
]
|
|
2889
|
+
},
|
|
2890
|
+
"overlayMinSpacing": {
|
|
2891
|
+
"description": "The least seconds between the starts of two EDL overlays (the app's budget, e.g. 8); without it, only one overlay at a time.",
|
|
2892
|
+
"type": "number",
|
|
2893
|
+
"minimum": 0,
|
|
2894
|
+
"maximum": 60
|
|
2895
|
+
},
|
|
2863
2896
|
"captionPreset": {
|
|
2864
2897
|
"description": "Keeps a 9:16 film's captions inside a platform's safe zone: reels, shorts, tiktok or all; without it, layout decides.",
|
|
2865
2898
|
"type": "string",
|
|
@@ -2886,6 +2919,24 @@
|
|
|
2886
2919
|
"maxLength": 20
|
|
2887
2920
|
}
|
|
2888
2921
|
},
|
|
2922
|
+
"captionMaxWords": {
|
|
2923
|
+
"description": "The words a caption card aims at (1-12, a brand's words per caption); without it, 4 for highlight and 6 for phrase captions.",
|
|
2924
|
+
"type": "integer",
|
|
2925
|
+
"minimum": 1,
|
|
2926
|
+
"maximum": 12
|
|
2927
|
+
},
|
|
2928
|
+
"captionMinWords": {
|
|
2929
|
+
"description": "The fewest words a caption card shows (1-4; 2 means never a one-word card): a short card joins the one before it or takes words from it; without it, cards stay as cut.",
|
|
2930
|
+
"type": "integer",
|
|
2931
|
+
"minimum": 1,
|
|
2932
|
+
"maximum": 4
|
|
2933
|
+
},
|
|
2934
|
+
"captionMaxCharacters": {
|
|
2935
|
+
"description": "The most characters a short card's join may make (8-200, what fits the caption's width); without it, no limit.",
|
|
2936
|
+
"type": "integer",
|
|
2937
|
+
"minimum": 8,
|
|
2938
|
+
"maximum": 200
|
|
2939
|
+
},
|
|
2889
2940
|
"edit": {
|
|
2890
2941
|
"description": "The cut's look; the defaults read as an ordinary phone video.",
|
|
2891
2942
|
"default": {},
|
package/src/compose/timeline.ts
CHANGED
|
@@ -328,6 +328,56 @@ export interface CaptionChunkOptions {
|
|
|
328
328
|
* its chunk. Absent: every word may end one.
|
|
329
329
|
*/
|
|
330
330
|
keepsWithNext?: (word: TimedWord) => boolean;
|
|
331
|
+
/** The fewest words a chunk shows (`balanceCaptionGroups`); default 1: chunks stay as they are cut. */
|
|
332
|
+
minWords?: number;
|
|
333
|
+
/** The most characters a short chunk's join may make, words joined by spaces (`balanceCaptionGroups`); absent: no limit. */
|
|
334
|
+
maxCharacters?: number;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** How short caption chunks are evened out (`balanceCaptionGroups`). */
|
|
338
|
+
export interface CaptionBalanceOptions {
|
|
339
|
+
/** The fewest words a chunk shows; 1 leaves the chunks as they are. */
|
|
340
|
+
minWords: number;
|
|
341
|
+
/** The words a chunk aims at; a short chunk's join may pass it by one word (a sentence's last word stays with it). */
|
|
342
|
+
maxWords: number;
|
|
343
|
+
/** The most characters a join may make, words joined by spaces (what fits the caption's width); absent: no limit. */
|
|
344
|
+
maxCharacters?: number;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function getGroupText(words: readonly TimedWord[]): string {
|
|
348
|
+
return words.map((word) => word.text).join(" ");
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Caption groups without one shorter than `minWords` where it can be helped (issue: one-word boards): a short group
|
|
353
|
+
* joins the group before it when the join fits (`maxWords` + 1 words, `maxCharacters`); otherwise words move over from
|
|
354
|
+
* the end of the group before it, as long as that one keeps `minWords`. A short first group does the same with the
|
|
355
|
+
* group after it. A text shorter than `minWords` stays as it is. The groups are new arrays; no word changes.
|
|
356
|
+
*/
|
|
357
|
+
export function balanceCaptionGroups(groups: readonly (readonly TimedWord[])[], options: CaptionBalanceOptions): TimedWord[][] {
|
|
358
|
+
const { minWords, maxWords, maxCharacters } = options;
|
|
359
|
+
const result = groups.map((group) => [...group]);
|
|
360
|
+
if (minWords <= 1) return result;
|
|
361
|
+
const fits = (words: readonly TimedWord[]): boolean => words.length <= maxWords + 1 && (maxCharacters === undefined || getGroupText(words).length <= maxCharacters);
|
|
362
|
+
const balanced: TimedWord[][] = [];
|
|
363
|
+
for (const group of result) {
|
|
364
|
+
const previous = balanced.at(-1);
|
|
365
|
+
if (group.length < minWords && previous !== undefined) {
|
|
366
|
+
if (fits([...previous, ...group])) {
|
|
367
|
+
previous.push(...group);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
// `previous` has more than `minWords` words while the loop runs, so `pop` returns a word.
|
|
371
|
+
while (group.length < minWords && previous.length > minWords) group.unshift(previous.pop() as TimedWord);
|
|
372
|
+
}
|
|
373
|
+
balanced.push(group);
|
|
374
|
+
}
|
|
375
|
+
const [first, second] = balanced;
|
|
376
|
+
if (first === undefined || second === undefined || first.length >= minWords) return balanced;
|
|
377
|
+
if (fits([...first, ...second])) return [[...first, ...second], ...balanced.slice(2)];
|
|
378
|
+
// `second` has more than `minWords` words while the loop runs, so `shift` returns a word.
|
|
379
|
+
while (first.length < minWords && second.length > minWords) first.push(second.shift() as TimedWord);
|
|
380
|
+
return balanced;
|
|
331
381
|
}
|
|
332
382
|
|
|
333
383
|
/**
|
|
@@ -344,31 +394,30 @@ export function splitAfterKept(words: TimedWord[], keepsWithNext: ((word: TimedW
|
|
|
344
394
|
/**
|
|
345
395
|
* Words → caption chunks: at most `maxWords` words, broken after the end of a sentence and after a comma, so a caption
|
|
346
396
|
* does not glue two thoughts together; never after a word `keepsWithNext` keeps, unless punctuation ends it or every
|
|
347
|
-
* word of the chunk is kept.
|
|
397
|
+
* word of the chunk is kept. With `minWords`, short chunks are evened out (`balanceCaptionGroups`). A number as
|
|
398
|
+
* `options` is `maxWords`.
|
|
348
399
|
*/
|
|
349
400
|
export function captionChunks(words: TimedWord[], options: number | CaptionChunkOptions = {}): CaptionChunk[] {
|
|
350
|
-
const { maxWords = 4, keepsWithNext } = typeof options === "number" ? { maxWords: options } : options;
|
|
351
|
-
const
|
|
401
|
+
const { maxWords = 4, keepsWithNext, minWords = 1, maxCharacters } = typeof options === "number" ? { maxWords: options } : options;
|
|
402
|
+
const groups: TimedWord[][] = [];
|
|
352
403
|
let current: TimedWord[] = [];
|
|
353
|
-
const push = (chunkWords: TimedWord[]) => {
|
|
354
|
-
const first = chunkWords[0];
|
|
355
|
-
const last = chunkWords[chunkWords.length - 1];
|
|
356
|
-
if (first === undefined || last === undefined) return;
|
|
357
|
-
chunks.push({ words: chunkWords, start: first.start, end: last.end });
|
|
358
|
-
};
|
|
359
404
|
for (const word of words) {
|
|
360
405
|
current.push(word);
|
|
361
406
|
if (/[.,?!:;]$/.test(word.text)) {
|
|
362
|
-
push(current);
|
|
407
|
+
groups.push(current);
|
|
363
408
|
current = [];
|
|
364
409
|
} else if (current.length >= maxWords) {
|
|
365
410
|
const { chunk, carry } = splitAfterKept(current, keepsWithNext);
|
|
366
|
-
push(chunk);
|
|
411
|
+
groups.push(chunk);
|
|
367
412
|
current = carry;
|
|
368
413
|
}
|
|
369
414
|
}
|
|
370
|
-
push(current);
|
|
371
|
-
return
|
|
415
|
+
if (current.length > 0) groups.push(current);
|
|
416
|
+
return balanceCaptionGroups(groups, { minWords, maxWords, maxCharacters }).map((group) => ({
|
|
417
|
+
words: group,
|
|
418
|
+
start: (group[0] as TimedWord).start,
|
|
419
|
+
end: (group[group.length - 1] as TimedWord).end,
|
|
420
|
+
}));
|
|
372
421
|
}
|
|
373
422
|
|
|
374
423
|
/**
|
package/src/config/brand.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
|
|
4
|
-
import { COLOR_ROLES, getDefaultToken, isOpaqueHexColor, type BrandColors, type ColorsResult } from "./colors.js";
|
|
4
|
+
import { COLOR_ROLES, OPTIONAL_COLOR_ROLES, getDefaultToken, isOpaqueHexColor, type BrandColors, type ColorsResult } from "./colors.js";
|
|
5
5
|
import { readCssColors } from "./css-colors.js";
|
|
6
6
|
import { readDesignJsonColors } from "./design-json.js";
|
|
7
7
|
import type { ConfigIssue } from "./issues.js";
|
|
@@ -74,6 +74,25 @@ export function resolveBrandColors(brand: Brand, root: string): BrandColorsResul
|
|
|
74
74
|
}
|
|
75
75
|
colors[role] = value;
|
|
76
76
|
}
|
|
77
|
+
// An optional role takes its inline colour, else its token when the source has one; a token the config names and
|
|
78
|
+
// the source lacks is an issue, a default token it lacks leaves the role unset.
|
|
79
|
+
for (const role of OPTIONAL_COLOR_ROLES) {
|
|
80
|
+
const inline = brand.colors[role];
|
|
81
|
+
if (inline !== undefined) {
|
|
82
|
+
colors[role] = inline.toLowerCase();
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (reader === null) continue;
|
|
86
|
+
const named = brand.tokensFrom?.roles[role];
|
|
87
|
+
const token = named ?? getDefaultToken(role);
|
|
88
|
+
const read = reader([token]);
|
|
89
|
+
const value = read.ok ? read.colors[token] : undefined;
|
|
90
|
+
if (value !== undefined) colors[role] = value;
|
|
91
|
+
else if (named !== undefined) {
|
|
92
|
+
const reason = read.ok ? `no colour for "${token}"` : read.error;
|
|
93
|
+
issues.push({ path: ["brand", "tokensFrom", "roles", role], message: `brand.tokensFrom has no colour for it: ${reason}` });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
77
96
|
if (colors.background !== undefined && !isOpaqueHexColor(colors.background)) {
|
|
78
97
|
issues.push({ path: ["brand", "colors", "background"], message: `"${colors.background}" must be #rrggbb: the vignette adds its own transparency` });
|
|
79
98
|
}
|
package/src/config/colors.ts
CHANGED
|
@@ -26,7 +26,20 @@ export const COLOR_ROLES = [
|
|
|
26
26
|
|
|
27
27
|
export type ColorRole = (typeof COLOR_ROLES)[number];
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Colour roles a brand may leave out: only a feature that asks for them needs them, so a brand without them still
|
|
31
|
+
* resolves (issue #1199).
|
|
32
|
+
*/
|
|
33
|
+
export const OPTIONAL_COLOR_ROLES = [
|
|
34
|
+
/** The box behind the word being spoken, with `captionHighlightStyle: "box"`. */
|
|
35
|
+
"captionHighlightBox",
|
|
36
|
+
/** The text of the word being spoken on its box, with `captionHighlightStyle: "box"`. */
|
|
37
|
+
"captionHighlightText",
|
|
38
|
+
] as const;
|
|
39
|
+
|
|
40
|
+
export type OptionalColorRole = (typeof OPTIONAL_COLOR_ROLES)[number];
|
|
41
|
+
|
|
42
|
+
export type BrandColors = Record<ColorRole, string> & Partial<Record<OptionalColorRole, string>>;
|
|
30
43
|
|
|
31
44
|
export const COLOR_THEMES = ["light", "dark"] as const;
|
|
32
45
|
|
|
@@ -48,6 +61,30 @@ export function isOpaqueHexColor(value: string): boolean {
|
|
|
48
61
|
}
|
|
49
62
|
|
|
50
63
|
/** The token a role reads from a source when the config names none: `onCta` → `on-cta`. */
|
|
51
|
-
export function getDefaultToken(role: ColorRole): string {
|
|
64
|
+
export function getDefaultToken(role: ColorRole | OptionalColorRole): string {
|
|
52
65
|
return role.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
53
66
|
}
|
|
67
|
+
|
|
68
|
+
/** `#abc`, `#abcd`, `#aabbcc` or `#aabbccdd` as `#aabbcc` (lower case, alpha dropped). */
|
|
69
|
+
function toOpaque(color: string): string {
|
|
70
|
+
const digits = color.replace(/^#/, "").toLowerCase();
|
|
71
|
+
const full = digits.length <= 4 ? [...digits].map((digit) => digit + digit).join("") : digits;
|
|
72
|
+
return `#${full.slice(0, 6)}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The relative luminance (WCAG 2) of a hex colour, its alpha ignored. */
|
|
76
|
+
export function getRelativeLuminance(color: string): number {
|
|
77
|
+
if (!isHexColor(color)) throw new Error(`Not a hex colour: "${color}".`);
|
|
78
|
+
const hex = toOpaque(color);
|
|
79
|
+
const channel = (offset: number): number => {
|
|
80
|
+
const value = Number.parseInt(hex.slice(offset, offset + 2), 16) / 255;
|
|
81
|
+
return value <= 0.039_28 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
82
|
+
};
|
|
83
|
+
return 0.2126 * channel(1) + 0.7152 * channel(3) + 0.0722 * channel(5);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The WCAG contrast ratio of two hex colours (alpha ignored), from 1 to 21. */
|
|
87
|
+
export function getContrastRatio(first: string, second: string): number {
|
|
88
|
+
const [lighter, darker] = [getRelativeLuminance(first), getRelativeLuminance(second)].sort((a, b) => b - a) as [number, number];
|
|
89
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
90
|
+
}
|
package/src/config/config.ts
CHANGED
|
@@ -252,9 +252,14 @@ function resolveFootage(data: MarketingJson, at: (relative: string) => string):
|
|
|
252
252
|
},
|
|
253
253
|
captions: film.captions,
|
|
254
254
|
captionStyle: film.captionStyle,
|
|
255
|
+
...(film.captionHighlightStyle === "text" ? {} : { captionHighlightStyle: film.captionHighlightStyle }),
|
|
255
256
|
...(film.captionPreset === undefined ? {} : { captionPreset: film.captionPreset }),
|
|
257
|
+
...(film.overlayMinSpacing === undefined ? {} : { overlayMinSpacing: film.overlayMinSpacing }),
|
|
256
258
|
...(film.captionMaxLines === undefined ? {} : { captionMaxLines: film.captionMaxLines }),
|
|
257
259
|
...(film.captionKeepWithNext === undefined ? {} : { captionKeepWithNext: film.captionKeepWithNext }),
|
|
260
|
+
...(film.captionMaxWords === undefined ? {} : { captionMaxWords: film.captionMaxWords }),
|
|
261
|
+
...(film.captionMinWords === undefined ? {} : { captionMinWords: film.captionMinWords }),
|
|
262
|
+
...(film.captionMaxCharacters === undefined ? {} : { captionMaxCharacters: film.captionMaxCharacters }),
|
|
258
263
|
edit: {
|
|
259
264
|
zoomPercent: film.edit.zoomPercent,
|
|
260
265
|
zoomEaseFrames: film.edit.zoomEaseFrames,
|
package/src/config/schema.ts
CHANGED
|
@@ -15,11 +15,11 @@ import {
|
|
|
15
15
|
import { bigNumberDataSchema, carouselDataSchema, headlineChartDataSchema, headlineCtaDataSchema } from "../og/templates/schemas.js";
|
|
16
16
|
import { CHANNEL_CODE_MAX_LENGTH, CHANNEL_CODE_PATTERN, DEFAULT_LINK_IN_BIO, PLATFORMS } from "../platforms.js";
|
|
17
17
|
import { DECLICK_LEVELS } from "../footage/declick.js";
|
|
18
|
-
import { CAPTION_PRESETS, CAPTION_STYLES, CLIP_FITS, CLIP_ROLES, CUT_TRANSITIONS, JUMP_TRANSITIONS } from "../footage/film.js";
|
|
18
|
+
import { CAPTION_HIGHLIGHT_STYLES, CAPTION_PRESETS, CAPTION_STYLES, CLIP_FITS, CLIP_ROLES, CUT_TRANSITIONS, JUMP_TRANSITIONS } from "../footage/film.js";
|
|
19
19
|
import { normalizeKeyTerms } from "../footage/keyterms.js";
|
|
20
20
|
import { ELEVENLABS_DEFAULT_MODEL } from "../voice/voiceover.js";
|
|
21
21
|
import { actionSchema, type SceneAction } from "./actions-schema.js";
|
|
22
|
-
import { COLOR_ROLES, COLOR_THEMES, isHexColor, type ColorRole } from "./colors.js";
|
|
22
|
+
import { COLOR_ROLES, COLOR_THEMES, OPTIONAL_COLOR_ROLES, isHexColor, type ColorRole, type OptionalColorRole } from "./colors.js";
|
|
23
23
|
import { DAY_PATTERN, isCalendarDay } from "./day.js";
|
|
24
24
|
import { getOgImageNames } from "./og-image-names.js";
|
|
25
25
|
import { findMalformedPlaceholder, findPlaceholders } from "./placeholders.js";
|
|
@@ -114,7 +114,7 @@ const fontSchema = z.strictObject({
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
/** What each colour role paints; the descriptions of `brand.colors` and `brand.tokensFrom.roles`. */
|
|
117
|
-
const COLOR_ROLE_DESCRIPTIONS: Record<ColorRole, string> = {
|
|
117
|
+
const COLOR_ROLE_DESCRIPTIONS: Record<ColorRole | OptionalColorRole, string> = {
|
|
118
118
|
background: "The frame behind the phone and the vignette; #rrggbb, because the vignette appends an alpha.",
|
|
119
119
|
foreground: "Text on the background: the persona card's name, the end card.",
|
|
120
120
|
muted: "Secondary text: the persona card's tagline, the end card's note.",
|
|
@@ -124,21 +124,23 @@ const COLOR_ROLE_DESCRIPTIONS: Record<ColorRole, string> = {
|
|
|
124
124
|
captionBackground: "The caption pill.",
|
|
125
125
|
captionText: "Caption words not spoken yet.",
|
|
126
126
|
captionHighlight: "The word being spoken.",
|
|
127
|
+
captionHighlightBox: 'The box behind the word being spoken, with captionHighlightStyle "box"; optional otherwise.',
|
|
128
|
+
captionHighlightText: 'The text of the word being spoken on its box, with captionHighlightStyle "box"; optional otherwise.',
|
|
127
129
|
};
|
|
128
130
|
|
|
129
131
|
const colorRolesShape = Object.fromEntries(
|
|
130
|
-
COLOR_ROLES.map((role) => [role, hexColor.optional().describe(`${COLOR_ROLE_DESCRIPTIONS[role]} A hex colour; without it, the colour comes from tokensFrom.`)]),
|
|
132
|
+
[...COLOR_ROLES, ...OPTIONAL_COLOR_ROLES].map((role) => [role, hexColor.optional().describe(`${COLOR_ROLE_DESCRIPTIONS[role]} A hex colour; without it, the colour comes from tokensFrom.`)]),
|
|
131
133
|
) as Record<
|
|
132
|
-
|
|
134
|
+
ColorRole | OptionalColorRole,
|
|
133
135
|
z.ZodOptional<typeof hexColor>
|
|
134
136
|
>;
|
|
135
137
|
|
|
136
138
|
const tokenName = z.string().regex(TOKEN_NAME_PATTERN, "must be a token name such as accent-fill");
|
|
137
139
|
|
|
138
140
|
const roleTokensShape = Object.fromEntries(
|
|
139
|
-
COLOR_ROLES.map((role) => [role, tokenName.optional().describe(`The source token for the ${role} role (${COLOR_ROLE_DESCRIPTIONS[role]}) Default: the role's name in kebab case.`)]),
|
|
141
|
+
[...COLOR_ROLES, ...OPTIONAL_COLOR_ROLES].map((role) => [role, tokenName.optional().describe(`The source token for the ${role} role (${COLOR_ROLE_DESCRIPTIONS[role]}) Default: the role's name in kebab case.`)]),
|
|
140
142
|
) as Record<
|
|
141
|
-
|
|
143
|
+
ColorRole | OptionalColorRole,
|
|
142
144
|
z.ZodOptional<typeof tokenName>
|
|
143
145
|
>;
|
|
144
146
|
|
|
@@ -581,6 +583,16 @@ const footageSchema = z
|
|
|
581
583
|
.enum(CAPTION_STYLES)
|
|
582
584
|
.default("phrase")
|
|
583
585
|
.describe("phrase (the default): 2-6 words of plain text with a soft shadow; highlight: a pill that lights each word as it is said."),
|
|
586
|
+
captionHighlightStyle: z
|
|
587
|
+
.enum(CAPTION_HIGHLIGHT_STYLES)
|
|
588
|
+
.default("text")
|
|
589
|
+
.describe('How a highlight caption lights the word being said: text (the default) colours it captionHighlight; box puts it on a rounded box of brand.colors.captionHighlightBox with its text in captionHighlightText (both then required).'),
|
|
590
|
+
overlayMinSpacing: z
|
|
591
|
+
.number()
|
|
592
|
+
.min(0)
|
|
593
|
+
.max(60)
|
|
594
|
+
.optional()
|
|
595
|
+
.describe("The least seconds between the starts of two EDL overlays (the app's budget, e.g. 8); without it, only one overlay at a time."),
|
|
584
596
|
captionPreset: z
|
|
585
597
|
.enum(CAPTION_PRESETS)
|
|
586
598
|
.optional()
|
|
@@ -597,6 +609,21 @@ const footageSchema = z
|
|
|
597
609
|
.max(100)
|
|
598
610
|
.optional()
|
|
599
611
|
.describe("Words a caption card must not end on (they move to the next card), compared lower-case; a number always keeps with the next word. Without it, the language's default (pl: one-letter words and short prepositions, en: articles); [] keeps numbers only."),
|
|
612
|
+
captionMaxWords: z.number().int().min(1).max(12).optional().describe("The words a caption card aims at (1-12, a brand's words per caption); without it, 4 for highlight and 6 for phrase captions."),
|
|
613
|
+
captionMinWords: z
|
|
614
|
+
.number()
|
|
615
|
+
.int()
|
|
616
|
+
.min(1)
|
|
617
|
+
.max(4)
|
|
618
|
+
.optional()
|
|
619
|
+
.describe("The fewest words a caption card shows (1-4; 2 means never a one-word card): a short card joins the one before it or takes words from it; without it, cards stay as cut."),
|
|
620
|
+
captionMaxCharacters: z
|
|
621
|
+
.number()
|
|
622
|
+
.int()
|
|
623
|
+
.min(8)
|
|
624
|
+
.max(200)
|
|
625
|
+
.optional()
|
|
626
|
+
.describe("The most characters a short card's join may make (8-200, what fits the caption's width); without it, no limit."),
|
|
600
627
|
edit: z
|
|
601
628
|
.strictObject({
|
|
602
629
|
zoomPercent: z.number().min(105).max(112).default(108).describe("How far a zoom cut punches in (105-112 %, default 108)."),
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getContrastRatio, type BrandColors } from "../config/colors.js";
|
|
2
|
+
import type { FootageFilm } from "./film.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* How a footage film's `highlight` captions light the word being said (issue #1199): its text in `captionHighlight`
|
|
6
|
+
* (`text`), or the word on a rounded box of `captionHighlightBox` with its text in `captionHighlightText` (`box`).
|
|
7
|
+
* The render and the draft both draw what this resolves.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type CaptionHighlightLook = { style: "text"; color: string } | { style: "box"; box: string; text: string };
|
|
11
|
+
|
|
12
|
+
export type CaptionHighlightResult = { ok: true; look: CaptionHighlightLook } | { ok: false; error: string };
|
|
13
|
+
|
|
14
|
+
/** The colours the look reads. */
|
|
15
|
+
export type CaptionHighlightColors = Pick<BrandColors, "captionHighlight" | "captionHighlightBox" | "captionHighlightText">;
|
|
16
|
+
|
|
17
|
+
/** How long a word stays lit from its start, in seconds (render and draft alike). */
|
|
18
|
+
export const CAPTION_HIGHLIGHT_SECONDS = 0.32;
|
|
19
|
+
|
|
20
|
+
/** The box's padding beside the lit word, in font sizes; above and below, the line's own height is the room. */
|
|
21
|
+
export const CAPTION_HIGHLIGHT_BOX_PADDING_EM = 0.15;
|
|
22
|
+
|
|
23
|
+
/** The box's corner radius, in px: a little over half the pill's 22 px, so the box nests in the pill's rounding. */
|
|
24
|
+
export const CAPTION_HIGHLIGHT_BOX_RADIUS = 12;
|
|
25
|
+
|
|
26
|
+
/** The film's highlight look, or an error naming the missing brand colours when it asks for a box without them. */
|
|
27
|
+
export function getCaptionHighlight(film: Pick<FootageFilm, "captionHighlightStyle">, colors: CaptionHighlightColors): CaptionHighlightResult {
|
|
28
|
+
if ((film.captionHighlightStyle ?? "text") === "text") return { ok: true, look: { style: "text", color: colors.captionHighlight } };
|
|
29
|
+
const { captionHighlightBox: box, captionHighlightText: text } = colors;
|
|
30
|
+
if (box === undefined || text === undefined) {
|
|
31
|
+
const missing = [box === undefined ? "captionHighlightBox" : null, text === undefined ? "captionHighlightText" : null].filter((role) => role !== null);
|
|
32
|
+
return { ok: false, error: `captionHighlightStyle "box" needs the brand colours ${missing.join(" and ")} (brand.colors or brand.tokensFrom).` };
|
|
33
|
+
}
|
|
34
|
+
return { ok: true, look: { style: "box", box, text } };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface CaptionHighlightContrast {
|
|
38
|
+
/** The lit word's text (`captionHighlightText`) against its box (`captionHighlightBox`). */
|
|
39
|
+
textOnBox: number;
|
|
40
|
+
/** The box (`captionHighlightBox`) against the pill (`captionBackground`). */
|
|
41
|
+
boxOnPill: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The WCAG contrast ratios of a `box` highlight, for the app to warn on (the kit never changes the colours): the lit
|
|
46
|
+
* text on its box, and the box on the pill. Null when either box colour is missing.
|
|
47
|
+
*/
|
|
48
|
+
export function getCaptionHighlightContrast(colors: Pick<BrandColors, "captionBackground" | "captionHighlightBox" | "captionHighlightText">): CaptionHighlightContrast | null {
|
|
49
|
+
const { captionHighlightBox: box, captionHighlightText: text } = colors;
|
|
50
|
+
if (box === undefined || text === undefined) return null;
|
|
51
|
+
return { textOnBox: getContrastRatio(text, box), boxOnPill: getContrastRatio(box, colors.captionBackground) };
|
|
52
|
+
}
|
package/src/footage/captions.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
|
|
3
|
-
import { CAPTION_LINE_HEIGHT, CAPTION_PILL_PADDING, captionChunks, resolveLayout, splitAfterKept, type CaptionLayout, type LayoutOverride } from "../compose/timeline.js";
|
|
3
|
+
import { CAPTION_LINE_HEIGHT, CAPTION_PILL_PADDING, balanceCaptionGroups, captionChunks, resolveLayout, splitAfterKept, type CaptionLayout, type LayoutOverride } from "../compose/timeline.js";
|
|
4
4
|
import type { BrandFont } from "../config/config.js";
|
|
5
5
|
import { readCharacterMap, type CharacterMap } from "../og/character-map.js";
|
|
6
6
|
import type { TimedWord } from "../voice/voiceover.js";
|
|
@@ -31,15 +31,22 @@ export interface PhraseChunkOptions {
|
|
|
31
31
|
* phrase on one (a full phrase hands it to the next); punctuation still does. Absent: every word may end one.
|
|
32
32
|
*/
|
|
33
33
|
keepsWithNext?: (word: TimedWord) => boolean;
|
|
34
|
+
/** The most words a phrase holds; default 6. */
|
|
35
|
+
maxWords?: number;
|
|
36
|
+
/** The fewest words a phrase shows, across a pause too (`balanceCaptionGroups`); default 1: phrases stay as cut. */
|
|
37
|
+
minWords?: number;
|
|
38
|
+
/** The most characters a short phrase's join may make (`balanceCaptionGroups`); absent: no limit. */
|
|
39
|
+
maxCharacters?: number;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|
|
37
|
-
* The words as phrases of 2-6: a phrase ends at punctuation, after six words or at a pause, never on a
|
|
38
|
-
* `keepsWithNext` keeps (unless punctuation ends it or the phrase holds kept words only); a single word left
|
|
39
|
-
* joins the phrase before it when that one has room and no pause separates them.
|
|
43
|
+
* The words as phrases of 2-6: a phrase ends at punctuation, after six words (`maxWords`) or at a pause, never on a
|
|
44
|
+
* word `keepsWithNext` keeps (unless punctuation ends it or the phrase holds kept words only); a single word left
|
|
45
|
+
* alone joins the phrase before it when that one has room and no pause separates them. With `minWords`, short phrases
|
|
46
|
+
* are then evened out (`balanceCaptionGroups`).
|
|
40
47
|
*/
|
|
41
48
|
export function phraseChunks(words: TimedWord[], options: PhraseChunkOptions = {}): PhraseChunk[] {
|
|
42
|
-
const { keepsWithNext } = options;
|
|
49
|
+
const { keepsWithNext, maxWords = MAX_PHRASE_WORDS, minWords = 1, maxCharacters } = options;
|
|
43
50
|
const groups: TimedWord[][] = [];
|
|
44
51
|
let current: TimedWord[] = [];
|
|
45
52
|
words.forEach((word, index) => {
|
|
@@ -53,7 +60,7 @@ export function phraseChunks(words: TimedWord[], options: PhraseChunkOptions = {
|
|
|
53
60
|
if (/[.,?!:;…]$/u.test(word.text)) {
|
|
54
61
|
groups.push(current);
|
|
55
62
|
current = [];
|
|
56
|
-
} else if (current.length
|
|
63
|
+
} else if (current.length >= maxWords) {
|
|
57
64
|
const { chunk, carry } = splitAfterKept(current, keepsWithNext);
|
|
58
65
|
groups.push(chunk);
|
|
59
66
|
current = carry;
|
|
@@ -66,14 +73,14 @@ export function phraseChunks(words: TimedWord[], options: PhraseChunkOptions = {
|
|
|
66
73
|
const first = group[0] as TimedWord;
|
|
67
74
|
const last = previous?.at(-1);
|
|
68
75
|
const isClose = last !== undefined && first.start - last.end <= PHRASE_GAP_SECONDS;
|
|
69
|
-
if (previous !== undefined && group.length < MIN_PHRASE_WORDS && previous.length <
|
|
76
|
+
if (previous !== undefined && group.length < MIN_PHRASE_WORDS && previous.length < maxWords && isClose) previous.push(...group);
|
|
70
77
|
else merged.push(group);
|
|
71
78
|
}
|
|
72
|
-
return merged.map((group) => ({ words: group, start: (group[0] as TimedWord).start, end: (group[group.length - 1] as TimedWord).end }));
|
|
79
|
+
return balanceCaptionGroups(merged, { minWords, maxWords, maxCharacters }).map((group) => ({ words: group, start: (group[0] as TimedWord).start, end: (group[group.length - 1] as TimedWord).end }));
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
/** What a film's caption cards are cut by; without `language`, no language default applies. */
|
|
76
|
-
export type CaptionWordsFilm = Pick<FootageFilm, "captionKeepWithNext"> & { language?: string };
|
|
83
|
+
export type CaptionWordsFilm = Pick<FootageFilm, "captionKeepWithNext" | "captionMinWords" | "captionMaxWords" | "captionMaxCharacters"> & { language?: string };
|
|
77
84
|
|
|
78
85
|
const NUMBER_PATTERN = /^\d+(?:[.,]\d+)*$/u;
|
|
79
86
|
|
|
@@ -89,12 +96,19 @@ export function getCaptionKeepsWithNext(film: CaptionWordsFilm): (word: TimedWor
|
|
|
89
96
|
|
|
90
97
|
/**
|
|
91
98
|
* A footage film's caption cards in film time: none without captions, `captionChunks` for `highlight`, `phraseChunks`
|
|
92
|
-
* otherwise; both keep the film's kept words with the next (`getCaptionKeepsWithNext`)
|
|
99
|
+
* otherwise; both keep the film's kept words with the next (`getCaptionKeepsWithNext`) and take the film's
|
|
100
|
+
* `captionMaxWords`, `captionMinWords` and `captionMaxCharacters` (absent: each style's defaults, no evening out). The
|
|
101
|
+
* render and the draft share it.
|
|
93
102
|
*/
|
|
94
103
|
export function getFootageCaptionChunks(film: CaptionWordsFilm & Pick<FootageFilm, "captions" | "captionStyle">, words: TimedWord[]): PhraseChunk[] {
|
|
95
104
|
if (!film.captions) return [];
|
|
96
|
-
const
|
|
97
|
-
|
|
105
|
+
const options = {
|
|
106
|
+
keepsWithNext: getCaptionKeepsWithNext(film),
|
|
107
|
+
...(film.captionMaxWords === undefined ? {} : { maxWords: film.captionMaxWords }),
|
|
108
|
+
...(film.captionMinWords === undefined ? {} : { minWords: film.captionMinWords }),
|
|
109
|
+
...(film.captionMaxCharacters === undefined ? {} : { maxCharacters: film.captionMaxCharacters }),
|
|
110
|
+
};
|
|
111
|
+
return film.captionStyle === "highlight" ? captionChunks(words, options) : phraseChunks(words, options);
|
|
98
112
|
}
|
|
99
113
|
|
|
100
114
|
/** When a caption chunk is on screen, in film seconds. */
|