@celljs/ta-motion 0.0.0-stage → 4.41.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/README.en.md +11 -0
- package/README.md +10 -2
- package/extension/index.mjs +105 -0
- package/package.json +59 -4
- package/web/index.js +2233 -0
package/README.en.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Cell - Ta Motion
|
|
2
|
+
|
|
3
|
+
A pi package that comes with Ta (on by default; turn it off in Settings → Extensions of the web client): Animations. An idea, a report or numbers become a short animation played in the reply: its words, numbers and timing changed in place, exported as an MP4 video. Drawn in code; no model of video, no footage or people.
|
|
4
|
+
|
|
5
|
+
- **How it is written**: under the Ta service every turn's system prompt has a `<ta-motion>` section: to put content in motion the model writes a `ta-motion` block (JSON): the frame (16:9, 9:16, 1:1), a theme, an accent, scenes (a length, a transition fade/slide/zoom/cut, a subtitle) and their parts: words, a number that counts up, bars that grow one by one, a line drawn from left to right, a pie that sweeps, a list line by line, shapes and arrows, pictures of the computer; each part with where it is (in percent of the frame), how it comes in, a delay and an emphasis.
|
|
6
|
+
- **Playing**: drawn on a canvas, what is on the frame a function of the time alone: it plays once as the card comes into view (stays at its end when the system asks for less motion), a tap pauses and goes on, the bar under it is dragged through, the scenes marked on it.
|
|
7
|
+
- **Changing it**: ask Ta in the conversation ("slow the second scene down", "make Q3 18%"), the next version of the same work; once kept, Edit on its work's page changes the length and subtitle of each scene, its words, numbers, chart values and list lines without a model, the changes of half a minute one version (TaWorkEdit). Pointed at, a part is `scenes[i].items[j]`.
|
|
8
|
+
- **Export**: Export as MP4 video under the block: drawn frame by frame in the page, encoded as H.264 with WebCodecs and written as MP4 by a muxer of its own (`web-src/mp4-mux.ts`, no dependency), much faster than it plays (about 2 seconds for 15); a page without that encoder records it as it plays with MediaRecorder (perhaps WebM); with neither it says to export it in Ta on the computer. The phone app saves it to the album, elsewhere it downloads.
|
|
9
|
+
- **Sharing**: it declares `pi.shared`, so the share page of a browser plays it too.
|
|
10
|
+
|
|
11
|
+
The format is in `web-src/motion-spec.ts`, the prompt in `web-src/motion-prompt.ts`, the design in `docs/design/ta-data-motion.md`.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cell - Ta Motion
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展 关闭):动画讲解。把想法、报告或数据做成回复里直接播放的短动画:文字、数字、时长点着就能改,可导出 MP4 视频。全由代码绘制,不用视频生成模型,不生成画面和人物。
|
|
4
|
+
|
|
5
|
+
- **写法**:在 Ta 服务下,每一轮的系统提示里多一段 `<ta-motion>`:要让内容动起来时写一个 `ta-motion` 代码块(JSON):画幅(16:9、9:16、1:1)、主题、主色,若干场景(时长、转场 fade/slide/zoom/cut、字幕),场景里的元素:文字、计数的数字、逐根长出的柱状图、从左往右画出的折线、扫开的饼图、逐条出现的列表、形状与箭头、本机图片;每个元素有位置(画面百分比)、入场方式、延迟、强调。
|
|
6
|
+
- **播放**:画在画布上,画面只取决于时间:卡片进入视野时自动播放一次(系统设了减少动态时直接停在结尾),点画面暂停/继续,可拖动进度条,场景之间有刻度。
|
|
7
|
+
- **改**:在对话里让 Ta 改("第二个场景慢一点"、"Q3 改成 18%"),出同一件作品的下一版;存成作品后,作品页「修改」可直接改每个场景的时长、字幕、文字、数字、图表数值和列表,不经模型,30 秒内的修改合成一版(TaWorkEdit)。圈一块让 Ta 改时按 `scenes[i].items[j]` 报位置。
|
|
8
|
+
- **导出**:块下「导出为 MP4 视频」:在页面里逐帧绘制、用 WebCodecs 编成 H.264,自写的 MP4 封装(`web-src/mp4-mux.ts`,无依赖),比实时播放快得多(15 秒的动画约 2 秒);页面没有编码器时用 MediaRecorder 边放边录(可能是 WebM);都没有时提示到电脑上的 Ta 导出。手机 App 存进相册,其他环境下载。
|
|
9
|
+
- **分享**:声明了 `pi.shared`,浏览器分享页也能播放。
|
|
10
|
+
|
|
11
|
+
格式见 `web-src/motion-spec.ts`,提示词见 `web-src/motion-prompt.ts`,设计见 `docs/design/ta-data-motion.md`。
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// ../ta-protocol/esm/common/host-cloud-protocol.js
|
|
2
|
+
var TA_CLOUD_OUTPUT_BYTES = 1024 * 1024;
|
|
3
|
+
|
|
4
|
+
// ../ta-protocol/esm/common/ta-extension-host.js
|
|
5
|
+
var TA_HOST_EVENT = "ta:host";
|
|
6
|
+
var TaHostUtil;
|
|
7
|
+
(function(TaHostUtil2) {
|
|
8
|
+
TaHostUtil2.WAIT_MS = 1000;
|
|
9
|
+
function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
let heard = false;
|
|
12
|
+
let answered = false;
|
|
13
|
+
const timer = setTimeout(() => resolve(undefined), waitMs);
|
|
14
|
+
const request = {
|
|
15
|
+
name,
|
|
16
|
+
heard: () => {
|
|
17
|
+
heard = true;
|
|
18
|
+
},
|
|
19
|
+
resolve: (answer) => {
|
|
20
|
+
answered = true;
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
resolve(answer);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
events.emit(TA_HOST_EVENT, request);
|
|
26
|
+
if (!heard && !answered) {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
resolve(undefined);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
TaHostUtil2.reach = reach;
|
|
33
|
+
function marked(systemPrompt, mark) {
|
|
34
|
+
return role(systemPrompt).includes(mark);
|
|
35
|
+
}
|
|
36
|
+
TaHostUtil2.marked = marked;
|
|
37
|
+
function role(systemPrompt) {
|
|
38
|
+
if (!systemPrompt) {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
const open = `<addendum>
|
|
42
|
+
`;
|
|
43
|
+
const start = systemPrompt.indexOf(open);
|
|
44
|
+
const context = systemPrompt.indexOf(`<project_context>
|
|
45
|
+
`);
|
|
46
|
+
if (start < 0 || context >= 0 && context < start) {
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
const end = systemPrompt.indexOf(`
|
|
50
|
+
</addendum>`, start);
|
|
51
|
+
return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
|
|
52
|
+
}
|
|
53
|
+
TaHostUtil2.role = role;
|
|
54
|
+
})(TaHostUtil || (TaHostUtil = {}));
|
|
55
|
+
var TA_DOUBLE_LOOK = {
|
|
56
|
+
name: "@celljs/ta-web",
|
|
57
|
+
key: "assistant.species",
|
|
58
|
+
given: ["trex", "triceratops", "stegosaurus", "brachiosaurus", "velociraptor", "ankylosaurus", "pteranodon", "parasaurolophus"]
|
|
59
|
+
};
|
|
60
|
+
var TaDoubleLookUtil;
|
|
61
|
+
(function(TaDoubleLookUtil2) {
|
|
62
|
+
function given(id) {
|
|
63
|
+
let hash = 2166136261;
|
|
64
|
+
for (let i = 0;i < id.length; i++) {
|
|
65
|
+
hash = Math.imul(hash ^ id.charCodeAt(i), 16777619);
|
|
66
|
+
}
|
|
67
|
+
return TA_DOUBLE_LOOK.given[(hash >>> 0) % TA_DOUBLE_LOOK.given.length];
|
|
68
|
+
}
|
|
69
|
+
TaDoubleLookUtil2.given = given;
|
|
70
|
+
})(TaDoubleLookUtil || (TaDoubleLookUtil = {}));
|
|
71
|
+
|
|
72
|
+
// web-src/motion-protocol.ts
|
|
73
|
+
var NAME = "@celljs/ta-motion";
|
|
74
|
+
var LANGUAGE = "ta-motion";
|
|
75
|
+
|
|
76
|
+
// web-src/motion-prompt.ts
|
|
77
|
+
var MOTION_PROMPT = `To show an idea, a result or numbers in motion (an animated explainer, a chart that grows, steps of a walkthrough, a short video of the user's own content for a talk or a post), write a fenced block of language ${LANGUAGE} holding JSON; Ta plays it in the reply like a short video, drawn from the JSON (no footage, no people), and the user changes its words, numbers and timing and exports it as MP4:
|
|
78
|
+
{"title": string, "size"?: "16:9" | "9:16" | "1:1", "theme"?: "dark" | "light", "accent"?: "#5b8cff", "background"?: a colour or [from, to], "scenes": [{"duration"?: seconds, "transition"?: "fade" | "slide" | "zoom" | "cut", "caption"?: a subtitle, "background"?, "items": [...]}]}
|
|
79
|
+
Every item has "at": [x, y] (its middle, in percent of the frame; [50, 50] when left out) and "w" (its width in percent), and may have "enter": "fade" | "rise" | "drop" | "left" | "right" | "pop" | "zoom" | "type" | "none", "delay" (seconds into the scene), "dur", "color", "emphasis": "pulse" | "float", "align":
|
|
80
|
+
- {"type": "text", "text": "…", "size": "hero" | "title" | "subtitle" | "body" | "caption"}
|
|
81
|
+
- {"type": "number", "value": 18, "from"?: 0, "prefix"?: "$", "suffix"?: "%", "label"?: "…"}: counts up
|
|
82
|
+
- {"type": "bars", "items": [{"label": "Q1", "value": 12}], "unit"?: "M", "horizontal"?: true}: grows bar by bar
|
|
83
|
+
- {"type": "line", "series": [{"label"?: "…", "values": [3, 5, 4, 8]}], "labels": ["Jan", "Feb", "Mar", "Apr"]}: draws from left to right
|
|
84
|
+
- {"type": "pie", "items": [{"label": "…", "value": 40}]}
|
|
85
|
+
- {"type": "list", "items": ["…"], "marker"?: "dot" | "number" | "check"}: line by line
|
|
86
|
+
- {"type": "shape", "shape": "rect" | "circle" | "line" | "arrow", "to"?: [x, y] (where a line ends), "fill"?, "stroke"?, "h"?}
|
|
87
|
+
- {"type": "image", "src": "<a file of the computer>", "h"?, "fit"?: "cover"}
|
|
88
|
+
One idea a scene, 3 to 8 scenes, 15 to 45 seconds in all unless asked; keep items apart (a title near y 18, a chart near y 58 with w 70); the words and numbers come from the user's content, never made up. To change it, write the whole block again.`;
|
|
89
|
+
|
|
90
|
+
// web-src/extension.ts
|
|
91
|
+
function activate(pi) {
|
|
92
|
+
let served;
|
|
93
|
+
const underServe = () => served ??= TaHostUtil.reach(pi.events, NAME).then((answer) => answer !== undefined);
|
|
94
|
+
pi.on("session_start", () => {
|
|
95
|
+
underServe();
|
|
96
|
+
});
|
|
97
|
+
pi.on("before_agent_start", async (event) => {
|
|
98
|
+
if (await underServe()) {
|
|
99
|
+
event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [LANGUAGE]: MOTION_PROMPT };
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
activate as default
|
|
105
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-motion",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.41.0",
|
|
4
|
+
"description": "A pi package for Ta: ideas and numbers of replies played as short animations, changed by hand and exported as MP4",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/cellbang/ta",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/cellbang/ta/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"web",
|
|
19
|
+
"extension",
|
|
20
|
+
"!**/*.map"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -b && bun build web-src/index.tsx --format esm --target browser --outfile web/index.js && bun build web-src/extension.ts --format esm --target node --outfile extension/index.mjs",
|
|
24
|
+
"clean": "rm -rf lib web extension *.tsbuildinfo",
|
|
25
|
+
"test": "bun test ./lib",
|
|
26
|
+
"watch": "tsc -b -w --preserveWatchOutput"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@celljs/ta-protocol": "4.41.0",
|
|
30
|
+
"@celljs/ta-web": "4.41.0",
|
|
31
|
+
"@types/react": "^19.3.3"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"pi": {
|
|
37
|
+
"title": {
|
|
38
|
+
"en": "Animations",
|
|
39
|
+
"zh-CN": "动画讲解",
|
|
40
|
+
"zh-TW": "動畫講解",
|
|
41
|
+
"ja-JP": "アニメーション解説"
|
|
42
|
+
},
|
|
43
|
+
"summary": {
|
|
44
|
+
"en": "Turns an idea, a report or numbers into a short animation played in the reply: words, numbers and timing changed by hand, exported as an MP4 video. Drawn in code, no footage or people.",
|
|
45
|
+
"zh-CN": "把想法、报告或数据做成回复里直接播放的短动画:文字、数字和时长点着就能改,可导出成 MP4 视频。全由代码绘制,不生成画面和人物。",
|
|
46
|
+
"zh-TW": "把想法、報告或資料做成回覆裡直接播放的短動畫:文字、數字和時長點著就能改,可匯出成 MP4 影片。全由程式繪製,不生成畫面和人物。",
|
|
47
|
+
"ja-JP": "アイデアやレポート、数値を返信の中で再生できる短いアニメーションに。文字・数値・長さはその場で直せ、MP4 動画として書き出せます。すべてコードで描画し、映像や人物は生成しません。"
|
|
48
|
+
},
|
|
49
|
+
"icon": "Film",
|
|
50
|
+
"web": [
|
|
51
|
+
"./web/index.js"
|
|
52
|
+
],
|
|
53
|
+
"shared": true,
|
|
54
|
+
"extensions": [
|
|
55
|
+
"./extension/index.mjs"
|
|
56
|
+
],
|
|
57
|
+
"sections": [
|
|
58
|
+
"ta-motion"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
}
|