@anvpx/motion-cli 0.1.6 → 0.1.7

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.
@@ -1,2 +1,10 @@
1
1
  import type { Command } from "../types.ts";
2
+ type BuiltWord = {
3
+ w: string;
4
+ start: number;
5
+ end: number;
6
+ };
7
+ /** Split a scene into balanced cue chunks, at most CUE_MAX_WORDS each. */
8
+ export declare const splitCueWords: (words: readonly BuiltWord[]) => BuiltWord[][];
2
9
  export declare const captionsCommand: Command;
10
+ export {};
@@ -61,7 +61,21 @@ const sceneWords = (row, bound, fallback) => {
61
61
  }
62
62
  return { words, omitted };
63
63
  };
64
- /** One `add /scenes/-` op per narrated scene, with a per-scene captioned/omitted report. */
64
+ /** Cue budget: broadcast captions rarely hold more than this many words. */
65
+ const CUE_MAX_WORDS = 12;
66
+ /** Split a scene into balanced cue chunks, at most CUE_MAX_WORDS each. */
67
+ export const splitCueWords = (words) => {
68
+ if (words.length <= CUE_MAX_WORDS)
69
+ return [[...words]];
70
+ const count = Math.ceil(words.length / CUE_MAX_WORDS);
71
+ const size = Math.ceil(words.length / count);
72
+ const cues = [];
73
+ for (let i = 0; i < words.length; i += size) {
74
+ cues.push(words.slice(i, i + size));
75
+ }
76
+ return cues;
77
+ };
78
+ /** One `add /scenes/-` op per caption cue, with a per-scene captioned/omitted report. */
65
79
  const planFromManifest = (board, manifest) => {
66
80
  const timed = baseTimeline(board);
67
81
  if (typeof timed === "number")
@@ -88,19 +102,43 @@ const planFromManifest = (board, manifest) => {
88
102
  continue;
89
103
  }
90
104
  scenes += 1;
91
- ops.push({
92
- op: "add",
93
- path: "/scenes/-",
94
- value: {
95
- id: `cap-${row.id}`,
96
- type: "caption",
97
- layer: "overlay",
98
- over: row.id,
99
- duration: bound,
100
- props: { words: built.words },
101
- },
105
+ const cues = splitCueWords(built.words);
106
+ cues.forEach((cue, index) => {
107
+ const first = cue[0];
108
+ const last = cue[cue.length - 1];
109
+ if (first === undefined || last === undefined)
110
+ return;
111
+ const single = cues.length === 1;
112
+ let offset = single ? 0 : round(Math.max(0, first.start - 0.12));
113
+ let duration = single
114
+ ? bound
115
+ : round(Math.max(0.35, Math.min(bound, last.end + 0.25) - offset));
116
+ if (offset + duration > bound)
117
+ duration = round(bound - offset);
118
+ if (duration <= 0) {
119
+ offset = 0;
120
+ duration = bound;
121
+ }
122
+ const cueWords = cue.map((word) => ({
123
+ w: word.w,
124
+ start: single ? word.start : round(Math.max(0, word.start - offset)),
125
+ end: single ? word.end : round(Math.max(0.01, word.end - offset)),
126
+ }));
127
+ ops.push({
128
+ op: "add",
129
+ path: "/scenes/-",
130
+ value: {
131
+ id: cues.length === 1 ? `cap-${row.id}` : `cap-${row.id}-${index + 1}`,
132
+ type: "caption",
133
+ layer: "overlay",
134
+ over: row.id,
135
+ ...(offset > 0 ? { offset } : {}),
136
+ duration,
137
+ props: { words: cueWords },
138
+ },
139
+ });
102
140
  });
103
- report.push(`scene "${row.id}": ${built.words.length} words captioned` +
141
+ report.push(`scene "${row.id}": ${built.words.length} words in ${cues.length} cue(s)` +
104
142
  (built.omitted > 0 ? `, ${built.omitted} omitted past ${bound}s` : ""));
105
143
  }
106
144
  if (scenes === 0 || words === 0) {
@@ -12,8 +12,8 @@ import type { Command } from "../types.ts";
12
12
  * at real versions) or choiceB (bundle into one tarball); either lands with
13
13
  * a version bump of core manifest + this pin + plugin.json together.
14
14
  */
15
- export declare const PINNED_CORE_VERSION = "0.1.6";
16
- export declare const PINNED_NPX = "npx -y @anvpx/motion@0.1.6";
15
+ export declare const PINNED_CORE_VERSION = "0.1.7";
16
+ export declare const PINNED_NPX = "npx -y @anvpx/motion@0.1.7";
17
17
  /** Skill file whose sha256 must survive `plugin install` byte for byte. */
18
18
  export declare const PLUGIN_SKILL: string;
19
19
  export interface PluginEnv {
@@ -17,7 +17,7 @@ import { EXIT } from "../exit-codes.js";
17
17
  * at real versions) or choiceB (bundle into one tarball); either lands with
18
18
  * a version bump of core manifest + this pin + plugin.json together.
19
19
  */
20
- export const PINNED_CORE_VERSION = "0.1.6";
20
+ export const PINNED_CORE_VERSION = "0.1.7";
21
21
  export const PINNED_NPX = `npx -y @anvpx/motion@${PINNED_CORE_VERSION}`;
22
22
  /** Skill file whose sha256 must survive `plugin install` byte for byte. */
23
23
  export const PLUGIN_SKILL = join("skills", "motion-kit", "SKILL.md");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvpx/motion-cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "The mk CLI for @anvpx/motion: validate, preview, approve and render storyboards.",
5
5
  "license": "MIT",
6
6
  "author": "anvpx",
@@ -30,10 +30,10 @@
30
30
  "dist/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@anvpx/motion-audio": "0.1.6",
34
- "@anvpx/motion-build": "0.1.6",
35
- "@anvpx/motion-schema": "0.1.6",
36
- "@anvpx/motion-templates": "0.1.6"
33
+ "@anvpx/motion-audio": "0.1.7",
34
+ "@anvpx/motion-build": "0.1.7",
35
+ "@anvpx/motion-schema": "0.1.7",
36
+ "@anvpx/motion-templates": "0.1.7"
37
37
  },
38
38
  "scripts": {
39
39
  "test:integration": "vitest run --config vitest.integration.config.ts"