@zenaigc/zenmcp 0.0.0-stage → 0.1.1

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.
Files changed (66) hide show
  1. package/INSTALL.md +77 -0
  2. package/README.md +53 -2
  3. package/dist/src/acquire/download.js +152 -0
  4. package/dist/src/acquire/errors.js +8 -0
  5. package/dist/src/acquire/share.js +67 -0
  6. package/dist/src/acquire/social.js +98 -0
  7. package/dist/src/acquire/trim.js +95 -0
  8. package/dist/src/assets/files.js +29 -0
  9. package/dist/src/assets/generator.js +141 -0
  10. package/dist/src/assets/images.js +90 -0
  11. package/dist/src/assets/index.js +3 -0
  12. package/dist/src/assets/model-library.js +87 -0
  13. package/dist/src/assets/upload-cache.js +36 -0
  14. package/dist/src/contract/cloud-v1.js +334 -0
  15. package/dist/src/core/hash.js +18 -0
  16. package/dist/src/core/index.js +4 -0
  17. package/dist/src/core/job-store.js +251 -0
  18. package/dist/src/core/safety.js +43 -0
  19. package/dist/src/core/schema.js +295 -0
  20. package/dist/src/doctor.js +22 -0
  21. package/dist/src/effects/check.js +19 -0
  22. package/dist/src/effects/font.js +78 -0
  23. package/dist/src/effects/index.js +188 -0
  24. package/dist/src/engine/card.js +50 -0
  25. package/dist/src/engine/direct.js +493 -0
  26. package/dist/src/engine/generate.js +234 -0
  27. package/dist/src/engine/index.js +3 -0
  28. package/dist/src/engine/media.js +24 -0
  29. package/dist/src/engine/steps.js +444 -0
  30. package/dist/src/engine/storage.js +90 -0
  31. package/dist/src/gateway/attempt-store.js +110 -0
  32. package/dist/src/gateway/budget.js +39 -0
  33. package/dist/src/gateway/cloud-gateway.js +141 -0
  34. package/dist/src/gateway/config.js +10 -0
  35. package/dist/src/gateway/device-auth.js +53 -0
  36. package/dist/src/gateway/errors.js +105 -0
  37. package/dist/src/gateway/http.js +124 -0
  38. package/dist/src/gateway/index.js +8 -0
  39. package/dist/src/gateway/paid-runner.js +376 -0
  40. package/dist/src/gateway/types.js +42 -0
  41. package/dist/src/inspect/index.js +276 -0
  42. package/dist/src/inspect/media.js +43 -0
  43. package/dist/src/mcp/server.js +177 -0
  44. package/dist/src/models/wan3/index.js +173 -0
  45. package/dist/src/models/wan3/limits.js +25 -0
  46. package/dist/src/timeline/conform.js +255 -0
  47. package/dist/src/timeline/cuts.js +225 -0
  48. package/dist/src/timeline/diff.js +82 -0
  49. package/dist/src/timeline/errors.js +8 -0
  50. package/dist/src/timeline/ffmpeg.js +164 -0
  51. package/dist/src/timeline/index.js +6 -0
  52. package/dist/src/timeline/params.js +46 -0
  53. package/dist/src/timeline/probe.js +98 -0
  54. package/dist/src/timeline/types.js +1 -0
  55. package/dist/templates/pop-title/README.md +18 -0
  56. package/dist/templates/pop-title/index.html +102 -0
  57. package/dist/templates/pop-title/pop-title.js +97 -0
  58. package/dist/templates/pop-title/render.js +42 -0
  59. package/dist/templates/pop-title/size-1080/index.html +102 -0
  60. package/dist/templates/pop-title/variables.example.json +9 -0
  61. package/dist/templates/pop-title/vendor/FONT.md +10 -0
  62. package/dist/templates/pop-title/vendor/NotoSansCJKsc-Bold.otf +0 -0
  63. package/dist/templates/pop-title/vendor/OFL.txt +92 -0
  64. package/dist/templates/pop-title/vendor/gsap.min.js +11 -0
  65. package/package.json +35 -4
  66. package/skills/zenmcp/SKILL.md +27 -0
