@celljs/ta-motion 4.41.0 → 4.43.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 CHANGED
@@ -3,7 +3,8 @@
3
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
4
 
5
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.
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. The frame keeps its shape: as wide as the card, at most 70% of the window high (a tall one does not run long); a number wider than its box is drawn smaller, those of a size in a scene together, so a row of them never overlaps.
7
+ - **Full screen**: the button right of the bar, or a double click on the frame. It fills the screen with its shape kept (bands at the sides or above and below), the title and controls over it, fading after 2.5 s still while it plays; Esc leaves, Space plays and pauses, the arrows move 5 s. Where the browser has full screen (a computer, Android) it goes into it too, and Android turns to the shape of the frame; on an iPhone and in WeChat it fills Ta's page. The canvas is 4K pixels on its longer side at most.
7
8
  - **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
9
  - **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
10
  - **Sharing**: it declares `pi.shared`, so the share page of a browser plays it too.
package/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展 关闭):动画讲解。把想法、报告或数据做成回复里直接播放的短动画:文字、数字、时长点着就能改,可导出 MP4 视频。全由代码绘制,不用视频生成模型,不生成画面和人物。
4
4
 
5
5
  - **写法**:在 Ta 服务下,每一轮的系统提示里多一段 `<ta-motion>`:要让内容动起来时写一个 `ta-motion` 代码块(JSON):画幅(16:9、9:16、1:1)、主题、主色,若干场景(时长、转场 fade/slide/zoom/cut、字幕),场景里的元素:文字、计数的数字、逐根长出的柱状图、从左往右画出的折线、扫开的饼图、逐条出现的列表、形状与箭头、本机图片;每个元素有位置(画面百分比)、入场方式、延迟、强调。
6
- - **播放**:画在画布上,画面只取决于时间:卡片进入视野时自动播放一次(系统设了减少动态时直接停在结尾),点画面暂停/继续,可拖动进度条,场景之间有刻度。
6
+ - **播放**:画在画布上,画面只取决于时间:卡片进入视野时自动播放一次(系统设了减少动态时直接停在结尾),点画面暂停/继续,可拖动进度条,场景之间有刻度。画面保持比例:回复里最宽占满卡片、最高不超过窗口的 70%(竖屏动画不会撑得很长);数字超出自己的宽度时缩小,同一场景同字号的数字一起缩,排成一行不会叠在一起。
7
+ - **全屏**:进度条右边的按钮或双击画面。铺满屏幕、比例不变(两侧或上下留黑边),标题和控件叠在画面上、播放时 2.5 秒不动就淡出;Esc 退出,空格播放/暂停,左右键前后 5 秒。有浏览器全屏的地方(电脑、安卓)同时进浏览器全屏,安卓上按画面方向转屏;iPhone 和微信里铺满 Ta 的页面。画布最长边不超过 4K 像素。
7
8
  - **改**:在对话里让 Ta 改("第二个场景慢一点"、"Q3 改成 18%"),出同一件作品的下一版;存成作品后,作品页「修改」可直接改每个场景的时长、字幕、文字、数字、图表数值和列表,不经模型,30 秒内的修改合成一版(TaWorkEdit)。圈一块让 Ta 改时按 `scenes[i].items[j]` 报位置。
8
9
  - **导出**:块下「导出为 MP4 视频」:在页面里逐帧绘制、用 WebCodecs 编成 H.264,自写的 MP4 封装(`web-src/mp4-mux.ts`,无依赖),比实时播放快得多(15 秒的动画约 2 秒);页面没有编码器时用 MediaRecorder 边放边录(可能是 WebM);都没有时提示到电脑上的 Ta 导出。手机 App 存进相册,其他环境下载。
9
10
  - **分享**:声明了 `pi.shared`,浏览器分享页也能播放。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-motion",
3
- "version": "4.41.0",
3
+ "version": "4.43.0",
4
4
  "description": "A pi package for Ta: ideas and numbers of replies played as short animations, changed by hand and exported as MP4",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -26,8 +26,8 @@
26
26
  "watch": "tsc -b -w --preserveWatchOutput"
27
27
  },
28
28
  "devDependencies": {
29
- "@celljs/ta-protocol": "4.41.0",
30
- "@celljs/ta-web": "4.41.0",
29
+ "@celljs/ta-protocol": "4.43.0",
30
+ "@celljs/ta-web": "4.43.0",
31
31
  "@types/react": "^19.3.3"
32
32
  },
