fablecut 1.22.1 → 1.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/app.js CHANGED
@@ -33,6 +33,13 @@ const TRACK_SIZE_PRESETS = {
33
33
  m: { thumbs: true, hVideo: 44, hAudio: 32 },
34
34
  l: { thumbs: true, hVideo: 58, hAudio: 42 },
35
35
  };
36
+ /* a finger needs taller lanes; empty ones shrink to a line (fitTrackHeights) */
37
+ const TRACK_SIZE_PHONE = {
38
+ s: { hVideo: 36, hAudio: 32 },
39
+ m: { hVideo: 46, hAudio: 40 },
40
+ l: { hVideo: 58, hAudio: 50 },
41
+ };
42
+ const TRACK_H_EMPTY = 12;
36
43
  const TRACK_SIZE_KEY = "fablecut-track-size";
37
44
  const LAST_TRANS_KEY = { in: "fablecut-last-trans-in", out: "fablecut-last-trans-out" };
38
45
  const DEFAULT_LAST_TRANS = { type: "fade", duration: 1 };
@@ -1200,9 +1207,15 @@ function localTimeForMedia(c, mediaTarget) {
1200
1207
  return (i - 1 + frac) * step;
1201
1208
  }
1202
1209
  let toastTimer = null;
1210
+ /* A symbol that phones draw as a colour emoji. Desktop shows the character; the
1211
+ compact layouts show the icon compact.css has under the same name. */
1212
+ const GLYPHS = { play: "▶", pause: "⏸", folder: "📁", browse: "📂", audio: "🎵", svg: "✨", image: "🖼", video: "🎞", sfx: "🔊", piece: "🧩", warn: "⚠", get: "⬇" };
1213
+ const glyph = (name) => `<span class="gx gx-${name}">${GLYPHS[name]}</span>`;
1214
+ /** On a phone or tablet the same hint in touch words ("tap" for "click"; compact.js has the list). */
1215
+ const touchWords = (s) => (self.FableCutCompact && monCompact() ? FableCutCompact.words(s) : s);
1203
1216
  function toast(msg) {
1204
1217
  if (!els.toast) return;
1205
- els.toast.textContent = msg;
1218
+ els.toast.textContent = touchWords(msg);
1206
1219
  els.toast.classList.add("show");
1207
1220
  clearTimeout(toastTimer);
1208
1221
  toastTimer = setTimeout(() => els.toast.classList.remove("show"), 3200);
@@ -1978,6 +1991,14 @@ function mediaKindFromFile(file) {
1978
1991
  if (["png", "jpg", "jpeg", "gif", "webp", "bmp", "avif"].includes(ext)) return "image";
1979
1992
  return null;
1980
1993
  }
1994
+ /** Why a file can't be used here, in words a person can act on. */
1995
+ function importWhy(file, kind) {
1996
+ const ext = (/\.([a-z0-9]+)$/i.exec(file.name) || [])[1] || "";
1997
+ if (/^hei[cf]$/i.test(ext) || /hei[cf]/i.test(file.type || "")) return "a HEIC photo, which this browser can't read. Save or share it as JPEG, or set the camera to JPEG";
1998
+ if (!kind) return `the editor doesn't know this type${ext ? ` (.${ext.toLowerCase()})` : ""}`;
1999
+ if (kind === "video") return "this browser can't play it. Camera clips are often HEVC (H.265): set the camera to H.264 (“Most compatible”), or convert this one";
2000
+ return "the file can't be read";
2001
+ }
1981
2002
  async function importFiles(fileList) {
1982
2003
  const files = [...fileList];
1983
2004
  if (!files.length) return [];
@@ -1985,14 +2006,20 @@ async function importFiles(fileList) {
1985
2006
  ? runtime.importFolderId : null;
1986
2007
  runtime.importFolderId = null;
1987
2008
  let added = 0, skipped = 0;
1988
- const addedMedia = [], gen = runtime.projectGen;
2009
+ const addedMedia = [], gen = runtime.projectGen, notes = []; // notes: what to know about a file (left out, or no picture)
2010
+ const tell = (i, name) => window.dispatchEvent(new CustomEvent("fablecut:importing", { detail: { i, n: files.length, name, notes: i < files.length ? [] : notes } }));
1989
2011
  for (const file of files) {
2012
+ tell(files.indexOf(file), file.name);
1990
2013
  const kind = mediaKindFromFile(file);
1991
- if (!kind) { skipped++; continue; }
2014
+ if (!kind) { skipped++; notes.push({ name: file.name, why: importWhy(file, null) }); continue; }
1992
2015
  let src, transient = false;
1993
2016
  if (state.connected) {
1994
2017
  try {
1995
2018
  const res = await fetch("/api/upload?name=" + encodeURIComponent(file.name), { method: "POST", body: file });
2019
+ if (res.status === 507) { // no room for it: a clip that lives only in this tab would be lost with it
2020
+ notes.push({ name: file.name, why: (await res.json().catch(() => ({}))).error || "there is no room left to store it" });
2021
+ skipped++; continue;
2022
+ }
1996
2023
  if (!res.ok) throw new Error("upload " + res.status);
1997
2024
  src = (await res.json()).src;
1998
2025
  } catch { src = URL.createObjectURL(file); transient = true; }
@@ -2004,7 +2031,8 @@ async function importFiles(fileList) {
2004
2031
  await loadMediaMetadata(m);
2005
2032
  if (kind === "video") grabThumb(m).catch(() => { });
2006
2033
  ensureWave(m);
2007
- } catch { skipped++; continue; }
2034
+ } catch { skipped++; notes.push({ name: file.name, why: importWhy(file, kind) }); continue; }
2035
+ if (kind === "video" && !m.width && m.duration > 0) notes.push({ name: file.name, why: "only its sound can be used: " + importWhy(file, kind) });
2008
2036
  if (gen !== runtime.projectGen) { toast("Import stopped: another project was opened. The uploaded files are in media/"); break; }
2009
2037
  project.media.push(m);
2010
2038
  addedMedia.push(m);
@@ -2016,6 +2044,8 @@ async function importFiles(fileList) {
2016
2044
  toast("Couldn't import — unsupported or unreadable file type");
2017
2045
  else if (skipped)
2018
2046
  toast(`Imported ${added}, skipped ${skipped}`);
2047
+ tell(files.length, "");
2048
+ if (added) window.dispatchEvent(new CustomEvent("fablecut:imported", { detail: { media: addedMedia, gen } }));
2019
2049
  return addedMedia;
2020
2050
  }
2021
2051
 
@@ -2104,7 +2134,7 @@ function renderBin() {
2104
2134
  if (mediaOffline.size && binView.filter !== "offline") {
2105
2135
  const warn = document.createElement("div");
2106
2136
  warn.className = "bin-filterbar bin-offline-bar";
2107
- warn.innerHTML = `<span>⚠ ${mediaOffline.size} file${mediaOffline.size === 1 ? " is" : "s are"} offline</span>
2137
+ warn.innerHTML = `<span>${glyph("warn")} ${mediaOffline.size} file${mediaOffline.size === 1 ? " is" : "s are"} offline</span>
2108
2138
  <button type="button" class="btn tiny" data-show>Show</button><button type="button" class="btn tiny accent" data-relink>Relink…</button>`;
2109
2139
  warn.querySelector("[data-show]").addEventListener("click", () => setBinFilter("offline"));
2110
2140
  warn.querySelector("[data-relink]").addEventListener("click", () => openRelinkDialog());
@@ -2172,7 +2202,7 @@ function renderBin() {
2172
2202
  item.dataset.mediaId = m.id;
2173
2203
  item.style.setProperty("--bin-depth", flat ? 0 : depth);
2174
2204
  const aux = runtime.mediaAux.get(m.id) || {};
2175
- const icon = mediaKindIcon(m.kind, "🎞");
2205
+ const icon = mediaKindIcon(m.kind, "video");
2176
2206
  const thumbSrc = aux.thumb || (m.kind === "image" || m.kind === "svg" ? m.src : null);
2177
2207
  const uses = ctx.usage.get(m.id) || 0;
2178
2208
  const folder = flat && m.folderId ? getFolder(m.folderId) : null;
@@ -2197,12 +2227,13 @@ function renderBin() {
2197
2227
  <div class="bin-sub">${offline ? `<span class="bin-offline" title="The file is missing — right-click → Relink…">OFFLINE</span> ` : ""}${escapeHtml(sub)}</div>
2198
2228
  ${m.tags && m.tags.length ? `<div class="bin-tags">${m.tags.map((t) => `<span class="bin-tag">#${escapeHtml(t)}</span>`).join("")}</div>` : ""}
2199
2229
  </div>
2230
+ <button type="button" class="btn tiny bin-add" title="Add at the playhead" aria-label="Add at the playhead">+</button>
2200
2231
  <div class="bin-side">${favHtml}${usesHtml}${proxyBadgeHtml(m)}</div>
2201
2232
  <span class="bin-del" title="Remove (and its clips)">✕</span>`;
2202
2233
  }
2203
2234
  const thumbEl = item.querySelector(".bin-thumb");
2204
2235
  if (thumbSrc) thumbEl.style.backgroundImage = `url(${JSON.stringify(thumbSrc)})`;
2205
- else thumbEl.textContent = icon;
2236
+ else thumbEl.innerHTML = icon;
2206
2237
  const nameEl = item.querySelector(".bin-name");
2207
2238
  nameEl.textContent = m.name;
2208
2239
  item.title = [m.name, offline ? "⚠ Offline: " + decodeURIComponent(String(m.src).split("?")[0]) + " is missing — right-click → Relink…" : "", MediaLib.describe(m), m.tags && m.tags.length ? m.tags.map((t) => "#" + t).join(" ") : ""].filter(Boolean).join("\n");
@@ -2237,6 +2268,7 @@ function renderBin() {
2237
2268
  if (getSetting("linkSelect")) flashMonitorAttention();
2238
2269
  });
2239
2270
  item.addEventListener("contextmenu", (e) => { e.preventDefault(); e.stopPropagation(); showMediaMenu(e.clientX, e.clientY, m); });
2271
+ item.querySelector(".bin-add")?.addEventListener("click", (e) => { e.stopPropagation(); addClipFromMedia(m); });
2240
2272
  item.querySelector(".bin-fav").addEventListener("click", (e) => { e.stopPropagation(); setMediaFavorite([m.id], !m.favorite); });
2241
2273
  item.querySelector(".bin-uses").addEventListener("click", (e) => {
2242
2274
  e.stopPropagation();
@@ -2260,7 +2292,7 @@ function renderBin() {
2260
2292
  const count = mediaInFolder(f.id).length + folderChildren(f.id).length;
2261
2293
  row.innerHTML = `
2262
2294
  <button type="button" class="bin-folder-twist" title="${f.open ? "Collapse" : "Expand"}" aria-expanded="${f.open}">${f.open ? "▼" : "▶"}</button>
2263
- <span class="bin-folder-icon">📁</span>
2295
+ <span class="bin-folder-icon">${glyph("folder")}</span>
2264
2296
  <span class="bin-folder-name"></span>
2265
2297
  <span class="bin-folder-count">${count}</span>
2266
2298
  <button type="button" class="bin-folder-add" title="New subfolder">+</button>
@@ -2597,6 +2629,7 @@ function showMediaMenu(x, y, m) {
2597
2629
  toast(`Added ${m.name} to the collection “${col.name}”`);
2598
2630
  }, { placeholder: "Selects, Interviews…", ok: "Create" }));
2599
2631
  sep();
2632
+ if (monCompact() && project.folders.length) item("Move to folder…", () => FableCutCompact.moveToFolder(x, y, m.folderId || null, (id) => moveMediaToFolder(m.id, id)));
2600
2633
  item("Remove from project", () => removeMediaFromBin(m));
2601
2634
  document.body.appendChild(menu);
2602
2635
  menu.id = "trackCtxMenu";
@@ -2681,6 +2714,7 @@ function goToPlacement(p) {
2681
2714
  /* Reveal in project: show a clip's media (or comp) in the Project bin. */
2682
2715
  function revealInProject(c) {
2683
2716
  const id = c.kind === "comp" ? null : c.mediaId;
2717
+ if (self.FableCutCompact && monCompact()) FableCutCompact.openSheet("media");
2684
2718
  if (state.binTab !== "project") setBinTab("project");
2685
2719
  let sel;
2686
2720
  if (id) {
@@ -3153,12 +3187,12 @@ function libKind(name) {
3153
3187
  if (IMAGE_EXT.test(name)) return "image";
3154
3188
  return null;
3155
3189
  }
3156
- /** Emoji shown for a bin/library item without a thumbnail preview. `other` is
3190
+ /** Symbol (markup) shown for a bin/library item without a thumbnail preview. `other` is
3157
3191
  * the fallback for kinds not explicitly mapped here (image/svg items always
3158
3192
  * render a real thumbnail in both callers, so their icon is never actually
3159
3193
  * shown). Shared by renderBin and renderLibrary. */
3160
3194
  function mediaKindIcon(kind, other) {
3161
- return kind === "audio" ? "🎵" : kind === "svg" ? "✨" : kind === "image" ? "🖼" : kind === "video" ? "🎞" : other;
3195
+ return glyph(["audio", "svg", "image", "video"].includes(kind) ? kind : other);
3162
3196
  }
3163
3197
  /* Find-or-create the project media entry for a library file (dedup by src). */
3164
3198
  function mediaForLibraryItem(f) {
@@ -3192,18 +3226,18 @@ function toggleSfxPreview(f, btn) {
3192
3226
  const cur = runtime.sfxPreview;
3193
3227
  if (cur && cur.dataset.src === f.src && !cur.paused) {
3194
3228
  cur.pause();
3195
- btn.textContent = "▶";
3229
+ btn.innerHTML = glyph("play");
3196
3230
  return;
3197
3231
  }
3198
3232
  if (cur) { cur.pause(); }
3199
3233
  musicPreviewStop();
3200
- els.libList.querySelectorAll(".music-play").forEach((b) => (b.textContent = "▶"));
3201
- els.libList.querySelectorAll(".lib-play").forEach((b) => (b.textContent = "▶"));
3234
+ els.libList.querySelectorAll(".music-play").forEach((b) => (b.innerHTML = glyph("play")));
3235
+ els.libList.querySelectorAll(".lib-play").forEach((b) => (b.innerHTML = glyph("play")));
3202
3236
  const a = new Audio(f.src);
3203
3237
  a.dataset.src = f.src;
3204
- a.onended = () => { btn.textContent = "▶"; };
3238
+ a.onended = () => { btn.innerHTML = glyph("play"); };
3205
3239
  a.play().catch(() => toast("Couldn't play " + f.name));
3206
- btn.textContent = "⏸";
3240
+ btn.innerHTML = glyph("pause");
3207
3241
  runtime.sfxPreview = a;
3208
3242
  }
3209
3243
  function renderLibrary() {
@@ -3222,7 +3256,7 @@ function renderLibrary() {
3222
3256
  els.libList.appendChild(head);
3223
3257
  } else if (!files.length) {
3224
3258
  els.libList.innerHTML = `<div class="bin-empty">
3225
- <div class="bin-empty-icon">${dir === "sfx" ? "🔊" : dir === "svg" ? "✨" : "🧩"}</div>
3259
+ <div class="bin-empty-icon">${glyph(dir === "sfx" ? "sfx" : dir === "svg" ? "svg" : "piece")}</div>
3226
3260
  <p>No assets yet.</p>
3227
3261
  <p class="hint">Drop files into<br><b>library/${dir}/</b><br>— this list live-updates.</p></div>`;
3228
3262
  return;
@@ -3233,18 +3267,18 @@ function renderLibrary() {
3233
3267
  item.className = "bin-item lib-item";
3234
3268
  item.draggable = true;
3235
3269
  const visual = kind === "image" || kind === "svg";
3236
- const icon = mediaKindIcon(kind, "🧩");
3270
+ const icon = mediaKindIcon(kind, "piece");
3237
3271
  item.innerHTML = `
3238
3272
  <div class="bin-thumb${kind === "svg" ? " svg" : ""}"></div>
3239
3273
  <div class="bin-meta">
3240
3274
  <div class="bin-name"></div>
3241
3275
  <div class="bin-sub">${(f.size / 1024).toFixed(0)} KB</div>
3242
3276
  </div>
3243
- ${dir === "sfx" ? `<button class="btn tiny lib-play" title="Preview">▶</button>` : ""}
3277
+ ${dir === "sfx" ? `<button class="btn tiny lib-play" title="Preview">${glyph("play")}</button>` : ""}
3244
3278
  <button class="btn tiny accent lib-add" title="Add at playhead">+</button>`;
3245
3279
  const thumbEl = item.querySelector(".bin-thumb");
3246
3280
  if (visual) thumbEl.style.backgroundImage = `url(${JSON.stringify(f.src)})`;
3247
- else thumbEl.textContent = icon;
3281
+ else thumbEl.innerHTML = icon;
3248
3282
  const nameEl = item.querySelector(".bin-name");
3249
3283
  nameEl.textContent = f.name;
3250
3284
  nameEl.title = f.rel || f.name;
@@ -3337,17 +3371,17 @@ async function musicSearch(kind, more) {
3337
3371
  }
3338
3372
  function musicTogglePreview(t, btn) {
3339
3373
  if (musicPreview && musicPreview.id === t.id) {
3340
- musicPreviewStop(); btn.textContent = "▶"; return;
3374
+ musicPreviewStop(); btn.innerHTML = glyph("play"); return;
3341
3375
  }
3342
3376
  musicPreviewStop();
3343
3377
  if (runtime.sfxPreview) runtime.sfxPreview.pause();
3344
- els.libList.querySelectorAll(".music-play, .lib-play").forEach((b) => (b.textContent = "▶"));
3378
+ els.libList.querySelectorAll(".music-play, .lib-play").forEach((b) => (b.innerHTML = glyph("play")));
3345
3379
  const a = new Audio(t.url);
3346
3380
  // the list may have been redrawn since: reset whichever ▶ buttons are on screen now
3347
3381
  const done = () => {
3348
3382
  if (!musicPreview || musicPreview.audio !== a) return; // stopped or replaced meanwhile
3349
3383
  musicPreview = null;
3350
- els.libList.querySelectorAll(".music-play").forEach((b) => (b.textContent = "▶"));
3384
+ els.libList.querySelectorAll(".music-play").forEach((b) => (b.innerHTML = glyph("play")));
3351
3385
  };
3352
3386
  a.onended = done;
3353
3387
  a.play().catch((e) => {
@@ -3355,7 +3389,7 @@ function musicTogglePreview(t, btn) {
3355
3389
  done();
3356
3390
  toast("Couldn't play " + t.title);
3357
3391
  });
3358
- btn.textContent = "⏸";
3392
+ btn.innerHTML = glyph("pause");
3359
3393
  musicPreview = { id: t.id, audio: a };
3360
3394
  }
3361
3395
  /** Download a track into media/ and register it with its licence; place = add at the playhead too. */
@@ -3506,13 +3540,13 @@ function appendOnlineSearch(kind, focus) {
3506
3540
  item.className = "bin-item lib-item music-item";
3507
3541
  const busy = musicImporting.has(t.id);
3508
3542
  item.innerHTML = `
3509
- <button type="button" class="btn tiny music-play" title="Preview">${musicPreview && musicPreview.id === t.id ? "⏸" : "▶"}</button>
3543
+ <button type="button" class="btn tiny music-play" title="Preview">${glyph(musicPreview && musicPreview.id === t.id ? "pause" : "play")}</button>
3510
3544
  <div class="bin-meta">
3511
3545
  <div class="bin-name"></div>
3512
3546
  <div class="bin-sub"></div>
3513
3547
  <div class="music-lic"></div>
3514
3548
  </div>
3515
- <button type="button" class="btn tiny music-get" title="Import into the Project bin"${busy ? " disabled" : ""}>${busy ? "…" : "⬇"}</button>
3549
+ <button type="button" class="btn tiny music-get" title="Import into the Project bin"${busy ? " disabled" : ""}>${busy ? "…" : glyph("get")}</button>
3516
3550
  <button type="button" class="btn tiny accent lib-add" title="Import and add at the playhead"${busy ? " disabled" : ""}>+</button>`;
3517
3551
  item.querySelector(".bin-name").textContent = t.title;
3518
3552
  item.querySelector(".bin-name").title = t.title + (t.tags.length ? "\n#" + t.tags.join(" #") : "");
@@ -4402,7 +4436,8 @@ function addClipFromMedia(m, trackId, at) {
4402
4436
  // plant a stereo placeholder now (so the drop isn't picture-only, and so the
4403
4437
  // next pushUndo snapshot includes the AV link); reconcileAudioChannels upgrades
4404
4438
  // or trims once decodeAudioData reports the real count.
4405
- if (kind === "video") {
4439
+ // A file known to have no audio stream (a screen recording, a time-lapse) gets none.
4440
+ if (kind === "video" && m.audioChannels !== 0) {
4406
4441
  c.props.volume = 0;
4407
4442
  c.linkGroup = "lg_" + uid();
4408
4443
  const nCh = m.channels > 0 ? m.channels : 2;
@@ -4458,7 +4493,7 @@ function insertSourceAtPlayhead() {
4458
4493
  if (state.playing) pause();
4459
4494
  if (state.source.playing) pauseSource();
4460
4495
  pushUndo();
4461
- const { clip: c, at } = EDIT.insertAt(m, inn, duration, state.time);
4496
+ const { clip: c, at } = EDIT.insertAt(m, inn, duration, state.time, m.audioChannels === 0 ? 0 : undefined);
4462
4497
  if (c) selectClip(c.id);
4463
4498
  state.time = +(at + duration).toFixed(4);
4464
4499
  state.dirtyTimeline = true;
@@ -4485,7 +4520,7 @@ function replaceSourceAtPlayhead() {
4485
4520
  if (state.playing) pause();
4486
4521
  if (state.source.playing) pauseSource();
4487
4522
  pushUndo();
4488
- const { clip: c, at } = EDIT.overwriteAt(m, inn, duration, state.time);
4523
+ const { clip: c, at } = EDIT.overwriteAt(m, inn, duration, state.time, m.audioChannels === 0 ? 0 : undefined);
4489
4524
  pruneSelection();
4490
4525
  if (c) selectClip(c.id);
4491
4526
  state.time = +(at + duration).toFixed(4);
@@ -4760,7 +4795,7 @@ function openMediaPicker(anchor, c) {
4760
4795
  menu.className = "style-menu";
4761
4796
  const browse = document.createElement("div");
4762
4797
  browse.className = "style-opt media-opt";
4763
- browse.textContent = "📂 Browse file…";
4798
+ browse.innerHTML = glyph("browse") + " Browse file…";
4764
4799
  browse.addEventListener("click", () => {
4765
4800
  close();
4766
4801
  pickReplacementFile(c);
@@ -4916,6 +4951,7 @@ function gapSearchRange() {
4916
4951
  return { t0: 0, t1: Math.max(projDur(), 0) };
4917
4952
  }
4918
4953
  function ensurePlayheadVisible() {
4954
+ if (tlCentred()) return; // it always is
4919
4955
  const px = state.time * state.pps, sc = els.timelineScroll;
4920
4956
  if (!sc) return;
4921
4957
  if (px < sc.scrollLeft || px > sc.scrollLeft + sc.clientWidth - 40) {
@@ -5218,7 +5254,28 @@ els.timelineScroll.addEventListener("scroll", () => {
5218
5254
  const inner = $("trackHeadInner");
5219
5255
  if (inner) inner.style.transform = `translateY(${-els.timelineScroll.scrollTop}px)`;
5220
5256
  });
5257
+ /* On a phone scrolling the timeline is scrubbing it: a finger hides what it
5258
+ points at, so the playhead never has to be grabbed. 0:00 sits at the left edge
5259
+ (TL_LEFT clears the track letters); as time goes on the playhead drifts to the
5260
+ middle (tlHeadX) and stays there, so there is no empty half screen before the
5261
+ first clip and the clips always follow the finger. Every conversion between
5262
+ clientX and a time goes through tlX(); elsewhere that is plain scrollLeft. */
5263
+ const TL_LEFT = 46, TL_DRIFT = 1 / 3; // px on screen per px of timeline until the middle is reached
5264
+ const TL_LEFT_TABLET = 24; // room for the left trim grip of a clip at 0:00
5265
+ const tlCentred = () => typeof FableCutLayout !== "undefined" && FableCutLayout.mode === "phone";
5266
+ const tlPad = () => (tlCentred() ? TL_LEFT : typeof FableCutLayout !== "undefined" && FableCutLayout.mode === "tablet" ? TL_LEFT_TABLET : 0);
5267
+ const tlX = () => els.timelineScroll.scrollLeft - tlPad();
5268
+ const tlHeadX = (u) => Math.min(els.timelineScroll.clientWidth / 2, TL_LEFT + u * TL_DRIFT); // u = time × pps
5269
+ /** A finger moved the clips dx px to the left: the time that puts the playhead at. */
5270
+ function scrubTimeline(dx) {
5271
+ const u = state.time * state.pps, mid = els.timelineScroll.clientWidth / 2, left = u - tlHeadX(u) + dx;
5272
+ let next = (left + TL_LEFT) / (1 - TL_DRIFT);
5273
+ if (TL_LEFT + next * TL_DRIFT > mid) next = left + mid;
5274
+ setTime(next / state.pps);
5275
+ followCentre();
5276
+ }
5221
5277
  function contentWidth() {
5278
+ if (tlCentred()) return projDur() * state.pps + els.timelineScroll.clientWidth / 2; // the last frame can reach the middle
5222
5279
  const minSec = (els.timelineScroll.clientWidth || 800) / state.pps;
5223
5280
  return Math.max(projDur() + TIMELINE_PAD_SEC, minSec) * state.pps;
5224
5281
  }
@@ -5306,8 +5363,10 @@ function clipKeyframesHtml(c) {
5306
5363
  return html + `</div>`;
5307
5364
  }
5308
5365
  function rebuildClips() {
5309
- const w = contentWidth();
5366
+ fitTrackHeights();
5367
+ const w = contentWidth(), pad = tlPad();
5310
5368
  els.tracksContent.style.width = w + "px";
5369
+ els.tracksContent.style.marginLeft = pad ? pad + "px" : "";
5311
5370
  els.ruler.style.width = els.timelineScroll.clientWidth + "px";
5312
5371
  for (const row of els.tracks.children) row.innerHTML = "";
5313
5372
  const matted = project.clips.map((x) => [x, clipMatte(x)]).filter(([, m]) => m);
@@ -5756,7 +5815,7 @@ function drawRuler() {
5756
5815
  if (rulerWorker) {
5757
5816
  rulerWorker.postMessage({
5758
5817
  type: "draw", w, h, dpr,
5759
- sl: els.timelineScroll.scrollLeft, pps: state.pps,
5818
+ sl: tlX(), pps: state.pps,
5760
5819
  markers: project.markers, markerColors: MARKER_COLORS,
5761
5820
  inPoint: project.inPoint, outPoint: project.outPoint,
5762
5821
  time: state.time, fps: projectFps(),
@@ -5773,7 +5832,7 @@ function drawRulerMainThread(w, h, dpr) {
5773
5832
  const g = cv.getContext("2d");
5774
5833
  g.setTransform(dpr, 0, 0, dpr, 0, 0);
5775
5834
  g.clearRect(0, 0, w, h);
5776
- const sl = els.timelineScroll.scrollLeft, pps = state.pps;
5835
+ const sl = tlX(), pps = state.pps;
5777
5836
  const steps = [0.1, 0.25, 0.5, 1, 2, 5, 10, 15, 30, 60, 120, 300];
5778
5837
  const step = steps.find((s) => s * pps >= 70) || 600;
5779
5838
  const minor = step / 5;
@@ -5941,7 +6000,7 @@ function openSnapMenu(anchor) {
5941
6000
  /* ── Pointer interactions on timeline ── */
5942
6001
  function timeAtEvent(e) {
5943
6002
  const rect = els.timelineScroll.getBoundingClientRect();
5944
- return clamp((e.clientX - rect.left + els.timelineScroll.scrollLeft) / state.pps, 0, 1e6);
6003
+ return clamp((e.clientX - rect.left + tlX()) / state.pps, 0, 1e6);
5945
6004
  }
5946
6005
  function trackAtEvent(e) {
5947
6006
  for (const row of els.tracks.children) {
@@ -5982,8 +6041,9 @@ function showTrimReadout(ev, text) {
5982
6041
  document.body.appendChild(el);
5983
6042
  }
5984
6043
  el.textContent = text;
5985
- el.style.left = ev.clientX + 14 + "px";
5986
- el.style.top = ev.clientY + 18 + "px";
6044
+ const finger = ev.pointerType === "touch";
6045
+ el.style.left = ev.clientX + (finger ? -40 : 14) + "px";
6046
+ el.style.top = ev.clientY + (finger ? -74 : 18) + "px";
5987
6047
  el.hidden = false;
5988
6048
  }
5989
6049
  function hideTrimReadout() { if (runtime.trimReadout) runtime.trimReadout.hidden = true; }
@@ -6078,7 +6138,8 @@ els.tracksContent.addEventListener("contextmenu", (e) => {
6078
6138
  e.preventDefault();
6079
6139
  showClipCtxMenu(e.clientX, e.clientY, c);
6080
6140
  });
6081
- els.tracksContent.addEventListener("pointerdown", (e) => {
6141
+ /* (named: touch.js calls it once a finger's gesture is known to be an edit) */
6142
+ function timelinePointerDown(e) {
6082
6143
  if (e.button !== 0) return;
6083
6144
  // Clicking the timeline should release inspector text fields so shortcuts (z, s, …) work
6084
6145
  if (isTypingTarget(document.activeElement) && els.inspector.contains(document.activeElement))
@@ -6138,7 +6199,8 @@ els.tracksContent.addEventListener("pointerdown", (e) => {
6138
6199
  const mode = onHandle ? (edge === "l" ? "trim-l" : "trim-r") : "move";
6139
6200
  // a plain click (no drag) on a multi-selection collapses it to that clip on release
6140
6201
  startClipGesture(e, c, mode, !additive && state.selIds.size > 1);
6141
- });
6202
+ }
6203
+ els.tracksContent.addEventListener("pointerdown", timelinePointerDown);
6142
6204
 
6143
6205
  els.tracksContent.addEventListener("dblclick", (e) => {
6144
6206
  const clipDiv = e.target.closest(".clip");
@@ -6377,9 +6439,10 @@ function startScrub(e) {
6377
6439
  /* Marker under a ruler pointer event: the diamond row at the bottom, ±6 px. */
6378
6440
  function markerAtRulerEvent(e) {
6379
6441
  const r = els.ruler.getBoundingClientRect();
6380
- if (e.clientY - r.top < RULER_H - 13) return null;
6381
- const x = e.clientX - els.timelineScroll.getBoundingClientRect().left + els.timelineScroll.scrollLeft;
6382
- let best = null, bd = 6;
6442
+ const finger = e.pointerType === "touch";
6443
+ if (!finger && e.clientY - r.top < RULER_H - 13) return null;
6444
+ const x = e.clientX - els.timelineScroll.getBoundingClientRect().left + tlX();
6445
+ let best = null, bd = finger ? 16 : 6;
6383
6446
  for (const m of project.markers || []) {
6384
6447
  const d = Math.abs(m.t * state.pps - x);
6385
6448
  if (d <= bd) { bd = d; best = m; }
@@ -6567,6 +6630,7 @@ function seekToMarker(m) {
6567
6630
  }
6568
6631
  /* Scroll the timeline so time t is on screen (no-op when it already is). */
6569
6632
  function revealTime(t) {
6633
+ if (tlCentred()) return; // the view follows the playhead
6570
6634
  const sc = els.timelineScroll, px = t * state.pps;
6571
6635
  if (px < sc.scrollLeft || px > sc.scrollLeft + sc.clientWidth - 40)
6572
6636
  sc.scrollLeft = Math.max(0, px - sc.clientWidth / 3);
@@ -6779,18 +6843,20 @@ function setZoom(pps, anchorClientX) {
6779
6843
  const scroller = els.timelineScroll;
6780
6844
  const rect = scroller.getBoundingClientRect();
6781
6845
  const ax = anchorClientX != null ? anchorClientX - rect.left : rect.width / 2;
6782
- const tAtAnchor = (scroller.scrollLeft + ax) / state.pps;
6846
+ const tAtAnchor = (tlX() + ax) / state.pps;
6783
6847
  state.pps = clamp(pps, ZOOM_MIN, ZOOM_MAX);
6784
6848
  els.zoomSlider.value = state.pps;
6785
6849
  state.dirtyTimeline = true;
6786
6850
  rebuildClips();
6787
- scroller.scrollLeft = Math.max(0, tAtAnchor * state.pps - ax);
6851
+ if (tlCentred()) { followCentre(); return; } // zooms around the playhead
6852
+ scroller.scrollLeft = Math.max(0, tAtAnchor * state.pps - ax + tlPad());
6788
6853
  }
6789
6854
  /* Fit clip content into 95% of the viewport, then scroll to the start.
6790
6855
  TIMELINE_PAD_SEC is scroll room added by contentWidth(), not part of the fit. */
6791
6856
  function zoomToFit() {
6792
- const w = els.timelineScroll.clientWidth || 800;
6857
+ const w = (els.timelineScroll.clientWidth || 800) - tlPad();
6793
6858
  const span = Math.max(projDur(), 1);
6859
+ if (tlCentred()) setTime(0); // the view follows the playhead: all of it shows from the start
6794
6860
  setZoom((TIMELINE_FIT_FILL * w) / span);
6795
6861
  els.timelineScroll.scrollLeft = 0;
6796
6862
  }
@@ -6820,8 +6886,9 @@ function zoomToRange(t0, t1) {
6820
6886
  els.zoomSlider.value = pps;
6821
6887
  rebuildClips();
6822
6888
  const center = (t0 + t1) / 2;
6823
- const maxScroll = Math.max(0, contentWidth() - w);
6824
- els.timelineScroll.scrollLeft = clamp(center * pps - w / 2, 0, maxScroll);
6889
+ if (tlCentred()) { setTime(center); followCentre(); return; }
6890
+ const maxScroll = Math.max(0, contentWidth() + tlPad() - w);
6891
+ els.timelineScroll.scrollLeft = clamp(center * pps + tlPad() - w / 2, 0, maxScroll);
6825
6892
  }
6826
6893
  els.zoomSlider.addEventListener("input", () => setZoom(+els.zoomSlider.value));
6827
6894
  $("btnZoomFit").addEventListener("click", zoomToFit);
@@ -6917,6 +6984,7 @@ function clipStatusBar(c) {
6917
6984
  `</div>`;
6918
6985
  }
6919
6986
  function renderInspector(lite) {
6987
+ if (!lite) window.dispatchEvent(new Event("fablecut:selection")); // the compact tool bar follows it
6920
6988
  if (colorState.open && !lite) renderColorPage();
6921
6989
  const c = getClip(state.selId);
6922
6990
  if (!c) {
@@ -7940,7 +8008,7 @@ function updateSourceScrub() {
7940
8008
  }
7941
8009
  function syncPlayButton() {
7942
8010
  const on = isSourceMode() ? state.source.playing : state.playing;
7943
- els.btnPlay.textContent = on ? "⏸" : "▶";
8011
+ els.btnPlay.innerHTML = glyph(on ? "pause" : "play");
7944
8012
  els.btnPlay.classList.toggle("on", on);
7945
8013
  }
7946
8014
  /** Brief white border flash over the canvas (Project → Source feedback). */
@@ -8225,6 +8293,7 @@ function beginTcEntry(el, kind, initial) {
8225
8293
  input.spellcheck = false;
8226
8294
  input.autocomplete = "off";
8227
8295
  input.title = "Enter to go · Esc to cancel (see ? for formats)";
8296
+ if (window.matchMedia?.("(pointer: coarse)").matches) input.inputMode = "decimal";
8228
8297
  input.value = initial ?? fmt(base);
8229
8298
  // Sit exactly over the readout it replaces: same font, a hair of padding
8230
8299
  // for relative "+30" entries, no taller than the line (IN/OUT rows stack).
@@ -12449,7 +12518,7 @@ function showSequenceMenu(x, y) {
12449
12518
  item(`<span>Duplicate “${escapeHtml(open.name)}”</span>`, () => newSequence({ from: "open" }));
12450
12519
  item(`<span>Rename “${escapeHtml(open.name)}”…</span>`, () => promptBinText(x, y, "Sequence name", open.name, (v) => renameSequence(openId, v), { max: 120, ok: "Rename" }));
12451
12520
  item(`<span>Delete “${escapeHtml(open.name)}”…</span>`, (b) => {
12452
- if (b.dataset.armed !== "1") { b.dataset.armed = "1"; b.querySelector("span").textContent = "Click again to delete it"; return; }
12521
+ if (b.dataset.armed !== "1") { b.dataset.armed = "1"; b.querySelector("span").textContent = touchWords("Click again to delete it"); return; }
12453
12522
  hideTrackCtxMenu();
12454
12523
  deleteSequence(openId);
12455
12524
  }, rows.length < 2 ? "A project keeps at least one sequence" : null, true);
@@ -12882,10 +12951,18 @@ function isVisualClip(c) { return c && c.kind !== "adjust" && c.kind !== "audio"
12882
12951
  clamped into the visible canvas (inset by its own size) so it stays visible
12883
12952
  and grabbable when the clip's box extends past the frame. Drawing and
12884
12953
  hit-testing both use these, so they can never disagree. */
12954
+ /* Sizes of the editing handles, in canvas px. A finger needs a fixed size on the
12955
+ screen however small the preview is shown. Only the editing overlay and its hit
12956
+ tests use these: nothing that is exported does. */
12957
+ const monScale = () => els.preview.width / Math.max(1, els.preview.getBoundingClientRect().width);
12958
+ const monCompact = () => typeof FableCutLayout !== "undefined" && FableCutLayout.mode !== "desktop";
12959
+ const monMark = (base) => (monCompact() ? Math.max(base, 5.5 * monScale()) : base);
12960
+ const monGap = (base) => (monCompact() ? Math.max(base, 38 * monScale()) : base); // knob to edge: two fingertips apart
12961
+ const monGrab = (base, e) => (monCompact() || (e && e.pointerType === "touch") ? Math.max(base, 20 * monScale()) : base);
12885
12962
  function overlayHandles(b, W, H) {
12886
12963
  const cs = Math.cos(b.rot), sn = Math.sin(b.rot);
12887
12964
  const toScreen = (lx, ly) => ({ x: b.cx + lx * cs - ly * sn, y: b.cy + lx * sn + ly * cs });
12888
- const hs = Math.max(6, W / 150), gap = Math.max(24, W / 34), m = hs * 1.4;
12965
+ const hs = monMark(Math.max(6, W / 150)), gap = monGap(Math.max(24, W / 34)), m = hs * 1.4;
12889
12966
  const cl = (p) => ({ x: clamp(p.x, m, W - m), y: clamp(p.y, m, H - m) });
12890
12967
  return {
12891
12968
  hs,
@@ -12984,7 +13061,7 @@ els.preview.addEventListener("pointerdown", (e) => {
12984
13061
  canvasDrag = null;
12985
13062
  if (isVisualClip(cur) && activeAt(cur, state.time)) {
12986
13063
  const b = clipBounds(cur, evalProps(cur, state.time), W, H), lp = toLocal(pt, b);
12987
- const hd = overlayHandles(b, W, H), grab = hd.hs * 1.8;
13064
+ const hd = overlayHandles(b, W, H), grab = monGrab(hd.hs * 1.8, e);
12988
13065
  if (runtime.anchorTool) { // Anchor tool: the anchor point follows the pointer, the picture stays put
12989
13066
  const p0 = propsAtPlayhead(cur);
12990
13067
  canvasDrag = { mode: "anchor", id: cur.id, p0, m: layerScreenMatrix(cur, p0, W, H, state.time).scale(Motion.contentScale(cur, p0)).inverse() };
@@ -12994,7 +13071,7 @@ els.preview.addEventListener("pointerdown", (e) => {
12994
13071
  } else if (hd.corners.some((h) => Math.abs(pt.x - h.x) <= grab && Math.abs(pt.y - h.y) <= grab)) {
12995
13072
  if (cur.kind === "text" && !cur.props.textPath) { // a title on a path scales; its box is the path's
12996
13073
  canvasDrag = {
12997
- ...beginTextBoxDrag(cur, pt, W, H),
13074
+ ...beginTextBoxDrag(cur, pt, W, H, hd.corners.findIndex((h) => Math.abs(pt.x - h.x) <= grab && Math.abs(pt.y - h.y) <= grab)),
12998
13075
  seedBox: !hasTextBox(cur.props),
12999
13076
  startClient: { x: e.clientX, y: e.clientY },
13000
13077
  };
@@ -13045,7 +13122,7 @@ function updateCanvasCursor(e) {
13045
13122
  if (runtime.anchorTool && isVisualClip(cur) && activeAt(cur, state.time) && !state.playing && !state.exporting) cursor = "crosshair";
13046
13123
  else if (isVisualClip(cur) && activeAt(cur, state.time) && !state.playing && !state.exporting) {
13047
13124
  const b = clipBounds(cur, evalProps(cur, state.time), W, H);
13048
- const hd = overlayHandles(b, W, H), grab = hd.hs * 1.8;
13125
+ const hd = overlayHandles(b, W, H), grab = monGrab(hd.hs * 1.8, e);
13049
13126
  const corner = hd.corners.find((h) => Math.abs(pt.x - h.x) <= grab && Math.abs(pt.y - h.y) <= grab);
13050
13127
  const lp = toLocal(pt, b);
13051
13128
  if (Math.hypot(pt.x - hd.rotate.x, pt.y - hd.rotate.y) <= grab) cursor = ROTATE_CURSOR;
@@ -13070,7 +13147,7 @@ els.preview.addEventListener("pointermove", (e) => {
13070
13147
  canvasDidMove = true;
13071
13148
  if (canvasDrag.seedBox) {
13072
13149
  ensureTextBox(c);
13073
- Object.assign(canvasDrag, beginTextBoxDrag(c, pt, W, H), { seedBox: false });
13150
+ Object.assign(canvasDrag, beginTextBoxDrag(c, pt, W, H, canvasDrag.corner), { seedBox: false });
13074
13151
  }
13075
13152
  }
13076
13153
  if (canvasDrag.mode === "move") {
@@ -14043,7 +14120,7 @@ async function trackWithUi(c, label, job, after) {
14043
14120
  try {
14044
14121
  const r = await runTrack(c, { ...job, run, onProgress: (f) => {
14045
14122
  run.pct = f;
14046
- for (const el of els.inspector.querySelectorAll("[data-track-progress]")) el.textContent = `${label}: ${Math.round(f * 100)}% — Esc stops`;
14123
+ for (const el of els.inspector.querySelectorAll("[data-track-progress]")) el.textContent = touchWords(`${label}: ${Math.round(f * 100)}% — Esc stops`);
14047
14124
  } });
14048
14125
  if (r.samples.length < 2) { toast(r.lostAt != null ? "Lost the region on the next frame — try a spot with more detail, or a bigger region" : "Nothing to track there"); return r; }
14049
14126
  if (getClip(c.id) !== c || trackStamp(c) !== stamp || (maskStamp != null && JSON.stringify(maskList(c)[job.mask] ?? null) !== maskStamp)) {
@@ -14368,7 +14445,7 @@ function clipMaskHandles(c) {
14368
14445
  const A = Mask.anchors(m, B.bw, B.bh).map((a) => ({ a: B.toCanvas(a.x, a.y), i: B.toCanvas(a.ix, a.iy), o: B.toCanvas(a.ox, a.oy) }));
14369
14446
  const top = m.shape === "bezier" ? Math.min(...m.points.map((p) => p[1])) : -m.h / 2;
14370
14447
  const base = at(0, top), up = at(0, top - 0.01), d = Math.hypot(up.x - base.x, up.y - base.y) || 1;
14371
- const W = els.preview.width, H = els.preview.height, gap = Math.max(24, W / 34), inset = Math.max(8, W / 110);
14448
+ const W = els.preview.width, H = els.preview.height, gap = monGap(Math.max(24, W / 34)), inset = Math.max(8, W / 110);
14372
14449
  const knob = { x: clamp(base.x + (up.x - base.x) / d * gap, inset, W - inset), y: clamp(base.y + (up.y - base.y) / d * gap, inset, H - inset) };
14373
14450
  const edges = m.shape === "bezier" ? [] : [["w", m.w / 2, 0], ["w", -m.w / 2, 0], ["h", 0, m.h / 2], ["h", 0, -m.h / 2]].map(([k, x, y]) => ({ k, ...at(x, y) }));
14374
14451
  return { m, B, A, centre: at(0, 0), knob, knobBase: base, edges };
@@ -14383,7 +14460,7 @@ function strokeOutline(ctx, pts, closed) {
14383
14460
  function drawClipMaskOverlay(c, W) {
14384
14461
  const B = maskBox(c);
14385
14462
  if (!B) return false;
14386
- const lw = Math.max(1.5, W / 800), hs = Math.max(5, W / 170);
14463
+ const lw = Math.max(1.5, W / 800), hs = monMark(Math.max(5, W / 170));
14387
14464
  ctx2d.save();
14388
14465
  ctx2d.setTransform(1, 0, 0, 1, 0, 0);
14389
14466
  ctx2d.lineJoin = "round";
@@ -14480,7 +14557,7 @@ els.preview.addEventListener("pointerdown", (e) => {
14480
14557
  if (e.button !== 0 || isSourceMode()) return;
14481
14558
  const c = getClip(state.selId);
14482
14559
  if (!maskEditActive(c)) return;
14483
- const B = maskBox(c), pt = canvasPt(e), bp = B.toBox(pt), W = els.preview.width, grab = Math.max(8, W / 110);
14560
+ const B = maskBox(c), pt = canvasPt(e), bp = B.toBox(pt), W = els.preview.width, grab = monGrab(Math.max(8, W / 110), e);
14484
14561
  const near = (p) => Math.hypot(p.x - pt.x, p.y - pt.y) <= grab;
14485
14562
  if (maskUi.tool) {
14486
14563
  e.preventDefault(); e.stopImmediatePropagation();
@@ -14597,7 +14674,7 @@ els.preview.addEventListener("pointercancel", endClipMaskDrag, true);
14597
14674
  els.preview.addEventListener("dblclick", (e) => {
14598
14675
  const c = getClip(state.selId);
14599
14676
  if (!maskEditActive(c) || maskUi.tool) return;
14600
- const h = clipMaskHandles(c), pt = canvasPt(e), grab = Math.max(8, els.preview.width / 110);
14677
+ const h = clipMaskHandles(c), pt = canvasPt(e), grab = monGrab(Math.max(8, els.preview.width / 110), e);
14601
14678
  if (!h || h.m.shape !== "bezier") return;
14602
14679
  const i = h.A.findIndex((p) => Math.hypot(p.a.x - pt.x, p.a.y - pt.y) <= grab);
14603
14680
  if (i < 0) return;
@@ -15073,14 +15150,14 @@ function shapeHandles(c, W, H) {
15073
15150
  const at = (x, y) => { const q = I.transformPoint(new DOMPoint(x, y)); return { x: q.x, y: q.y }; };
15074
15151
  const corners = [[b.x0, b.y0], [b.x1, b.y0], [b.x1, b.y1], [b.x0, b.y1]].map(([x, y]) => ({ ...at(x, y), lx: x, ly: y }));
15075
15152
  const topMid = at((b.x0 + b.x1) / 2, b.y0), up = at((b.x0 + b.x1) / 2, b.y0 - 1), d = Math.hypot(up.x - topMid.x, up.y - topMid.y) || 1;
15076
- const gap = Math.max(24, W / 34), inset = Math.max(8, W / 110);
15153
+ const gap = monGap(Math.max(24, W / 34)), inset = Math.max(8, W / 110);
15077
15154
  const knob = { x: clamp(topMid.x + (up.x - topMid.x) / d * gap, inset, W - inset), y: clamp(topMid.y + (up.y - topMid.y) / d * gap, inset, H - inset) };
15078
15155
  const ol = it.type === "group" ? null : Motion.outline(it);
15079
15156
  const A = ol ? ol.A.map((a) => ({ a: at(a.x, a.y), i: at(a.ix, a.iy), o: at(a.ox, a.oy) })) : [];
15080
15157
  return { it, F, I, corners, topMid, knob, centre: at(0, 0), outline: ol, A, editable: it.type === "line" || it.type === "path" };
15081
15158
  }
15082
15159
  function drawShapeOverlay(c, W, H) {
15083
- const lw = Math.max(1.5, W / 800), hs = Math.max(5, W / 170);
15160
+ const lw = Math.max(1.5, W / 800), hs = monMark(Math.max(5, W / 170));
15084
15161
  const L = shapeLayerMatrix(c, W, H);
15085
15162
  ctx2d.save();
15086
15163
  ctx2d.setTransform(1, 0, 0, 1, 0, 0);
@@ -15164,7 +15241,7 @@ els.preview.addEventListener("pointerdown", (e) => {
15164
15241
  if (e.button !== 0 || isSourceMode()) return;
15165
15242
  const c = getClip(state.selId);
15166
15243
  if (!shapeEditActive(c)) return;
15167
- const W = els.preview.width, H = els.preview.height, pt = canvasPt(e), grab = Math.max(8, W / 110);
15244
+ const W = els.preview.width, H = els.preview.height, pt = canvasPt(e), grab = monGrab(Math.max(8, W / 110), e);
15168
15245
  const near = (p) => Math.hypot(p.x - pt.x, p.y - pt.y) <= grab;
15169
15246
  if (shapeUi.tool === "pen") {
15170
15247
  e.preventDefault(); e.stopImmediatePropagation();
@@ -15277,7 +15354,7 @@ els.preview.addEventListener("pointercancel", endShapeDrag, true);
15277
15354
  els.preview.addEventListener("dblclick", (e) => {
15278
15355
  const c = getClip(state.selId);
15279
15356
  if (!shapeEditActive(c) || shapeUi.tool) return;
15280
- const h = shapeHandles(c, els.preview.width, els.preview.height), pt = canvasPt(e), grab = Math.max(8, els.preview.width / 110);
15357
+ const h = shapeHandles(c, els.preview.width, els.preview.height), pt = canvasPt(e), grab = monGrab(Math.max(8, els.preview.width / 110), e);
15281
15358
  if (!h || h.it.type !== "path") return;
15282
15359
  const i = h.A.findIndex((p) => Math.hypot(p.a.x - pt.x, p.a.y - pt.y) <= grab);
15283
15360
  if (i < 0) return;
@@ -15561,7 +15638,7 @@ function motionPathGeom(c, W, H, t) {
15561
15638
  function drawMotionPathOverlay(c, W, H, t) {
15562
15639
  if (!motionPathActive(c)) return;
15563
15640
  if (pathUi.clip !== c.id) Object.assign(pathUi, { clip: c.id, key: -1, drag: null });
15564
- const g = motionPathGeom(c, W, H, t), lw = Math.max(1.5, W / 800), hs = Math.max(5, W / 170);
15641
+ const g = motionPathGeom(c, W, H, t), lw = Math.max(1.5, W / 800), hs = monMark(Math.max(5, W / 170));
15565
15642
  ctx2d.save();
15566
15643
  ctx2d.setTransform(1, 0, 0, 1, 0, 0);
15567
15644
  ctx2d.globalAlpha = 1; ctx2d.globalCompositeOperation = "source-over"; ctx2d.filter = "none";
@@ -15603,7 +15680,7 @@ els.preview.addEventListener("pointerdown", (e) => {
15603
15680
  if (e.button !== 0 || isSourceMode()) return;
15604
15681
  const c = getClip(state.selId);
15605
15682
  if (!motionPathActive(c) || maskEditActive(c) || shapeEditActive(c)) return;
15606
- const W = els.preview.width, H = els.preview.height, pt = canvasPt(e), grab = Math.max(8, W / 110);
15683
+ const W = els.preview.width, H = els.preview.height, pt = canvasPt(e), grab = monGrab(Math.max(8, W / 110), e);
15607
15684
  const g = motionPathGeom(c, W, H, state.time);
15608
15685
  const near = (q) => Math.hypot(q.x - pt.x, q.y - pt.y) <= grab;
15609
15686
  let drag = null;
@@ -15669,7 +15746,7 @@ els.preview.addEventListener("pointercancel", endPathDrag, true);
15669
15746
  els.preview.addEventListener("dblclick", (e) => {
15670
15747
  const c = getClip(state.selId);
15671
15748
  if (!motionPathActive(c) || maskEditActive(c) || shapeEditActive(c)) return;
15672
- const W = els.preview.width, H = els.preview.height, pt = canvasPt(e), grab = Math.max(8, W / 110);
15749
+ const W = els.preview.width, H = els.preview.height, pt = canvasPt(e), grab = monGrab(Math.max(8, W / 110), e);
15673
15750
  const g = motionPathGeom(c, W, H, state.time), j = g.keys.findIndex((k) => Math.hypot(k.a.x - pt.x, k.a.y - pt.y) <= grab);
15674
15751
  if (j < 0) return;
15675
15752
  e.preventDefault(); e.stopImmediatePropagation();
@@ -15917,17 +15994,17 @@ function ensureTextBox(c) {
15917
15994
  c.props.boxH = Math.max(24, +(half.hh * 2).toFixed(1));
15918
15995
  }
15919
15996
  /* Pin the opposite corner for a boxed-text resize (call after any seed). */
15920
- function beginTextBoxDrag(c, pt, W, H) {
15997
+ function beginTextBoxDrag(c, pt, W, H, corner = -1) { // corner: the one already taken, if any
15921
15998
  const b2 = clipBounds(c, evalProps(c, state.time), W, H);
15922
15999
  const hd2 = overlayHandles(b2, W, H);
15923
16000
  const grab = hd2.hs * 1.8;
15924
- const ci = hd2.corners.findIndex((h) => Math.abs(pt.x - h.x) <= grab && Math.abs(pt.y - h.y) <= grab);
16001
+ const ci = corner >= 0 ? corner : hd2.corners.findIndex((h) => Math.abs(pt.x - h.x) <= grab && Math.abs(pt.y - h.y) <= grab);
15925
16002
  const signs = [[-1, -1], [1, -1], [1, 1], [-1, 1]];
15926
16003
  const [dsx, dsy] = signs[ci >= 0 ? ci : 0];
15927
16004
  const cs = Math.cos(b2.rot), sn = Math.sin(b2.rot);
15928
16005
  const ox = -dsx * b2.hw, oy = -dsy * b2.hh;
15929
16006
  return {
15930
- mode: "box", id: c.id, rot: b2.rot, dragSX: dsx, dragSY: dsy,
16007
+ mode: "box", id: c.id, corner: ci, rot: b2.rot, dragSX: dsx, dragSY: dsy,
15931
16008
  fix: { x: b2.cx + ox * cs - oy * sn, y: b2.cy + ox * sn + oy * cs },
15932
16009
  aspect: Math.max(0.05, (b2.hw * 2) / Math.max(1e-6, b2.hh * 2)),
15933
16010
  };
@@ -16358,6 +16435,11 @@ async function loadProjectFonts() {
16358
16435
  try { await document.fonts.ready; } catch { }
16359
16436
  }
16360
16437
 
16438
+ /* Phone: the scroll position follows from the playhead's time. */
16439
+ function followCentre() {
16440
+ const sc = els.timelineScroll, u = state.time * state.pps, x = Math.max(0, u + TL_LEFT - tlHeadX(u));
16441
+ if (Math.abs(sc.scrollLeft - x) > 0.6) sc.scrollLeft = x;
16442
+ }
16361
16443
  /* ── Main loop ── */
16362
16444
  let lastTs = null;
16363
16445
  let exportWindow = null;
@@ -16457,7 +16539,7 @@ function loop(ts) {
16457
16539
  }
16458
16540
  // keep playhead visible
16459
16541
  const px = state.time * state.pps, sc = els.timelineScroll;
16460
- if (px < sc.scrollLeft || px > sc.scrollLeft + sc.clientWidth - 40)
16542
+ if (!tlCentred() && (px < sc.scrollLeft || px > sc.scrollLeft + sc.clientWidth - 40))
16461
16543
  sc.scrollLeft = Math.max(0, px - 60);
16462
16544
  }
16463
16545
  const draw = frameDue(ts);
@@ -16473,6 +16555,7 @@ function loop(ts) {
16473
16555
  if (state.dirtyTimeline) rebuildClips();
16474
16556
  if (trState.open) transcriptTick();
16475
16557
  watchCaptions(ts);
16558
+ if (tlCentred()) followCentre();
16476
16559
  const phX = Math.round(state.time * state.pps);
16477
16560
  if (phX !== playheadPx) {
16478
16561
  playheadPx = phX;
@@ -17429,10 +17512,14 @@ function exportWatchdog(seconds, onStall, { minMs = 60000, msPerSecond = 100, hi
17429
17512
  fail(err);
17430
17513
  }, Math.min(1000, limit / 4));
17431
17514
  const moved = () => { movedAt = performance.now(); };
17515
+ // a phone stops a tab in the background, timers and all: coming back, the export gets its whole limit again
17516
+ const back = () => { if (!document.hidden) moved(); };
17517
+ const page = typeof document !== "undefined" && document.addEventListener ? document : null;
17518
+ if (page) for (const ev of ["visibilitychange", "resume"]) page.addEventListener(ev, back);
17432
17519
  return {
17433
17520
  moved,
17434
17521
  guard(p) { return Promise.race([Promise.resolve(p).then((v) => { moved(); return v; }), stalled]); },
17435
- stop() { if (timer) clearInterval(timer); timer = 0; },
17522
+ stop() { if (timer) clearInterval(timer); timer = 0; if (page) for (const ev of ["visibilitychange", "resume"]) page.removeEventListener(ev, back); },
17436
17523
  };
17437
17524
  }
17438
17525
  /* Sequential /frame POSTs, batched. Concurrent bodies can still race on ffmpeg
@@ -18157,7 +18244,7 @@ async function fastExport(opts = {}) {
18157
18244
  const signal = exportAbort.signal;
18158
18245
  if (!opts.silent) showExportOverlay();
18159
18246
  els.exportProgress.style.width = "0%";
18160
- els.exportNote.textContent = "Rendering frames → ffmpeg. You can switch tabs; export continues.";
18247
+ els.exportNote.textContent = touchWords("Rendering frames → ffmpeg. You can switch tabs; export continues.");
18161
18248
  restoreExportVideoState();
18162
18249
  const deliveries = opts.deliveries || (opts.delivery ? [{ delivery: opts.delivery, name: opts.name || undefined }] : null);
18163
18250
  const delivery = deliveries ? deliveries[0].delivery : null;
@@ -18899,7 +18986,7 @@ async function webCodecsExport(name) {
18899
18986
  const signal = exportAbort.signal;
18900
18987
  showExportOverlay();
18901
18988
  els.exportProgress.style.width = "0%";
18902
- els.exportNote.textContent = "Encoding with WebCodecs → ffmpeg mux. You can switch tabs; export continues.";
18989
+ els.exportNote.textContent = touchWords("Encoding with WebCodecs → ffmpeg mux. You can switch tabs; export continues.");
18903
18990
  restoreExportVideoState();
18904
18991
  const { start: t0, end: t1, frames } = beginExportWindow();
18905
18992
  const fps = projectFps();
@@ -19387,6 +19474,7 @@ function cmdkCollect() {
19387
19474
  for (const h of document.querySelectorAll("#inspector .insp-section > h3")) {
19388
19475
  const name = h.textContent.replace(/\s+/g, " ").trim();
19389
19476
  add({ label: name, group: "Inspector", keywords: ["inspector", "section", "clip"], run: () => {
19477
+ if (self.FableCutCompact && monCompact()) { FableCutCompact.openSheet("inspector", { section: name }); return; }
19390
19478
  setSideTab("inspector");
19391
19479
  // the tab rebuilds the Inspector: find the section in the new one
19392
19480
  const live = [...document.querySelectorAll("#inspector .insp-section > h3")].find((x) => x.textContent.replace(/\s+/g, " ").trim() === name);
@@ -19569,6 +19657,7 @@ function onSettingsTabTrap(e) {
19569
19657
  }
19570
19658
  }
19571
19659
  function openSettings() {
19660
+ if ($("setLayout") && typeof FableCutLayout !== "undefined") $("setLayout").value = FableCutLayout.override || "";
19572
19661
  const cb = $("setLinkSelect");
19573
19662
  if (cb) cb.checked = !!getSetting("linkSelect");
19574
19663
  const ask = $("setExportAsk");
@@ -19590,6 +19679,7 @@ $("btnCloseSettings").addEventListener("click", closeSettings);
19590
19679
  $("settingsOverlay").addEventListener("click", (e) => {
19591
19680
  if (e.target === $("settingsOverlay")) closeSettings();
19592
19681
  });
19682
+ $("setLayout")?.addEventListener("change", (e) => FableCutLayout.set(e.target.value || null));
19593
19683
  $("setExportAsk")?.addEventListener("change", (e) => setSetting("exportAsk", !!e.target.checked));
19594
19684
  $("setLinkSelect").addEventListener("change", (e) => {
19595
19685
  setSetting("linkSelect", !!e.target.checked);
@@ -20276,6 +20366,8 @@ const TL_H_KEY = "fablecut-timeline-h";
20276
20366
  const TL_H_MIN = 180;
20277
20367
  const UPPER_MIN = 140;
20278
20368
  function availableTimelineMax() {
20369
+ // a tablet always keeps more than half for the preview and its panel
20370
+ if (typeof FableCutLayout !== "undefined" && FableCutLayout.mode === "tablet") return Math.floor(window.innerHeight * 0.46);
20279
20371
  const app = $("app").getBoundingClientRect();
20280
20372
  const topbar = document.querySelector(".topbar")?.getBoundingClientRect();
20281
20373
  const topbarH = topbar ? topbar.height : 46;
@@ -20295,6 +20387,7 @@ window.addEventListener("keyup", (e) => {
20295
20387
  });
20296
20388
  window.addEventListener("blur", () => { runtime.kHeld = false; });
20297
20389
  function setTimelineHeight(px) {
20390
+ if (tlCentred()) return px;
20298
20391
  const h = clamp(Math.round(px), TL_H_MIN, Math.max(TL_H_MIN, availableTimelineMax()));
20299
20392
  $("app").style.setProperty("--timeline-h", h + "px");
20300
20393
  state.dirtyTimeline = true;
@@ -20326,9 +20419,24 @@ function syncTrackSizeButtons() {
20326
20419
  document.body.classList.toggle("track-size-l", state.trackSize === "l");
20327
20420
  }
20328
20421
  function applyTrackHeights() {
20329
- const preset = TRACK_SIZE_PRESETS[state.trackSize] || TRACK_SIZE_PRESETS.l;
20422
+ const phone = tlCentred(), low = phone && FableCutLayout.landscape; // a phone on its side has room for small rows only
20423
+ const preset = (phone ? TRACK_SIZE_PHONE : TRACK_SIZE_PRESETS)[low ? "s" : state.trackSize] || TRACK_SIZE_PRESETS.l;
20424
+ const used = phone ? new Set(project.clips.map((c) => c.track)) : null;
20330
20425
  for (const t of TRACKS) {
20331
20426
  t.h = t.kind === "audio" ? preset.hAudio : preset.hVideo;
20427
+ if (phone && !used.has(t.id) && !runtime.showEmptyTracks && !runtime.keepEmptyTracks) t.h = TRACK_H_EMPTY;
20428
+ }
20429
+ }
20430
+ /* Phones show an empty track as a thin line; it opens up when a clip lands on
20431
+ it or while one is being carried. Sizes the rows in place. */
20432
+ function fitTrackHeights() {
20433
+ if (!tlCentred()) return;
20434
+ applyTrackHeights();
20435
+ for (const t of TRACKS) {
20436
+ const row = els.tracks.querySelector(`[data-track="${t.id}"]`), head = els.trackHeaders.querySelector(`.track-head[data-track="${t.id}"]`);
20437
+ if (!row) continue;
20438
+ if (head) { head.style.height = t.h + "px"; head.classList.toggle("thin", t.h === TRACK_H_EMPTY); }
20439
+ row.style.height = t.h + "px";
20332
20440
  }
20333
20441
  }
20334
20442
  /* Switch S/M/L track density, rebuild the timeline, and grow/shrink the pane
@@ -20609,7 +20717,7 @@ function bindColorPage(c) {
20609
20717
  cv.addEventListener("pointermove", (e) => {
20610
20718
  const d = colorState.drag;
20611
20719
  if (!d || d.w !== w) return;
20612
- const k = WHEEL_RIM[w] / Math.max(20, d.R) * (e.shiftKey ? 0.2 : 1);
20720
+ const k = WHEEL_RIM[w] / Math.max(20, d.R) * (e.shiftKey || runtime.fineWheels ? 0.2 : 1);
20613
20721
  let cb = d.cb + (e.clientX - d.x) * k, cr = d.cr - (e.clientY - d.y) * k;
20614
20722
  const r = Math.hypot(cb, cr) / WHEEL_RIM[w];
20615
20723
  if (r > 1) { cb /= r; cr /= r; }
@@ -20835,7 +20943,8 @@ function bindCurveEditor(c, guard) {
20835
20943
  drawCurveEditor(c); // fresh hit map: the panel may have resized, or no frame has drawn it yet
20836
20944
  const r = cv.getBoundingClientRect(), m = cv._map, px = e.clientX - r.left, py = e.clientY - r.top;
20837
20945
  const pts = curvePoints(c, colorState.curveTab, colorState.curveCh);
20838
- const i = pts.findIndex(([x, v]) => Math.hypot(m.X(x) / m.dpr - px, m.Y(v) / m.dpr - py) < 8);
20946
+ const off = pts.map(([x, v]) => Math.hypot(m.X(x) / m.dpr - px, m.Y(v) / m.dpr - py)), near = Math.min(...off);
20947
+ const i = near < (monCompact() ? 22 : 8) ? off.indexOf(near) : -1;
20839
20948
  return { pts, i, data: m.toData(px, py), px };
20840
20949
  };
20841
20950
  cv.addEventListener("pointerdown", (e) => {
@@ -21255,7 +21364,7 @@ function maskEditing(c) {
21255
21364
  function drawMaskOverlay(c, W) {
21256
21365
  const h = maskHandles(c);
21257
21366
  if (!h) return false;
21258
- const lw = Math.max(1.5, W / 800), hs = Math.max(5, W / 170);
21367
+ const lw = Math.max(1.5, W / 800), hs = monMark(Math.max(5, W / 170));
21259
21368
  ctx2d.save();
21260
21369
  ctx2d.setTransform(1, 0, 0, 1, 0, 0);
21261
21370
  const pts = maskOutline(c, h);
@@ -21303,7 +21412,7 @@ els.preview.addEventListener("pointerdown", (e) => {
21303
21412
  if (!maskEditing(c)) return;
21304
21413
  const h = maskHandles(c);
21305
21414
  if (!h) return;
21306
- const pt = canvasPt(e), W = els.preview.width, grab = Math.max(8, W / 110);
21415
+ const pt = canvasPt(e), W = els.preview.width, grab = monGrab(Math.max(8, W / 110), e);
21307
21416
  const near = (p) => Math.hypot(p.x - pt.x, p.y - pt.y) <= grab;
21308
21417
  const { m, sp } = h, a = sp.aspect, uv = sp.toUv(pt);
21309
21418
  let drag = null;
@@ -21387,7 +21496,7 @@ els.preview.addEventListener("pointercancel", endMaskDrag, true);
21387
21496
  els.preview.addEventListener("dblclick", (e) => {
21388
21497
  const c = getClip(state.selId);
21389
21498
  if (!maskEditing(c)) return;
21390
- const h = maskHandles(c), pt = canvasPt(e), grab = Math.max(8, els.preview.width / 110);
21499
+ const h = maskHandles(c), pt = canvasPt(e), grab = monGrab(Math.max(8, els.preview.width / 110), e);
21391
21500
  const i = h ? h.points.findIndex((p) => Math.hypot(p.x - pt.x, p.y - pt.y) <= grab) : -1;
21392
21501
  if (i < 0) return;
21393
21502
  e.preventDefault(); e.stopImmediatePropagation();
@@ -21552,6 +21661,17 @@ for (const b of document.querySelectorAll("#wsSwitch [data-ws]"))
21552
21661
  b.addEventListener("click", () => setWorkspace(b.dataset.ws));
21553
21662
 
21554
21663
  initPanelSplit();
21664
+ /* Another layout (a rotation, a resized window, the setting): rows and the
21665
+ split get that layout's sizes; selection, playhead, undo and whatever is
21666
+ open are untouched. */
21667
+ window.addEventListener("fablecut:layout", () => {
21668
+ applyTrackHeights();
21669
+ buildTrackDOM();
21670
+ if (!tlCentred()) setTimelineHeight(parseFloat(localStorage.getItem(TL_H_KEY)) || defaultTimelineHeight());
21671
+ rebuildClips();
21672
+ if (tlCentred()) followCentre(); else ensurePlayheadVisible();
21673
+ noteActivity();
21674
+ });
21555
21675
  buildTrackDOM();
21556
21676
  rebuildClips();
21557
21677
  renderBin();