@@ -0,0 +1,82 @@
1
+ import { TimelineError } from "./errors.js";
2
+ import { collectStderr, readRawFrames, spawnIo, waitClose } from "./ffmpeg.js";
3
+ import { timelineParams } from "./params.js";
4
+ import { probe } from "./probe.js";
5
+ /**
6
+ * Mean absolute difference of successive frames.
7
+ *
8
+ * Index i compares frame i and frame i+1. The clip is scaled to `width`
9
+ * with proportional height (nearest integer, at least 1) and read as
10
+ * gray, one frame at a time. A hard cut whose new shot starts at frame f
11
+ * therefore peaks at index f-1.
12
+ */
13
+ export async function frameDiffs(path, opts) {
14
+ const width = opts?.width ?? timelineParams.diffWidth;
15
+ if (!Number.isInteger(width) || width <= 0) {
16
+ throw new TimelineError("bad_params", `diff width must be a positive integer, got ${width}`);
17
+ }
18
+ const meta = await probe(path);
19
+ const height = proportionalHeight(meta.width, meta.height, width);
20
+ const frameBytes = width * height;
21
+ const decoder = spawnIo("ffmpeg", [
22
+ "-v",
23
+ "error",
24
+ "-i",
25
+ path,
26
+ "-map",
27
+ "0:v:0",
28
+ "-fps_mode",
29
+ "passthrough",
30
+ "-vf",
31
+ `scale=${width}:${height}:flags=area`,
32
+ "-f",
33
+ "rawvideo",
34
+ "-pix_fmt",
35
+ "gray",
36
+ "pipe:1",
37
+ ], "pipe");
38
+ const stderr = collectStderr(decoder.stderr);
39
+ const done = waitClose(decoder);
40
+ const diffs = [];
41
+ let previous = null;
42
+ if (decoder.stdout === null) {
43
+ decoder.kill("SIGKILL");
44
+ await done.catch(() => undefined);
45
+ throw new TimelineError("ffmpeg_failed", "frame diff decoder has no stdout");
46
+ }
47
+ try {
48
+ await readRawFrames(decoder.stdout, frameBytes, (frame) => {
49
+ if (previous !== null) {
50
+ diffs.push(meanAbsDiff(previous, frame));
51
+ }
52
+ previous = frame;
53
+ return Promise.resolve("continue");
54
+ });
55
+ }
56
+ catch (error) {
57
+ decoder.kill("SIGKILL");
58
+ try {
59
+ await done;
60
+ }
61
+ catch (spawnError) {
62
+ throw spawnError;
63
+ }
64
+ throw error;
65
+ }
66
+ const code = await done;
67
+ if (code !== 0) {
68
+ throw new TimelineError("ffmpeg_failed", `frame diff decode failed (${code})${stderr() ? `\n${stderr()}` : ""}`);
69
+ }
70
+ return Float64Array.from(diffs);
71
+ }
72
+ function proportionalHeight(srcWidth, srcHeight, width) {
73
+ return Math.max(1, Math.round((srcHeight * width) / srcWidth));
74
+ }
75
+ function meanAbsDiff(left, right) {
76
+ const n = left.length;
77
+ let sum = 0;
78
+ for (let i = 0; i < n; i += 1) {
79
+ sum += Math.abs(left[i] - right[i]);
80
+ }
81
+ return sum / n;
82
+ }
@@ -0,0 +1,8 @@
1
+ export class TimelineError extends Error {
2
+ code;
3
+ constructor(code, message) {
4
+ super(message);
5
+ this.name = "TimelineError";
6
+ this.code = code;
7
+ }
8
+ }
@@ -0,0 +1,164 @@
1
+ import { execFile, spawn } from "node:child_process";
2
+ import { once } from "node:events";
3
+ import { Readable } from "node:stream";
4
+ import { promisify } from "node:util";
5
+ import { TimelineError } from "./errors.js";
6
+ const execFileAsync = promisify(execFile);
7
+ const STDERR_LIMIT = 4000;
8
+ export async function runExec(command, args) {
9
+ try {
10
+ const { stdout } = await execFileAsync(command, args, {
11
+ maxBuffer: 16 * 1024 * 1024,
12
+ encoding: "utf8",
13
+ });
14
+ return stdout;
15
+ }
16
+ catch (error) {
17
+ const stderr = stderrOf(error);
18
+ const message = error instanceof Error ? error.message : String(error);
19
+ throw new TimelineError("ffmpeg_failed", `${command} failed: ${message}${stderr ? `\n${stderr}` : ""}`);
20
+ }
21
+ }
22
+ function stderrOf(error) {
23
+ if (typeof error !== "object" || error === null || !("stderr" in error)) {
24
+ return "";
25
+ }
26
+ const stderr = error.stderr;
27
+ if (typeof stderr === "string") {
28
+ return stderr.slice(0, STDERR_LIMIT);
29
+ }
30
+ if (Buffer.isBuffer(stderr)) {
31
+ return stderr.toString("utf8").slice(0, STDERR_LIMIT);
32
+ }
33
+ return "";
34
+ }
35
+ export function spawnIo(command, args, stdout) {
36
+ const child = spawn(command, args, {
37
+ stdio: [stdout === "pipe" ? "ignore" : "pipe", stdout, "pipe"],
38
+ });
39
+ child.on("error", () => {
40
+ // The close/error waiter owns the failure. This listener only
41
+ // prevents an unhandled 'error' event when the binary is missing.
42
+ });
43
+ return child;
44
+ }
45
+ export function collectStderr(stream) {
46
+ const chunks = [];
47
+ let size = 0;
48
+ stream?.on("data", (chunk) => {
49
+ const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
50
+ if (size >= STDERR_LIMIT) {
51
+ return;
52
+ }
53
+ chunks.push(buf);
54
+ size += buf.length;
55
+ });
56
+ return () => Buffer.concat(chunks).toString("utf8").slice(0, STDERR_LIMIT);
57
+ }
58
+ export function waitClose(child) {
59
+ if (child.exitCode !== null) {
60
+ return Promise.resolve(child.exitCode);
61
+ }
62
+ let settled = false;
63
+ const result = new Promise((resolve, reject) => {
64
+ const fail = (error) => {
65
+ if (settled) {
66
+ return;
67
+ }
68
+ settled = true;
69
+ reject(new TimelineError("ffmpeg_failed", error.message));
70
+ };
71
+ child.once("error", fail);
72
+ child.once("close", (code) => {
73
+ if (settled) {
74
+ return;
75
+ }
76
+ settled = true;
77
+ resolve(code ?? 1);
78
+ });
79
+ });
80
+ // Spawn can fail before the caller reaches `await`. A handler attached
81
+ // now marks that rejection handled, so Node does not exit. `await` on
82
+ // the same promise still throws the TimelineError.
83
+ result.catch(() => undefined);
84
+ return result;
85
+ }
86
+ export async function writeRawFrame(stdin, frame) {
87
+ if (stdin.write(frame)) {
88
+ return;
89
+ }
90
+ await once(stdin, "drain");
91
+ }
92
+ /**
93
+ * Yield exact-sized frames from a rawvideo byte stream.
94
+ * A short tail at EOF is discarded. `stream` is destroyed when `onFrame`
95
+ * returns "stop", so the producer does not block on a full pipe.
96
+ */
97
+ export async function readRawFrames(stream, frameBytes, onFrame) {
98
+ const queue = new ByteQueue();
99
+ let index = 0;
100
+ try {
101
+ for await (const chunk of stream) {
102
+ queue.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
103
+ while (true) {
104
+ const frame = queue.take(frameBytes);
105
+ if (frame === null) {
106
+ break;
107
+ }
108
+ const decision = await onFrame(frame, index);
109
+ index += 1;
110
+ if (decision === "stop") {
111
+ stream.on("error", () => {
112
+ // Stopping the producer closes the pipe on purpose.
113
+ });
114
+ stream.destroy();
115
+ return index;
116
+ }
117
+ }
118
+ }
119
+ }
120
+ catch (error) {
121
+ if (stream.destroyed) {
122
+ return index;
123
+ }
124
+ throw error;
125
+ }
126
+ return index;
127
+ }
128
+ class ByteQueue {
129
+ chunks = [];
130
+ head = 0;
131
+ available = 0;
132
+ push(chunk) {
133
+ if (chunk.length === 0) {
134
+ return;
135
+ }
136
+ this.chunks.push(chunk);
137
+ this.available += chunk.length;
138
+ }
139
+ take(size) {
140
+ if (this.available < size) {
141
+ return null;
142
+ }
143
+ const out = Buffer.allocUnsafe(size);
144
+ let written = 0;
145
+ while (written < size) {
146
+ const chunk = this.chunks[0];
147
+ if (chunk === undefined) {
148
+ throw new TimelineError("ffmpeg_failed", "raw frame queue underflow");
149
+ }
150
+ const have = chunk.length - this.head;
151
+ const need = size - written;
152
+ const n = Math.min(have, need);
153
+ chunk.copy(out, written, this.head, this.head + n);
154
+ written += n;
155
+ this.head += n;
156
+ this.available -= n;
157
+ if (this.head === chunk.length) {
158
+ this.chunks.shift();
159
+ this.head = 0;
160
+ }
161
+ }
162
+ return out;
163
+ }
164
+ }
@@ -0,0 +1,6 @@
1
+ export { TimelineError } from "./errors.js";
2
+ export { PARAMS_VERSION, timelineParams } from "./params.js";
3
+ export { probe } from "./probe.js";
4
+ export { frameDiffs } from "./diff.js";
5
+ export { detectCuts, locateCuts } from "./cuts.js";
6
+ export { conform } from "./conform.js";
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Timeline defaults, version 2.
3
+ *
4
+ * Calibrated only on the three local reference videos already on disk and
5
+ * the synthetic clips in test/timeline. This is not a claim about other
6
+ * footage. The absolute diff gate of 8–12 is not used. These defaults were
7
+ * not adjusted afterward to force those reference videos onto a hand log.
8
+ *
9
+ * - diffWidth (64–160, default 96): analysis width in pixels. Height follows
10
+ * the source aspect ratio.
11
+ * - madK (4–12, default 8): unknown-cut gate is median(diffs) + madK * MAD.
12
+ * MAD is the raw median absolute deviation, not the 1.4826 sigma estimate.
13
+ * locateCuts does not read this gate.
14
+ * - gateSlack (0–2, default 1): a sample must clear that gate by more than
15
+ * this many gray levels. One level keeps 8-bit rounding inside a steady
16
+ * ramp from becoming a cut. It is not a content threshold.
17
+ * - maxSpan (2–4, default 3): a merged run of more than this many high-diff
18
+ * samples is gradual motion, not a hard cut.
19
+ * - locateWindow (default 4 frames): half-width of an expected-cut search.
20
+ * Legal only when it is <= half the shortest segment of that call.
21
+ * - locateProminenceRatio (1.5–3, default 2): inside one window, the peak
22
+ * must be at least this many times the median of the other samples.
23
+ * - locateProminenceDelta (0.5–4, default 1): the peak must also exceed that
24
+ * median by this many gray levels, so a flat window cannot promote noise.
25
+ * - locateShoulderRatio (0.4–0.75, default 0.5): adjacent samples at least
26
+ * this fraction of the peak join the same transition.
27
+ * - ambiguityRatio (1.2–3, default 1.5): a second local peak within
28
+ * best/ratio is not a unique cut.
29
+ * - encodeCrf (18–23, default 18) and encodePreset (default veryfast):
30
+ * output quality only.
31
+ */
32
+ export const PARAMS_VERSION = 2;
33
+ export const timelineParams = {
34
+ version: PARAMS_VERSION,
35
+ diffWidth: 96,
36
+ madK: 8,
37
+ gateSlack: 1,
38
+ maxSpan: 3,
39
+ locateWindow: 4,
40
+ locateProminenceRatio: 2,
41
+ locateProminenceDelta: 1,
42
+ locateShoulderRatio: 0.5,
43
+ ambiguityRatio: 1.5,
44
+ encodeCrf: 18,
45
+ encodePreset: "veryfast",
46
+ };
@@ -0,0 +1,98 @@
1
+ import { TimelineError } from "./errors.js";
2
+ import { runExec } from "./ffmpeg.js";
3
+ export async function probe(path) {
4
+ // v:0 is ffprobe's specifier for the first video stream, the same stream
5
+ // ffmpeg selects with -map 0:v:0. Audio is a separate selection so a
6
+ // later video stream cannot replace the first one or hide the audio.
7
+ const stdout = await runExec("ffprobe", [
8
+ "-v",
9
+ "error",
10
+ "-count_frames",
11
+ "-print_format",
12
+ "json",
13
+ "-show_streams",
14
+ "-select_streams",
15
+ "v:0",
16
+ path,
17
+ ]);
18
+ const audioStdout = await runExec("ffprobe", [
19
+ "-v",
20
+ "error",
21
+ "-print_format",
22
+ "json",
23
+ "-show_entries",
24
+ "stream=codec_type",
25
+ "-select_streams",
26
+ "a",
27
+ path,
28
+ ]);
29
+ const parsed = parseProbeJson(stdout);
30
+ const audio = parseProbeJson(audioStdout);
31
+ const video = parsed.streams?.[0];
32
+ if (video?.codec_type !== "video") {
33
+ throw new TimelineError("probe_failed", `no video stream in ${path}`);
34
+ }
35
+ const width = positiveInt(video.width, "width");
36
+ const height = positiveInt(video.height, "height");
37
+ const fps = parseFps(video.r_frame_rate, video.avg_frame_rate);
38
+ const frames = parseFrameCount(video);
39
+ return {
40
+ frames,
41
+ fps,
42
+ width,
43
+ height,
44
+ has_audio: (audio.streams ?? []).some((stream) => stream.codec_type === "audio"),
45
+ };
46
+ }
47
+ function parseProbeJson(stdout) {
48
+ try {
49
+ return JSON.parse(stdout);
50
+ }
51
+ catch (error) {
52
+ const message = error instanceof Error ? error.message : String(error);
53
+ throw new TimelineError("probe_failed", `ffprobe returned invalid JSON: ${message}`);
54
+ }
55
+ }
56
+ function positiveInt(value, label) {
57
+ if (value === undefined || !Number.isInteger(value) || value <= 0) {
58
+ throw new TimelineError("probe_failed", `video ${label} is missing`);
59
+ }
60
+ return value;
61
+ }
62
+ function parseFrameCount(video) {
63
+ const raw = video.nb_read_frames ?? video.nb_frames;
64
+ if (raw === undefined) {
65
+ throw new TimelineError("probe_failed", "ffprobe did not report a frame count");
66
+ }
67
+ const frames = Number(raw);
68
+ if (!Number.isInteger(frames) || frames <= 0) {
69
+ throw new TimelineError("probe_failed", `unusable frame count ${raw}`);
70
+ }
71
+ return frames;
72
+ }
73
+ function parseFps(rFrameRate, avgFrameRate) {
74
+ const preferred = parseRate(rFrameRate);
75
+ if (preferred !== null) {
76
+ return preferred;
77
+ }
78
+ const average = parseRate(avgFrameRate);
79
+ if (average !== null) {
80
+ return average;
81
+ }
82
+ throw new TimelineError("probe_failed", `unusable frame rate ${rFrameRate ?? ""} / ${avgFrameRate ?? ""}`);
83
+ }
84
+ function parseRate(value) {
85
+ if (value === undefined) {
86
+ return null;
87
+ }
88
+ const match = /^(\d+)\/(\d+)$/.exec(value);
89
+ if (match === null) {
90
+ return null;
91
+ }
92
+ const num = Number(match[1]);
93
+ const den = Number(match[2]);
94
+ if (!Number.isInteger(num) || !Number.isInteger(den) || num <= 0 || den <= 0) {
95
+ return null;
96
+ }
97
+ return { num, den };
98
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ # pop-title
2
+
3
+ 两行逐字出现并放大的标题,叠在一条已有视频上。文案、起止帧和锚点来自变量文件。画布尺寸写在 HTML 里:`index.html` 是 480×854,`size-1080/index.html` 是 1080×1920。同一个目录不能放两个根合成,所以 1080 是子目录,并通过符号链接共用脚本、字体和底片路径。HyperFrames 不允许用变量改根合成的宽高或总时长。
4
+
5
+ 时间单位是帧。合成帧率是 `data-fps="30"`。脚本把帧换成秒:`秒 = 帧 / 30`。`startFrame` 含,`endFrame` 不含(该帧标题已完全消失)。根时长按本次实测底片写成 `9.9` 秒(297 帧 ÷ 30),换片时要改两个 HTML 的 `data-duration`,以及 `<video>` 的 `data-duration`。
6
+
7
+ 位置 `x`、`y` 是 0 到 1 的比例,锚点是标题块中心。字色 `#ffffff`,深色描边 `#1a1a1a`(0.08em),右下硬阴影 `0.08em 0.1em`。底片不进仓库:渲染前把视频放到 `assets/base.mp4`(相对各自的 `index.html`)。`size-1080` 不放指向不存在目录的符号链接。
8
+
9
+ 字体是 Noto Sans SC Bold 的实验子集,SIL OFL 1.1,见 `vendor/OFL.txt`。子集只含:测试文案第一行二变量替换上下。动画运行时是随模板附带的 GSAP 3.14.2。
10
+
11
+ ```sh
12
+ npx hyperframes@0.9.16 render \
13
+ --variables-file variables.example.json \
14
+ --fps 30 \
15
+ --output out.mp4
16
+ ```
17
+
18
+ 把 `assets/base.mp4` 换成实际底片,或在变量文件里改 `baseVideo`。换文案或时段只改变量文件,不改模板。
@@ -0,0 +1,102 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN" data-composition-variables='[
3
+ {"id":"line1","type":"string","label":"Line 1","description":"First title line. Each Unicode scalar is one glyph.","default":"测试文案第一行"},
4
+ {"id":"line2","type":"string","label":"Line 2","description":"Second title line.","default":"测试文案第二行"},
5
+ {"id":"startFrame","type":"number","label":"Start frame","description":"First frame index where glyphs begin to appear. Inclusive. Timeline seconds are frame/fps.","default":4},
6
+ {"id":"endFrame","type":"number","label":"End frame","description":"First frame index where the title is fully gone. Exclusive.","default":195},
7
+ {"id":"x","type":"number","label":"X","description":"Anchor x as a fraction of frame width, 0 to 1. The block is centered on this point.","default":0.5},
8
+ {"id":"y","type":"number","label":"Y","description":"Anchor y as a fraction of frame height, 0 to 1.","default":0.52},
9
+ {"id":"baseVideo","type":"string","label":"Base video","description":"Path to the video under this title. Audio is taken from this file.","default":"assets/base.mp4"}
10
+ ]'>
11
+ <head>
12
+ <meta charset="UTF-8" />
13
+ <meta name="viewport" content="width=480, height=854" />
14
+ <title>pop-title 480x854</title>
15
+ <script src="./vendor/gsap.min.js"></script>
16
+ <style>
17
+ html, body { margin: 0; background: #000; }
18
+ #root {
19
+ position: relative;
20
+ width: 480px;
21
+ height: 854px;
22
+ overflow: hidden;
23
+ background: #000;
24
+ }
25
+ #base {
26
+ position: absolute;
27
+ inset: 0;
28
+ width: 100%;
29
+ height: 100%;
30
+ object-fit: fill;
31
+ z-index: 0;
32
+ }
33
+ #title-slot {
34
+ position: absolute;
35
+ inset: 0;
36
+ z-index: 2;
37
+ pointer-events: none;
38
+ }
39
+ #title-block {
40
+ position: absolute;
41
+ transform: translate(-50%, -50%);
42
+ text-align: center;
43
+ white-space: nowrap;
44
+ }
45
+ .line { display: block; line-height: 1.08; }
46
+ @font-face {
47
+ font-family: "Noto Sans SC";
48
+ font-style: normal;
49
+ font-weight: 700;
50
+ src: url("./vendor/NotoSansCJKsc-Bold.otf") format("opentype");
51
+ }
52
+ .glyph {
53
+ display: inline-block;
54
+ color: #ffffff;
55
+ font-family: "Noto Sans SC", sans-serif;
56
+ font-weight: 700;
57
+ font-style: normal;
58
+ -webkit-text-stroke: 0.08em #1a1a1a;
59
+ paint-order: stroke fill;
60
+ text-shadow: 0.08em 0.1em 0 rgba(0, 0, 0, 0.72);
61
+ opacity: 0;
62
+ transform: scale(0.35);
63
+ transform-origin: center center;
64
+ }
65
+ </style>
66
+ </head>
67
+ <body>
68
+ <div
69
+ id="root"
70
+ data-composition-id="pop-title"
71
+ data-start="0"
72
+ data-duration="9.9"
73
+ data-fps="30"
74
+ data-width="480"
75
+ data-height="854"
76
+ >
77
+ <video
78
+ id="base"
79
+ data-var-src="baseVideo"
80
+ src="assets/base.mp4"
81
+ data-start="0"
82
+ data-duration="9.9"
83
+ data-track-index="0"
84
+ data-has-audio="true"
85
+ playsinline
86
+ ></video>
87
+ <div
88
+ id="title-slot"
89
+ class="clip"
90
+ data-start="0"
91
+ data-duration="9.9"
92
+ data-track-index="1"
93
+ >
94
+ <span id="title-block">
95
+ <span class="line" id="line1"></span>
96
+ <span class="line" id="line2"></span>
97
+ </span>
98
+ </div>
99
+ </div>
100
+ <script src="./pop-title.js"></script>
101
+ </body>
102
+ </html>
@@ -0,0 +1,97 @@
1
+ // Pop-title: two lines, per-glyph fade and scale, driven by variables.
2
+ // HyperFrames seeks this paused timeline. Do not call video.play or use randomness.
3
+ (function () {
4
+ var root = document.getElementById("root");
5
+ var compositionId = root.getAttribute("data-composition-id");
6
+ var fps = Number(root.getAttribute("data-fps"));
7
+ var filmSeconds = Number(root.getAttribute("data-duration"));
8
+ var frameWidth = Number(root.getAttribute("data-width"));
9
+
10
+ if (!window.__hyperframes || typeof window.__hyperframes.getVariables !== "function") {
11
+ throw new Error("window.__hyperframes.getVariables is not available");
12
+ }
13
+
14
+ var vars = window.__hyperframes.getVariables();
15
+ var line1 = String(vars.line1 == null ? "" : vars.line1);
16
+ var line2 = String(vars.line2 == null ? "" : vars.line2);
17
+ var startFrame = Number(vars.startFrame);
18
+ var endFrame = Number(vars.endFrame);
19
+ var x = Number(vars.x);
20
+ var y = Number(vars.y);
21
+
22
+ if (!Number.isFinite(fps) || fps <= 0) {
23
+ throw new Error("data-fps must be a positive number");
24
+ }
25
+ if (!Number.isFinite(filmSeconds) || filmSeconds <= 0) {
26
+ throw new Error("data-duration must be a positive number");
27
+ }
28
+ if (!Number.isFinite(startFrame) || !Number.isFinite(endFrame) || endFrame <= startFrame) {
29
+ throw new Error("endFrame must be greater than startFrame");
30
+ }
31
+
32
+ var block = document.getElementById("title-block");
33
+ block.style.left = (x * 100) + "%";
34
+ block.style.top = (y * 100) + "%";
35
+ // Glyph size tracks frame width so 480x854 and 1080x1920 share one layout.
36
+ block.style.fontSize = Math.round(frameWidth * 0.092) + "px";
37
+
38
+ function fillLine(id, text) {
39
+ var line = document.getElementById(id);
40
+ var glyphs = Array.from(text);
41
+ line.textContent = "";
42
+ glyphs.forEach(function (ch) {
43
+ var span = document.createElement("span");
44
+ span.className = "glyph";
45
+ span.textContent = ch;
46
+ line.appendChild(span);
47
+ });
48
+ return line.querySelectorAll(".glyph");
49
+ }
50
+
51
+ var glyphs = Array.prototype.slice.call(fillLine("line1", line1))
52
+ .concat(Array.prototype.slice.call(fillLine("line2", line2)));
53
+
54
+ // Entrance is about 0.9s at 30fps. Exit is shorter. Both shrink to fit the window.
55
+ var spanFrames = endFrame - startFrame;
56
+ var entranceFrames = Math.min(27, Math.max(1, Math.floor(spanFrames * 0.45)));
57
+ var exitFrames = Math.min(8, Math.max(1, Math.floor(spanFrames * 0.2)));
58
+ if (entranceFrames + exitFrames > spanFrames) {
59
+ entranceFrames = Math.max(1, spanFrames - 1);
60
+ exitFrames = spanFrames - entranceFrames;
61
+ }
62
+
63
+ var startSec = startFrame / fps;
64
+ var endSec = endFrame / fps;
65
+ var entranceSec = entranceFrames / fps;
66
+ var exitSec = exitFrames / fps;
67
+ var count = glyphs.length;
68
+ var stagger = count <= 1 ? 0 : (entranceSec * 0.75) / (count - 1);
69
+ var eachDur = Math.max(1 / fps, entranceSec - stagger * Math.max(0, count - 1));
70
+
71
+ var timeline = gsap.timeline({ paused: true });
72
+ glyphs.forEach(function (glyph, index) {
73
+ timeline.fromTo(
74
+ glyph,
75
+ { opacity: 0, scale: 0.35 },
76
+ {
77
+ opacity: 1,
78
+ scale: 1,
79
+ duration: eachDur,
80
+ ease: "power3.out",
81
+ immediateRender: false
82
+ },
83
+ startSec + index * stagger
84
+ );
85
+ timeline.to(
86
+ glyph,
87
+ { opacity: 0, scale: 0.85, duration: exitSec, ease: "power2.in" },
88
+ endSec - exitSec
89
+ );
90
+ });
91
+
92
+ // Root duration is authored in HTML. Hold the timeline through the last frame.
93
+ timeline.set({}, {}, filmSeconds);
94
+
95
+ window.__timelines = window.__timelines || {};
96
+ window.__timelines[compositionId] = timeline;
97
+ })();
@@ -0,0 +1,42 @@
1
+ // All text and frame ranges are authored by the task composition, not sample defaults.
2
+ (function () {
3
+ var root = document.getElementById('root');
4
+ var config = JSON.parse(document.getElementById('task').textContent);
5
+ var timeline = gsap.timeline({ paused: true });
6
+ config.layers.forEach(function (layer, index) {
7
+ var block = document.createElement('div');
8
+ block.className = 'title';
9
+ block.id = 'title-' + index;
10
+ block.style.left = (layer.x * 100) + '%';
11
+ block.style.top = (layer.y * 100) + '%';
12
+ block.style.color = layer.color;
13
+ root.appendChild(block);
14
+ var glyphs = [];
15
+ layer.lines.forEach(function (text) {
16
+ var line = document.createElement('div');
17
+ block.appendChild(line);
18
+ Array.from(text).forEach(function (ch) {
19
+ var glyph = document.createElement('span');
20
+ glyph.className = 'glyph';
21
+ glyph.textContent = ch;
22
+ line.appendChild(glyph);
23
+ glyphs.push(glyph);
24
+ });
25
+ });
26
+ var start = layer.start_frame / config.fps;
27
+ var end = layer.end_frame / config.fps;
28
+ var entrance = Math.min(0.9, (end - start) * 0.45);
29
+ var exit = Math.min(0.27, (end - start) * 0.2);
30
+ glyphs.forEach(function (glyph, i) {
31
+ timeline.fromTo(glyph, { opacity: 0, scale: 0.35 }, {
32
+ opacity: 1, scale: 1, duration: entrance * 0.25,
33
+ ease: 'power3.out', immediateRender: false
34
+ }, start + (glyphs.length > 1 ? i / (glyphs.length - 1) * entrance * 0.75 : 0));
35
+ timeline.to(glyph, { opacity: 0, scale: 0.85, duration: exit, ease: 'power2.in' }, end - exit);
36
+ timeline.set(glyph, { opacity: 0 }, end);
37
+ });
38
+ });
39
+ timeline.set({}, {}, config.duration);
40
+ window.__timelines = window.__timelines || {};
41
+ window.__timelines['pop-title'] = timeline;
42
+ })();