33
33
  "publishConfig": {
package/web/index.js CHANGED
@@ -45,6 +45,9 @@ var EN = {
45
45
  play: "Play",
46
46
  pause: "Pause",
47
47
  replay: "Play again",
48
+ full: "Full screen",
49
+ leaveFull: "Exit full screen",
50
+ playingFull: "Playing in full screen",
48
51
  export: "Export as MP4 video",
49
52
  exporting: "Exporting the video {percent}%",
50
53
  exported: "Saved as {name}",
@@ -80,6 +83,9 @@ var ZH = {
80
83
  play: "播放",
81
84
  pause: "暂停",
82
85
  replay: "重播",
86
+ full: "全屏",
87
+ leaveFull: "退出全屏",
88
+ playingFull: "正在全屏播放",
83
89
  export: "导出为 MP4 视频",
84
90
  exporting: "正在导出视频 {percent}%",
85
91
  exported: "已存为 {name}",
@@ -115,6 +121,9 @@ var ZH_TW = {
115
121
  play: "播放",
116
122
  pause: "暫停",
117
123
  replay: "重播",
124
+ full: "全螢幕",
125
+ leaveFull: "結束全螢幕",
126
+ playingFull: "正在全螢幕播放",
118
127
  export: "匯出為 MP4 影片",
119
128
  exporting: "正在匯出影片 {percent}%",
120
129
  exported: "已存為 {name}",
@@ -150,6 +159,9 @@ var JA = {
150
159
  play: "再生",
151
160
  pause: "一時停止",
152
161
  replay: "もう一度再生",
162
+ full: "全画面",
163
+ leaveFull: "全画面を終了",
164
+ playingFull: "全画面で再生中",
153
165
  export: "MP4 動画として書き出す",
154
166
  exporting: "動画を書き出し中 {percent}%",
155
167
  exported: "{name} として保存しました",
@@ -316,6 +328,30 @@ class MotionCanvas {
316
328
 
317
329
  // web-src/motion-parts.ts
318
330
  class MotionParts extends MotionCanvas {
331
+ shrink = new Map;
332
+ fitNumbers(items) {
333
+ const ctx = this.context;
334
+ const least = new Map;
335
+ this.shrink.clear();
336
+ for (const part of items) {
337
+ if (part.type !== "number") {
338
+ continue;
339
+ }
340
+ ctx.font = this.font(part.size, true).font;
341
+ const widest = Math.max(ctx.measureText(this.figure(part, part.value)).width, ctx.measureText(this.figure(part, part.from)).width);
342
+ const room = part.w / 100 * this.width * 0.96;
343
+ const share = widest > room ? room / widest : 1;
344
+ least.set(part.size, Math.min(least.get(part.size) ?? 1, share));
345
+ }
346
+ for (const part of items) {
347
+ if (part.type === "number") {
348
+ this.shrink.set(part, least.get(part.size) ?? 1);
349
+ }
350
+ }
351
+ }
352
+ figure(part, value) {
353
+ return `${part.prefix}${MotionLayout.format(value, part.decimals)}${part.suffix}`;
354
+ }
319
355
  text(part, w, shown) {
320
356
  const ctx = this.context;
321
357
  const { px, font } = this.font(part.size, part.bold);
@@ -341,15 +377,20 @@ class MotionParts extends MotionCanvas {
341
377
  number(part, w, h, grow) {
342
378
  const ctx = this.context;
343
379
  const value = part.from + (part.value - part.from) * MotionEase.outQuart(grow);
344
- const { px, font } = this.font(part.size, true);
345
- const label = part.label ? this.font("body", false) : undefined;
380
+ const { px, font } = this.font(part.size, true, this.shrink.get(part) ?? 1);
381
+ let label = part.label ? this.font("body", false) : undefined;
382
+ if (label && part.label) {
383
+ ctx.font = label.font;
384
+ const wide = ctx.measureText(part.label).width;
385
+ label = wide > w ? this.font("body", false, w / wide) : label;
386
+ }
346
387
  const top = -h / 2;
347
388
  ctx.textBaseline = "middle";
348
389
  ctx.textAlign = part.align;
349
390
  const x = part.align === "left" ? -w / 2 : part.align === "right" ? w / 2 : 0;
350
391
  ctx.font = font;
351
392
  ctx.fillStyle = part.color ?? this.motion.accent;
352
- ctx.fillText(`${part.prefix}${MotionLayout.format(value, part.decimals)}${part.suffix}`, x, top + px * 0.55);
393
+ ctx.fillText(this.figure(part, value), x, top + px * 0.55);
353
394
  if (label && part.label) {
354
395
  ctx.font = label.font;
355
396
  ctx.fillStyle = this.palette.muted;
@@ -1046,6 +1087,7 @@ class MotionPainter extends MotionParts {
1046
1087
  }
1047
1088
  scene(index, local, t) {
1048
1089
  const scene2 = this.motion.scenes[index];
1090
+ this.fitNumbers(scene2.items);
1049
1091
  this.background(scene2, t);
1050
1092
  const hits = [];
1051
1093
  scene2.items.forEach((part, item2) => {
@@ -1178,7 +1220,7 @@ class MotionPainter extends MotionParts {
1178
1220
  return this.wrap(part.text, w).length * px * 1.22;
1179
1221
  }
1180
1222
  case "number": {
1181
- const { px } = this.font(part.size, true);
1223
+ const { px } = this.font(part.size, true, this.shrink.get(part) ?? 1);
1182
1224
  return px * 1.1 + (part.label ? this.font("body", false).px * 1.6 : 0);
1183
1225
  }
1184
1226
  case "list": {
@@ -1523,6 +1565,99 @@ var MotionFiles;
1523
1565
  // web-src/motion-protocol.ts
1524
1566
  var LANGUAGE = "ta-motion";
1525
1567
 
1568
+ // ../ta-protocol/esm/common/work-title.js
1569
+ var TA_WORK_BLOCKS = {
1570
+ "ta-play": "Gamepad2",
1571
+ "ta-plot": "ChartSpline",
1572
+ "ta-3d": "Box",
1573
+ "ta-glance": "LayoutDashboard",
1574
+ "ta-doc": "FileText",
1575
+ "ta-slides": "Presentation",
1576
+ "ta-sheet": "Sheet",
1577
+ "ta-dash": "Gauge",
1578
+ "ta-motion": "Film"
1579
+ };
1580
+ var TaWorkTitle;
1581
+ (function(TaWorkTitle2) {
1582
+ function is(language) {
1583
+ return Object.keys(TA_WORK_BLOCKS).includes(language);
1584
+ }
1585
+ TaWorkTitle2.is = is;
1586
+ const MARKDOWN = ["ta-doc", "ta-slides"];
1587
+ function of(language, code) {
1588
+ var _a, _b;
1589
+ if (MARKDOWN.includes(language)) {
1590
+ const heading = (_a = /^ {0,3}#{1,6}\s+(.+?)\s*#*\s*$/m.exec(code.replace(/^ {0,3}(`{3,}|~{3,})[\s\S]*?^ {0,3}\1/gm, ""))) === null || _a === undefined ? undefined : _a[1];
1591
+ return clean(heading === null || heading === undefined ? undefined : heading.replace(/[*_`]+/g, ""));
1592
+ }
1593
+ if (language === "ta-play") {
1594
+ const title = (_b = /<title[^>]*>([^<]*)<\/title>/i.exec(code)) === null || _b === undefined ? undefined : _b[1];
1595
+ return clean(title === null || title === undefined ? undefined : title.replace(/&(amp|lt|gt|quot|#39);/g, (_, name) => {
1596
+ var _a2;
1597
+ return (_a2 = { amp: "&", lt: "<", gt: ">", quot: '"', "#39": "'" }[name]) !== null && _a2 !== undefined ? _a2 : "";
1598
+ }));
1599
+ }
1600
+ try {
1601
+ const value = JSON.parse(code);
1602
+ if (typeof (value === null || value === undefined ? undefined : value.title) === "string") {
1603
+ return clean(value.title);
1604
+ }
1605
+ const first = Array.isArray(value === null || value === undefined ? undefined : value.blocks) ? value.blocks.find((block) => typeof (block === null || block === undefined ? undefined : block.title) === "string" || typeof (block === null || block === undefined ? undefined : block.question) === "string") : undefined;
1606
+ return clean(typeof (first === null || first === undefined ? undefined : first.title) === "string" ? first.title : typeof (first === null || first === undefined ? undefined : first.question) === "string" ? first.question : undefined);
1607
+ } catch (_c) {
1608
+ return;
1609
+ }
1610
+ }
1611
+ TaWorkTitle2.of = of;
1612
+ function repeats(own, titled) {
1613
+ const plain = (text2) => {
1614
+ var _a;
1615
+ return (_a = clean(text2 === null || text2 === undefined ? undefined : text2.replace(/[*_`]+/g, ""))) === null || _a === undefined ? undefined : _a.toLowerCase();
1616
+ };
1617
+ const shown = plain(titled);
1618
+ return shown !== undefined && plain(own) === shown;
1619
+ }
1620
+ TaWorkTitle2.repeats = repeats;
1621
+ function clean(text2) {
1622
+ const line = text2 === null || text2 === undefined ? undefined : text2.trim().replace(/\s+/g, " ");
1623
+ return line ? line.slice(0, 60) : undefined;
1624
+ }
1625
+ })(TaWorkTitle || (TaWorkTitle = {}));
1626
+ var TaWorkBlock;
1627
+ (function(TaWorkBlock2) {
1628
+ function fenced(language, code) {
1629
+ const longest = Math.max(2, ...[...code.matchAll(/`+/g)].map((run) => run[0].length));
1630
+ const fence = "`".repeat(longest + 1);
1631
+ return `${fence}${language}
1632
+ ${code}
1633
+ ${fence}`;
1634
+ }
1635
+ TaWorkBlock2.fenced = fenced;
1636
+ })(TaWorkBlock || (TaWorkBlock = {}));
1637
+ var TaWorkFile;
1638
+ (function(TaWorkFile2) {
1639
+ const TYPE = /^text\/vnd\.([a-z0-9-]+)\+markdown$/;
1640
+ function type(language2) {
1641
+ return `text/vnd.${language2}+markdown`;
1642
+ }
1643
+ TaWorkFile2.type = type;
1644
+ function language(type2) {
1645
+ var _a;
1646
+ const found = (_a = TYPE.exec(type2)) === null || _a === undefined ? undefined : _a[1];
1647
+ return found && TaWorkTitle.is(found) ? found : undefined;
1648
+ }
1649
+ TaWorkFile2.language = language;
1650
+ function name(title2) {
1651
+ const clean = Array.from(title2, (char) => char < " " || '\\/:*?"<>|'.includes(char) ? " " : char).join("").replace(/\s+/g, " ").trim().slice(0, 60);
1652
+ return `${clean || "work"}.md`;
1653
+ }
1654
+ TaWorkFile2.name = name;
1655
+ function title(name2) {
1656
+ return name2.replace(/\.md$/i, "");
1657
+ }
1658
+ TaWorkFile2.title = title;
1659
+ })(TaWorkFile || (TaWorkFile = {}));
1660
+
1526
1661
  // ../ta-protocol/esm/common/work-ai-protocol.js
1527
1662
  var TA_WORKS = "@celljs/ta-works";
1528
1663
  var TaWorkAi;
@@ -1598,6 +1733,23 @@ var TaWorkMark;
1598
1733
  return TaWorkMark2.COMMENTED.includes(language) ? `<!-- ta-work: ${work} -->` : `"work": "${work}"`;
1599
1734
  }
1600
1735
  TaWorkMark2.mark = mark;
1736
+ function unnamed(language, code) {
1737
+ if (!of(language, code)) {
1738
+ return code;
1739
+ }
1740
+ if (TaWorkMark2.COMMENTED.includes(language)) {
1741
+ return code.replace(TaWorkMark2.COMMENT, "").replace(/^\s*\n/, "");
1742
+ }
1743
+ const stripped = code.replace(/"work"\s*:\s*"work-[a-z0-9]{1,32}"\s*,\s*/, "");
1744
+ try {
1745
+ if (!of(language, stripped) && JSON.parse(stripped)) {
1746
+ return stripped;
1747
+ }
1748
+ } catch (_a) {}
1749
+ const value = JSON.parse(code);
1750
+ return JSON.stringify(Object.fromEntries(Object.entries(value).filter(([key]) => key !== "work")), null, 2);
1751
+ }
1752
+ TaWorkMark2.unnamed = unnamed;
1601
1753
  })(TaWorkMark || (TaWorkMark = {}));
1602
1754
 
1603
1755
  // web-src/react.ts
@@ -1686,15 +1838,19 @@ function MotionEditor({
1686
1838
  const shown = motion.scenes[scene2];
1687
1839
  const s = shown.index;
1688
1840
  const field = (key, label, value, set, long = false) => /* @__PURE__ */ React.createElement("div", {
1689
- className: "tmt-field",
1841
+ className: "ta-form-item",
1690
1842
  key
1691
- }, /* @__PURE__ */ React.createElement("span", null, label), long ? /* @__PURE__ */ React.createElement("textarea", {
1843
+ }, /* @__PURE__ */ React.createElement("span", {
1844
+ className: "ta-form-label"
1845
+ }, label), long ? /* @__PURE__ */ React.createElement("textarea", {
1846
+ className: "ta-input",
1692
1847
  rows: 2,
1693
1848
  "aria-label": label,
1694
1849
  defaultValue: value,
1695
1850
  onChange: (event) => set(event.currentTarget.value),
1696
1851
  onBlur: commit
1697
1852
  }) : /* @__PURE__ */ React.createElement("input", {
1853
+ className: "ta-input",
1698
1854
  type: "text",
1699
1855
  "aria-label": label,
1700
1856
  defaultValue: value,
@@ -1818,8 +1974,38 @@ function MotionEditor({
1818
1974
  }))), shown.items.map(part)));
1819
1975
  }
1820
1976
 
1977
+ // web-src/motion-fit.ts
1978
+ var MotionFit;
1979
+ ((MotionFit) => {
1980
+ MotionFit.MAX_PIXELS = 3840;
1981
+ MotionFit.CARD_HEIGHT = 0.7;
1982
+ function contain(width, height, ratio) {
1983
+ if (!(width > 0) || !(height > 0) || !(ratio > 0)) {
1984
+ return { width: 0, height: 0 };
1985
+ }
1986
+ return width / height > ratio ? { width: Math.floor(height * ratio), height: Math.floor(height) } : { width: Math.floor(width), height: Math.floor(width / ratio) };
1987
+ }
1988
+ MotionFit.contain = contain;
1989
+ function scale(width, height, device) {
1990
+ const wanted = device > 0 ? device : 1;
1991
+ const longer = Math.max(width, height);
1992
+ return longer > 0 ? Math.min(wanted, MotionFit.MAX_PIXELS / longer) : wanted;
1993
+ }
1994
+ MotionFit.scale = scale;
1995
+ function cardWidth(ratio) {
1996
+ return `min(100%, calc(${MotionFit.CARD_HEIGHT * 100}vh * ${ratio}))`;
1997
+ }
1998
+ MotionFit.cardWidth = cardWidth;
1999
+ function orientation(ratio) {
2000
+ return ratio > 1.05 ? "landscape" : ratio < 0.95 ? "portrait" : undefined;
2001
+ }
2002
+ MotionFit.orientation = orientation;
2003
+ })(MotionFit ||= {});
2004
+
1821
2005
  // web-src/motion-view.tsx
1822
2006
  var TAP = 6;
2007
+ var IDLE = 2500;
2008
+ var STEP = 5;
1823
2009
  function clock(seconds) {
1824
2010
  const whole = Math.max(0, Math.round(seconds));
1825
2011
  return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`;
@@ -1847,7 +2033,14 @@ function Glyph({ kind }) {
1847
2033
  width: "4",
1848
2034
  height: "13",
1849
2035
  rx: "1"
1850
- })), kind === "replay" && /* @__PURE__ */ React.createElement("g", {
2036
+ })), (kind === "full" || kind === "leave") && /* @__PURE__ */ React.createElement("path", {
2037
+ d: kind === "full" ? "M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5" : "M9 4v5H4M20 9h-5V4M15 20v-5h5M4 15h5v5",
2038
+ fill: "none",
2039
+ stroke: "currentColor",
2040
+ strokeWidth: "2.2",
2041
+ strokeLinecap: "round",
2042
+ strokeLinejoin: "round"
2043
+ }), kind === "replay" && /* @__PURE__ */ React.createElement("g", {
1851
2044
  fill: "none",
1852
2045
  stroke: "currentColor",
1853
2046
  strokeWidth: "2.2",
@@ -1859,6 +2052,11 @@ function Glyph({ kind }) {
1859
2052
  d: "M4 4.5v4.5h4.5"
1860
2053
  })));
1861
2054
  }
2055
+ function FixedCover({ children }) {
2056
+ return /* @__PURE__ */ React.createElement("div", {
2057
+ className: "tmt-full-fixed"
2058
+ }, children);
2059
+ }
1862
2060
  function pointOf(motion, raw, hit, scene2, words) {
1863
2061
  let written;
1864
2062
  try {
@@ -1886,7 +2084,9 @@ function motionView(pi) {
1886
2084
  pictures,
1887
2085
  time,
1888
2086
  hits,
1889
- onTap
2087
+ onTap,
2088
+ onDoubleTap,
2089
+ style
1890
2090
  }) {
1891
2091
  const canvas = React.useRef(null);
1892
2092
  const from = React.useRef([0, 0]);
@@ -1903,9 +2103,9 @@ function motionView(pi) {
1903
2103
  let frame = 0;
1904
2104
  const draw = () => {
1905
2105
  frame = requestAnimationFrame(draw);
1906
- const scale = window.devicePixelRatio || 1;
1907
2106
  const w = element.clientWidth;
1908
2107
  const h = element.clientHeight;
2108
+ const scale = MotionFit.scale(w, h, window.devicePixelRatio || 1);
1909
2109
  const key = `${w}x${h}x${scale}`;
1910
2110
  if (key !== size) {
1911
2111
  size = key;
@@ -1926,7 +2126,7 @@ function motionView(pi) {
1926
2126
  return /* @__PURE__ */ React.createElement("canvas", {
1927
2127
  ref: canvas,
1928
2128
  className: "tmt-canvas",
1929
- style: { aspectRatio: `${width} / ${height}` },
2129
+ style: { aspectRatio: `${width} / ${height}`, ...style },
1930
2130
  onPointerDown: (event) => {
1931
2131
  from.current = [event.clientX, event.clientY];
1932
2132
  },
@@ -1936,7 +2136,8 @@ function motionView(pi) {
1936
2136
  }
1937
2137
  const box2 = event.currentTarget.getBoundingClientRect();
1938
2138
  onTap(event.clientX - box2.left, event.clientY - box2.top);
1939
- }
2139
+ },
2140
+ onDoubleClick: onDoubleTap
1940
2141
  });
1941
2142
  }
1942
2143
  function Player({ motion, props, edit, words }) {
@@ -1961,6 +2162,14 @@ function motionView(pi) {
1961
2162
  const [exporting, setExporting] = React.useState(() => MotionFiles.progress(props.code));
1962
2163
  const started = React.useRef(time.current > 0);
1963
2164
  const clockAt = React.useRef(undefined);
2165
+ const frame = MotionSpec.frame(motion.size);
2166
+ const ratio = frame.width / frame.height;
2167
+ const [full2, setFull] = React.useState(false);
2168
+ const fullStage = React.useRef(null);
2169
+ const [fit, setFit] = React.useState();
2170
+ const [idle, setIdle] = React.useState(false);
2171
+ const [nudged, setNudged] = React.useState(0);
2172
+ const wokeAt = React.useRef(0);
1964
2173
  React.useEffect(() => MotionFiles.watch(props.code, setExporting), [props.code]);
1965
2174
  React.useEffect(() => {
1966
2175
  let alive = true;
@@ -1985,7 +2194,7 @@ function motionView(pi) {
1985
2194
  time.current = 0;
1986
2195
  }
1987
2196
  clockAt.current = { at: performance.now(), from: time.current };
1988
- let frame = 0;
2197
+ let frame2 = 0;
1989
2198
  let told = 0;
1990
2199
  const tick = () => {
1991
2200
  const clock2 = clockAt.current;
@@ -2003,11 +2212,84 @@ function motionView(pi) {
2003
2212
  told = performance.now();
2004
2213
  setNow(time.current);
2005
2214
  }
2006
- frame = requestAnimationFrame(tick);
2215
+ frame2 = requestAnimationFrame(tick);
2007
2216
  };
2008
- frame = requestAnimationFrame(tick);
2009
- return () => cancelAnimationFrame(frame);
2217
+ frame2 = requestAnimationFrame(tick);
2218
+ return () => cancelAnimationFrame(frame2);
2010
2219
  }, [playing, total]);
2220
+ React.useEffect(() => {
2221
+ if (!full2) {
2222
+ return;
2223
+ }
2224
+ const root = document.documentElement;
2225
+ let entered = false;
2226
+ if (document.fullscreenEnabled && !document.fullscreenElement && root.requestFullscreen) {
2227
+ entered = true;
2228
+ root.requestFullscreen({ navigationUI: "hide" }).then(() => {
2229
+ const turn = MotionFit.orientation(ratio);
2230
+ const orientation = screen.orientation;
2231
+ return turn && orientation?.lock ? orientation.lock(turn) : undefined;
2232
+ }).catch(() => {
2233
+ return;
2234
+ });
2235
+ }
2236
+ const changed = () => {
2237
+ if (entered && !document.fullscreenElement) {
2238
+ setFull(false);
2239
+ }
2240
+ };
2241
+ const key = (event) => {
2242
+ if (event.key === "Escape") {
2243
+ setFull(false);
2244
+ } else if (event.key === " " && !(event.target instanceof HTMLInputElement && event.target.type !== "range")) {
2245
+ setPlaying((on) => !on);
2246
+ } else if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
2247
+ seek(time.current + (event.key === "ArrowLeft" ? -STEP : STEP));
2248
+ } else {
2249
+ return;
2250
+ }
2251
+ event.preventDefault();
2252
+ };
2253
+ document.addEventListener("fullscreenchange", changed);
2254
+ window.addEventListener("keydown", key);
2255
+ return () => {
2256
+ document.removeEventListener("fullscreenchange", changed);
2257
+ window.removeEventListener("keydown", key);
2258
+ screen.orientation?.unlock?.();
2259
+ if (entered && document.fullscreenElement) {
2260
+ document.exitFullscreen().catch(() => {
2261
+ return;
2262
+ });
2263
+ }
2264
+ };
2265
+ }, [full2, ratio, seek]);
2266
+ React.useEffect(() => {
2267
+ const element = fullStage.current;
2268
+ if (!full2 || !element) {
2269
+ setFit(undefined);
2270
+ return;
2271
+ }
2272
+ const measure = () => setFit(MotionFit.contain(element.clientWidth, element.clientHeight, ratio));
2273
+ measure();
2274
+ const observer = new ResizeObserver(measure);
2275
+ observer.observe(element);
2276
+ return () => observer.disconnect();
2277
+ }, [full2, ratio]);
2278
+ React.useEffect(() => {
2279
+ if (!full2 || !playing) {
2280
+ setIdle(false);
2281
+ return;
2282
+ }
2283
+ const timer = setTimeout(() => setIdle(true), IDLE);
2284
+ return () => clearTimeout(timer);
2285
+ }, [full2, playing, nudged]);
2286
+ const wake = () => {
2287
+ if (idle || performance.now() - wokeAt.current > 500) {
2288
+ wokeAt.current = performance.now();
2289
+ setIdle(false);
2290
+ setNudged((n) => n + 1);
2291
+ }
2292
+ };
2011
2293
  React.useEffect(() => {
2012
2294
  const element = card.current;
2013
2295
  if (!element || typeof IntersectionObserver === "undefined") {
@@ -2040,20 +2322,22 @@ function motionView(pi) {
2040
2322
  setPlaying(!playing);
2041
2323
  };
2042
2324
  const ended = !playing && now >= total - 0.01;
2043
- return /* @__PURE__ */ React.createElement("div", {
2044
- className: "tmt-card",
2045
- ref: card
2046
- }, motion.title && /* @__PURE__ */ React.createElement("div", {
2047
- className: "tmt-title"
2048
- }, motion.title), /* @__PURE__ */ React.createElement("div", {
2049
- className: "tmt-stage"
2050
- }, /* @__PURE__ */ React.createElement(Stage, {
2325
+ const toggleFull = () => {
2326
+ setFull(!full2);
2327
+ if (!full2 && !playing && !ended) {
2328
+ setPlaying(true);
2329
+ }
2330
+ };
2331
+ const stage = (style) => /* @__PURE__ */ React.createElement(Stage, {
2051
2332
  motion,
2052
2333
  pictures,
2053
2334
  time,
2054
2335
  hits,
2055
- onTap
2056
- })), /* @__PURE__ */ React.createElement("div", {
2336
+ onTap,
2337
+ onDoubleTap: props.point ? undefined : toggleFull,
2338
+ style
2339
+ });
2340
+ const controls = /* @__PURE__ */ React.createElement("div", {
2057
2341
  className: "tmt-controls"
2058
2342
  }, /* @__PURE__ */ React.createElement("button", {
2059
2343
  type: "button",
@@ -2081,12 +2365,44 @@ function motionView(pi) {
2081
2365
  style: { left: `${start / total * 100}%` }
2082
2366
  })))), /* @__PURE__ */ React.createElement("span", {
2083
2367
  className: "tmt-time"
2084
- }, exporting !== undefined ? MotionWords.fill(words.exporting, { percent: exporting }) : `${clock(now)} / ${clock(total)}`), edit.editable && /* @__PURE__ */ React.createElement("button", {
2368
+ }, exporting !== undefined ? MotionWords.fill(words.exporting, { percent: exporting }) : `${clock(now)} / ${clock(total)}`), edit.editable && !full2 && /* @__PURE__ */ React.createElement("button", {
2085
2369
  type: "button",
2086
2370
  className: "tmt-edit",
2087
2371
  "data-on": editing || undefined,
2088
2372
  onClick: () => setEditing(!editing)
2089
- }, editing ? words.done : words.edit)), edit.editable && editing && /* @__PURE__ */ React.createElement(MotionEditor, {
2373
+ }, editing ? words.done : words.edit), /* @__PURE__ */ React.createElement("button", {
2374
+ type: "button",
2375
+ className: "tmt-icon",
2376
+ "aria-label": full2 ? words.leaveFull : words.full,
2377
+ title: full2 ? words.leaveFull : words.full,
2378
+ onClick: toggleFull
2379
+ }, /* @__PURE__ */ React.createElement(Glyph, {
2380
+ kind: full2 ? "leave" : "full"
2381
+ })));
2382
+ const Cover = pi.ui.FullScreen ?? FixedCover;
2383
+ return /* @__PURE__ */ React.createElement("div", {
2384
+ className: "tmt-card",
2385
+ ref: card
2386
+ }, motion.title && !TaWorkTitle.repeats(motion.title, props.titled) && /* @__PURE__ */ React.createElement("div", {
2387
+ className: "tmt-title"
2388
+ }, motion.title), /* @__PURE__ */ React.createElement("div", {
2389
+ className: "tmt-stage",
2390
+ style: { width: MotionFit.cardWidth(ratio) }
2391
+ }, full2 ? /* @__PURE__ */ React.createElement("div", {
2392
+ className: "tmt-away",
2393
+ style: { aspectRatio: `${frame.width} / ${frame.height}` }
2394
+ }, words.playingFull) : stage()), !full2 && controls, full2 && /* @__PURE__ */ React.createElement(Cover, null, /* @__PURE__ */ React.createElement("div", {
2395
+ className: idle ? "tmt-full tmt-idle" : "tmt-full",
2396
+ onPointerMove: wake,
2397
+ onPointerDown: wake
2398
+ }, /* @__PURE__ */ React.createElement("div", {
2399
+ className: "tmt-full-stage",
2400
+ ref: fullStage
2401
+ }, fit && fit.width > 0 && stage({ width: fit.width, height: fit.height })), /* @__PURE__ */ React.createElement("div", {
2402
+ className: "tmt-full-head"
2403
+ }, /* @__PURE__ */ React.createElement("span", {
2404
+ className: "tmt-full-title"
2405
+ }, motion.title || words.untitled)), controls)), edit.editable && editing && !full2 && /* @__PURE__ */ React.createElement(MotionEditor, {
2090
2406
  motion,
2091
2407
  scene: scene2,
2092
2408
  words,
@@ -2154,8 +2470,44 @@ var STYLE = `
2154
2470
  }
2155
2471
  .ta-code-embedded > .tmt-card { margin: 0; padding: 0; max-width: none; border: 0; background: none; }
2156
2472
  .tmt-title { font-weight: 600; margin-bottom: 8px; }
2157
- .tmt-stage { border-radius: 8px; overflow: hidden; background: #0b1020; }
2473
+ /* The frame keeps its shape: as wide as the card, unless a tall one would then pass 70% of the window (MotionFit). */
2474
+ .tmt-stage { margin: 0 auto; border-radius: 8px; overflow: hidden; background: #0b1020; }
2158
2475
  .tmt-canvas { display: block; width: 100%; height: auto; cursor: pointer; touch-action: manipulation; }
2476
+ .tmt-away { display: flex; align-items: center; justify-content: center; color: rgba(255, 255, 255, 0.6); font-size: calc(12px * var(--tmt-s)); }
2477
+ .tmt-icon {
2478
+ flex: none; display: inline-flex; align-items: center; justify-content: center;
2479
+ width: 30px; height: 30px; border: 0; border-radius: 50%;
2480
+ background: transparent; color: var(--ta-muted); cursor: pointer; transition: background 0.15s, color 0.15s;
2481
+ }
2482
+ .tmt-icon:hover { background: var(--ta-hover-strong); color: var(--ta-text); }
2483
+ /* Full screen: the frame as big as the screen allows on black, the title and controls over it, fading while it plays. */
2484
+ .tmt-full { position: relative; flex: 1; min-height: 0; background: #000; color: #fff; font-size: calc(13px * var(--ta-font-scale, 1)); }
2485
+ .tmt-full-fixed { position: fixed; inset: 0; z-index: 45; display: flex; flex-direction: column; }
2486
+ .tmt-full-stage {
2487
+ position: absolute; display: flex; align-items: center; justify-content: center;
2488
+ top: env(safe-area-inset-top, 0px); right: env(safe-area-inset-right, 0px);
2489
+ bottom: env(safe-area-inset-bottom, 0px); left: env(safe-area-inset-left, 0px);
2490
+ }
2491
+ .tmt-full-head, .tmt-full .tmt-controls {
2492
+ position: absolute; left: 0; right: 0; margin: 0; transition: opacity 0.25s;
2493
+ padding-left: calc(16px + env(safe-area-inset-left, 0px)); padding-right: calc(16px + env(safe-area-inset-right, 0px));
2494
+ }
2495
+ .tmt-full-head {
2496
+ top: 0; display: flex; align-items: center; gap: 8px;
2497
+ padding-top: calc(10px + env(safe-area-inset-top, 0px)); padding-bottom: 24px;
2498
+ background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
2499
+ }
2500
+ .tmt-full-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
2501
+ .tmt-full .tmt-controls {
2502
+ bottom: 0; padding-top: 28px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
2503
+ background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
2504
+ }
2505
+ .tmt-full .tmt-icon { color: #fff; }
2506
+ .tmt-full .tmt-icon:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
2507
+ .tmt-full .tmt-time { color: rgba(255, 255, 255, 0.75); }
2508
+ .tmt-full .tmt-ticks i { background: rgba(255, 255, 255, 0.35); }
2509
+ .tmt-idle { cursor: none; }
2510
+ .tmt-idle .tmt-full-head, .tmt-idle .tmt-controls { opacity: 0; pointer-events: none; }
2159
2511
  .tmt-controls { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
2160
2512
  .tmt-play {
2161
2513
  flex: none; display: inline-flex; align-items: center; justify-content: center;
@@ -2168,30 +2520,26 @@ var STYLE = `
2168
2520
  .tmt-ticks i { position: absolute; top: -5px; width: 2px; height: 10px; margin-left: -1px; border-radius: 1px; background: var(--ta-border); }
2169
2521
  .tmt-time { flex: none; min-width: 72px; text-align: right; color: var(--ta-muted); font-variant-numeric: tabular-nums; font-size: calc(12px * var(--tmt-s)); }
2170
2522
  .tmt-edit {
2171
- flex: none; padding: 3px 10px; border: 1px solid var(--ta-border); border-radius: 999px;
2172
- background: transparent; color: var(--ta-text); font: inherit; cursor: pointer;
2523
+ flex: none; height: calc(28px * var(--tmt-s)); padding: 0 12px; border: 0; border-radius: 999px;
2524
+ background: var(--ta-chip); color: var(--ta-text); font: inherit; cursor: pointer; transition: background 0.15s;
2173
2525
  }
2174
- .tmt-edit[data-on] { border-color: var(--ta-accent); color: var(--ta-accent); }
2526
+ .tmt-edit:hover { background: var(--ta-hover-strong); }
2527
+ .tmt-edit[data-on] { background: color-mix(in srgb, var(--ta-accent) 14%, transparent); color: var(--ta-accent); }
2175
2528
  .tmt-making, .tmt-failed { color: var(--ta-muted); }
2176
2529
  .tmt-making-line { color: var(--ta-text); }
2177
2530
  .tmt-muted { color: var(--ta-muted); font-size: calc(12px * var(--tmt-s)); }
2178
- .tmt-editor { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--ta-border); }
2531
+ .tmt-editor { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--ta-border-muted); }
2179
2532
  .tmt-scenes { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
2180
2533
  .tmt-scenes button {
2181
- min-width: 30px; height: 26px; padding: 0 8px; border: 1px solid var(--ta-border); border-radius: 8px;
2182
- background: transparent; color: var(--ta-text); font: inherit; cursor: pointer;
2534
+ min-width: 30px; height: 26px; padding: 0 8px; border: 0; border-radius: 8px;
2535
+ background: var(--ta-chip); color: var(--ta-text); font: inherit; cursor: pointer;
2183
2536
  }
2184
- .tmt-scenes button[data-on] { border-color: var(--ta-accent); background: var(--ta-accent); color: #fff; }
2537
+ .tmt-scenes button:hover { background: var(--ta-hover-strong); }
2538
+ .tmt-scenes button[data-on] { background: var(--ta-accent); color: #fff; }
2185
2539
  .tmt-fields { display: flex; flex-direction: column; gap: 8px; }
2186
2540
  .tmt-row { display: flex; gap: 8px; }
2187
- .tmt-row > .tmt-field { flex: 1; min-width: 0; }
2188
- .tmt-field { display: flex; flex-direction: column; gap: 3px; }
2189
- .tmt-field span, .tmt-group-name { color: var(--ta-muted); font-size: calc(12px * var(--tmt-s)); }
2190
- .tmt-field input, .tmt-field textarea {
2191
- width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--ta-border); border-radius: 8px;
2192
- background: var(--ta-input, transparent); color: var(--ta-text); font: inherit; resize: vertical;
2193
- }
2194
- .tmt-field input:focus, .tmt-field textarea:focus { outline: none; border-color: var(--ta-accent); }
2541
+ .tmt-row > .ta-form-item { flex: 1; min-width: 0; }
2542
+ .tmt-group-name { color: var(--ta-muted); font-size: calc(12px * var(--tmt-s)); }
2195
2543
  .tmt-group { display: flex; flex-direction: column; gap: 6px; }
2196
2544
  `;
2197
2545
  function injectStyle() {