diff --git a/Cargo.lock b/Cargo.lock index 51804f635..b012bda16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1207,6 +1207,7 @@ version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" dependencies = [ "gif", + "image", ] [[package]] @@ -1476,6 +1477,7 @@ name = "craft-webp" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87#5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" dependencies = [ + "image", "thiserror 2.0.21", ] diff --git a/ROADMAP.md b/ROADMAP.md index 656487144..88fa7335e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,6 +2,7 @@ **Stage: alpha** · next: beta, ~30 points of "ready for real work" and ~350–620 h away +> **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-15 · **Change:** minor (releases v0.22.0 through v0.24.1; .aep gained project export (#2594), drag-and-drop import (#3103), an audit of hostile inputs with every loss reported (#3299, #3300, #3319, #3365), placeholders for unmapped effects (#3087), Lumetri Color, Puppet, CC Color Neutralizer, EXtractoR/IDentifier, HDR Highlight Compression, Echo, Linear Wipe, Offset and Color Stabilizer mappings, text-animator and Source Text expressions (#3170) and twice the import speed (#3302); GPU rendering 2.6× faster with one upload per frame and single-copy readback (#3335), smooth preview lanes (#3345), bounded GPU memory (#3028), shared multi-layer EXR decode (#474), EXR output options (#2915, #2916) and a WebAssembly ABI 2 plug-in path (#3329); eighteen effect parameters now take After Effects' ranges (#3470–#3480, #3483–#3484, #3487–#3491), with Color Stabilizer sampling (#3125), masked Grid/Checkerboard/Circle (#3121), Cryptomatte selection and Matte Only (#2839, #3130), fast-conformed frame blending (#3180) and bounded Levels and time-stretch math; number-field arithmetic (#3195), expressionError (#3219), prop.get with footage (#3231), reversed-layer audio (#3239), keyframed audio waveforms (#1722), Effect Controls lock and rename selection (#3193, #3198), viewer snapping (#2681, #3229), Graph Editor theming (#3202), Convert To Bezier Path (#3237), stopwatch Add Expression (#3192), Shift-drag timeline snapping (#1828), anchored marquee (#2859), Go to Time (#3373), text layers whose names follow their text (#3233), mute-aware audio preview (#2104), ScriptUI panel bars (#2796), Closed-path and Effect Controls arrow fixes (#2817, #2869) and accessible Info, Flowchart, Script Console and 3D Camera Tracker blocks (#1341); a file-dialog crash fix (#3084), crash diagnostics and replayable repros (#3357, #1224), Flatpak updater and nightly release fixes (#3516, #3520), craft-libs format and update cutovers, and CI test stabilisation (#3650, #3689, #3704); readiness estimates unchanged) · **Target:** Adobe After Effects 2026 (26.5.0.89) > **Last reviewed:** 2026-10-22 · **Last updated:** 2026-11-05 · **Change:** minor (ProRes alpha final-run conformance; previously: features of 30 October in the progress log: text Line Join, Timeline drag-reorder and multi-select of effects, viewer edge pan, ScriptUI drag capture and dock size; previously: localization recount after #1774) · **Target:** Adobe After Effects 2026 (26.5.0.89) EffectCraft aims to do what After Effects does, with the same panels, menus and behaviour, written diff --git a/crates/engine/src/system/library.rs b/crates/engine/src/system/library.rs index 5b7f63092..204594f90 100644 --- a/crates/engine/src/system/library.rs +++ b/crates/engine/src/system/library.rs @@ -255,6 +255,80 @@ fn release_problem(r: &Release) -> Option { None } +/// An owner or repository name on GitHub: letters, digits, `.`, `-`, `_`, and not `.` or `..`. +fn valid_repo_part(p: &str) -> bool { + !p.is_empty() && p != "." && p != ".." && p.bytes().all(|b| b.is_ascii_alphanumeric() || b"._-".contains(&b)) +} + +/// The rest of `s` after `prefix`, ignoring ASCII case. +fn strip_prefix_ignore_case<'a>(s: &'a str, prefix: &str) -> Option<&'a str> { + let head = s.get(..prefix.len())?; + head.eq_ignore_ascii_case(prefix).then(|| s.get(prefix.len()..)).flatten() +} + +/// A `.` or `..` path segment, also percent-encoded. +fn dot_segment(p: &str) -> bool { + let p = p.to_ascii_lowercase().replace("%2e", "."); + p == "." || p == ".." +} + +/// A character a release or repository URL may not contain: `?`, `#`, `\`, Unicode white space, +/// or U+FEFF (the catalog schema's `\s` matches it too). +fn bad_url_char(c: char) -> bool { + matches!(c, '?' | '#' | '\\' | '\u{feff}') || c.is_whitespace() +} + +/// `(owner, name)` in lower case of a `https://github.com//` repository URL (an +/// optional trailing `/` or `.git`) or of a folder in one, `https://github.com///tree//`; +/// `None` for anything else. +fn github_repo(repo: &str) -> Option<(String, String)> { + let rest = strip_prefix_ignore_case(repo.trim(), "https://github.com/")?; + if rest.contains(bad_url_char) { + return None; + } + let rest = rest.strip_suffix('/').unwrap_or(rest); + let parts: Vec<&str> = rest.split('/').collect(); + let (owner, name) = match parts.as_slice() { + [owner, name] => (*owner, name.strip_suffix(".git").unwrap_or(name)), + [owner, name, "tree", folder @ ..] if !folder.is_empty() && folder.iter().all(|p| !p.is_empty() && !dot_segment(p)) => (*owner, *name), + _ => return None, + }; + (valid_repo_part(owner) && valid_repo_part(name)).then(|| (owner.to_ascii_lowercase(), name.to_ascii_lowercase())) +} + +/// Why an `https://` release URL can't be used, if it can't: it must be a release asset, +/// `https://github.com///releases/download//`, and when the package +/// names a `repo`, that must be a GitHub repository URL (see [`github_repo`]) of `/`. +fn release_url_problem(repo: &str, url: &str) -> Option { + let not_asset = || Some(format!("`{url}` isn't a release asset (https://github.com///releases/download//)")); + let Some(rest) = strip_prefix_ignore_case(url, "https://github.com/") else { return not_asset() }; + if rest.contains(bad_url_char) { + return not_asset(); + } + let parts: Vec<&str> = rest.split('/').collect(); + // At least six segments, not exactly six: a tag may contain `/` (`release/v1`), and its assets are + // then at `releases/download/release/v1/`. `.` and `..` (also percent-encoded) would move + // the download to another path. + if parts.len() < 6 || parts.iter().any(|p| p.is_empty() || dot_segment(p)) { + return not_asset(); + } + let (Some(owner), Some(name), Some(releases), Some(download)) = (parts.first(), parts.get(1), parts.get(2), parts.get(3)) else { return not_asset() }; + if !valid_repo_part(owner) || !valid_repo_part(name) || *releases != "releases" || *download != "download" { + return not_asset(); + } + let repo = repo.trim(); + if repo.is_empty() { + return None; + } + match github_repo(repo) { + Some((o, n)) if o == owner.to_ascii_lowercase() && n == name.to_ascii_lowercase() => None, + Some(_) => Some(format!("`{url}` isn't a release asset of the package's repository {repo}")), + None => Some(format!( + "the package's `repo` {repo} isn't a GitHub repository URL (https://github.com//), so `{url}` can't be checked against it" + )), + } +} + /// Read a catalog: packages and releases that are malformed are left out (and reported), so one /// bad entry doesn't hide the others. pub fn parse_catalog(bytes: &[u8]) -> std::result::Result<(Catalog, Vec), String> { @@ -325,27 +399,44 @@ enum Source { File(PathBuf), } -/// `file:///C:/x` or `file:///home/x` as a path (percent-decoded; no remote hosts). -fn file_url_path(url: &str) -> Option { - let rest = url.strip_prefix("file://")?; +/// `file:///C:/x` or `file:///home/x` as a path (percent-decoded; no remote hosts). A path that +/// starts with two separators or holds a `\` (raw or percent-encoded), or a percent-encoded `/`, +/// is refused: on Windows such a path can name a network share, and reading it contacts that host. +fn file_url_path(url: &str) -> std::result::Result { + let bad = |why: &str| format!("bad file URL `{url}`: {why}"); + let rest = url.strip_prefix("file://").ok_or_else(|| bad("it doesn't start with file://"))?; let rest = rest.strip_prefix("localhost").unwrap_or(rest); if !rest.starts_with('/') { - return None; + return Err(bad("only local files can be read (file:///path)")); } let b = rest.as_bytes(); // `/C:/…` on Windows. - let rest = if b.len() > 2 && b.get(2) == Some(&b':') { rest.get(1..)? } else { rest }; + let rest = + if b.get(1).is_some_and(u8::is_ascii_alphabetic) && b.get(2) == Some(&b':') { rest.get(1..).ok_or_else(|| bad("bad drive letter"))? } else { rest }; let mut out = Vec::with_capacity(rest.len()); let mut bytes = rest.bytes(); while let Some(c) = bytes.next() { if c == b'%' { - let hex = [bytes.next()?, bytes.next()?]; - out.push(u8::from_str_radix(std::str::from_utf8(&hex).ok()?, 16).ok()?); + let hex = [bytes.next(), bytes.next()]; + let [Some(hi), Some(lo)] = hex else { return Err(bad("a % isn't followed by two hex digits")) }; + let byte = + std::str::from_utf8(&[hi, lo]).ok().and_then(|h| u8::from_str_radix(h, 16).ok()).ok_or_else(|| bad("a % isn't followed by two hex digits"))?; + if matches!(byte, b'/' | b'\\') { + return Err(bad("a percent-encoded / or \\ isn't allowed")); + } + out.push(byte); } else { out.push(c); } } - String::from_utf8(out).ok().map(PathBuf::from) + let path = String::from_utf8(out).map_err(|_| bad("the path isn't UTF-8"))?; + if path.contains('\\') { + return Err(bad("use / between folders, not \\")); + } + if path.starts_with("//") { + return Err(bad("network paths can't be read, only local files")); + } + Ok(PathBuf::from(path)) } /// Check `url` against the rules: `https://` on GitHub's hosts; `file://` when the catalog @@ -360,7 +451,7 @@ fn source(url: &str, catalog: Option<&str>) -> std::result::Result Result<(String, Package, Release)> { ), )); } - source(&rel.url, Some(&url)).map_err(|e| bad(c, e))?; + if let Source::Https(u) = source(&rel.url, Some(&url)).map_err(|e| bad(c, e))? + && let Some(why) = release_url_problem(&pkg.repo, &u) + { + return Err(bad(c, format!("{}: {why}", pkg.name))); + } Ok((url, pkg, rel)) } @@ -1033,7 +1128,7 @@ pub fn specs() -> Vec { "Refresh Plug-in Catalog", [], None, - "{catalog?: https:// or file:// URL of an index.json (default: the community catalog), wait?}", + "{catalog?: https:// or file:// URL of an index.json (default: the community catalog; file:// takes a local path, not a network path such as //server/share), wait?}", always, refresh ), @@ -1051,7 +1146,7 @@ pub fn specs() -> Vec { "Install Plug-in", [], None, - "{id, version?, wait?} — downloads the release, checks its SHA-256 against the catalog, loads it", + "{id, version?, wait?} — downloads the release (a GitHub release asset, in the package's repo when it names one), checks its SHA-256 against the catalog, loads it", always, install ), @@ -1135,6 +1230,99 @@ mod tests { assert!(latest_compatible(&Package::default()).is_none()); } + #[test] + fn release_urls_are_assets_of_the_declared_repository() { + let asset = "https://github.com/Me/Glow/releases/download/v1.0.0/glow.wasm"; + for repo in ["https://github.com/me/glow", "https://github.com/Me/Glow/", "https://GitHub.com/me/glow.git", ""] { + assert_eq!(release_url_problem(repo, asset), None, "{repo}"); + } + assert_eq!(release_url_problem("", "https://github.com/a/b/releases/download/tags/v1/x.wasm"), None, "a tag with a slash"); + assert!( + release_url_problem("https://github.com/me/glow", "https://github.com/me/other/releases/download/v1/x.wasm") + .unwrap() + .contains("package's repository") + ); + assert!(release_url_problem("https://github.com/me/glow", "https://github.com/you/glow/releases/download/v1/x.wasm").is_some()); + for no in [ + "https://raw.githubusercontent.com/me/glow/main/x.wasm", + "https://objects.githubusercontent.com/x.wasm", + "https://github.com/me/glow/blob/main/x.wasm", + "https://github.com/me/glow/releases/download/v1", + "https://github.com/me/glow/releases/download//x.wasm", + "https://github.com/me/glow/releases/download/v1/x.wasm?x=1", + "https://github.com/me/glow/releases/download/v1/x.wasm#x", + "https://github.com/me/glow/releases/download/../../../you/evil/releases/download/v1/x.wasm", + "https://github.com/me/glow/releases/download/%2e%2e/%2E./x/y/x.wasm", + "https://github.com/me/glow/releases/download/./v1/x.wasm", + "https://github.com/me/glow/releases/download/v1\\x.wasm", + "https://github.com/m e/glow/releases/download/v1/x.wasm", + "https://github.com/me/glow/releases/download/v 1/x.wasm", + "https://github.com/me/glow/releases/download/v1/x\t.wasm", + "https://github.com/me/glow/releases/download/v1/x.wasm\n", + "https://github.com/me/glow/releases/download/v1\u{a0}/x.wasm", + "https://github.com/me/glow/releases/download/v1/\u{85}x.wasm", + "https://github.com/me/glow/releases/download/v1/x\u{feff}.wasm", + "https://github.com/../glow/releases/download/v1/x.wasm", + "https://github.com.evil.com/me/glow/releases/download/v1/x.wasm", + ] { + assert!(release_url_problem("https://github.com/me/glow", no).is_some(), "{no}"); + assert!(release_url_problem("", no).is_some(), "{no}"); + } + assert_eq!(github_repo("https://github.com/Me/Glow.git"), Some(("me".into(), "glow".into()))); + assert_eq!(github_repo("https://github.com/Me/Glow/tree/main/plugins/glow"), Some(("me".into(), "glow".into()))); + for no in ["https://github.com/me", "https://github.com/me/glow/tree", "http://github.com/me/glow", "me/glow"] { + assert_eq!(github_repo(no), None, "{no}"); + } + } + + #[test] + fn a_repo_that_isnt_a_github_repository_url_refuses_every_release() { + let asset = "https://github.com/me/glow/releases/download/v1/glow.wasm"; + for repo in [ + "https://github.com/me/glow", + "https://github.com/me/glow/", + "https://github.com/me/glow.git", + "https://github.com/me/glow.git/", + " https://github.com/ME/glow ", + "https://github.com/me/glow/tree/main", + "https://github.com/me/glow/tree/main/plugins/glow/", + "", + " ", + ] { + assert_eq!(release_url_problem(repo, asset), None, "{repo:?}"); + } + let elsewhere = release_url_problem("https://github.com/me/glow/tree/main", "https://github.com/you/evil/releases/download/v1/glow.wasm"); + assert!(elsewhere.as_deref().is_some_and(|w| w.contains("package's repository")), "{elsewhere:?}"); + for repo in [ + "https://github.com/me/glow/tree", + "https://github.com/me/glow/tree/", + "https://github.com/me/glow/tree//x", + "https://github.com/me/glow/tree/main/../../you/evil", + "https://github.com/me/glow/tree/main/%2e%2e", + "https://github.com/me/glow/blob/main/README.md", + "https://github.com/me/glow.git/x", + "https://github.com/me/glow/releases", + "https://github.com/me/glow//", + "https://github.com/me", + "https://github.com/me/", + "http://github.com/me/glow", + "github.com/me/glow", + "me/glow", + "https://www.github.com/me/glow", + "https://gitlab.com/me/glow", + "https://github.com/me/glow?tab=readme", + "https://github.com/me/glow#readme", + "https://github.com/me/gl ow", + "https://github.com/me/glow/tree/main/my plug-in", + "https://github.com/me/glow/tree/ma\tin", + "https://github.com/me/glow/tree/main/x\u{feff}", + "https://github.com/me/..", + ] { + let why = release_url_problem(repo, asset); + assert!(why.as_deref().is_some_and(|w| w.contains("isn't a GitHub repository URL")), "{repo:?}: {why:?}"); + } + } + #[test] fn catalogs_leave_out_bad_entries() { let good = "a".repeat(64); @@ -1180,10 +1368,47 @@ mod tests { assert_eq!(source("file:///C:/p/x.wasm", None), Ok(Source::File(PathBuf::from("C:/p/x.wasm")))); assert!(source("file://", None).is_err()); // Percent-decoded; no remote hosts. - assert_eq!(file_url_path("file:///C:/My%20Plug-ins/Jos%C3%A9%23.wasm"), Some(PathBuf::from("C:/My Plug-ins/José#.wasm"))); - assert_eq!(file_url_path("file://localhost/home/x.wasm"), Some(PathBuf::from("/home/x.wasm"))); + assert_eq!(file_url_path("file:///C:/My%20Plug-ins/Jos%C3%A9%23.wasm"), Ok(PathBuf::from("C:/My Plug-ins/José#.wasm"))); + assert_eq!(file_url_path("file://localhost/home/x.wasm"), Ok(PathBuf::from("/home/x.wasm"))); for no in ["file://server/share/x.wasm", "file:///bad%2", "file:///bad%zz"] { - assert_eq!(file_url_path(no), None, "{no}"); + assert!(file_url_path(no).is_err(), "{no}"); + } + } + + #[test] + fn file_urls_cannot_name_a_network_path() { + for ok in [ + ("file:///C:/p/x.wasm", "C:/p/x.wasm"), + ("file:///c:/p/x.wasm", "c:/p/x.wasm"), + ("file:///home/me/x.wasm", "/home/me/x.wasm"), + ("file://localhost/C:/p/x.wasm", "C:/p/x.wasm"), + ("file:///home/me/a%20b/x.wasm", "/home/me/a b/x.wasm"), + ("file:///C:/p//x.wasm", "C:/p//x.wasm"), + ] { + assert_eq!(file_url_path(ok.0), Ok(PathBuf::from(ok.1)), "{}", ok.0); + } + for no in [ + // Two separators at the start: `//server/share/…`. + "file:////server/share/x.wasm", + "file://localhost//server/share/x.wasm", + "file://///server/share/x.wasm", + "file:////:x.wasm", + // Backslashes, raw or percent-encoded. + "file:///\\\\server\\share\\x.wasm", + "file:///\\server/share/x.wasm", + "file:///C:\\p\\x.wasm", + "file:///%5C%5Cserver/share/x.wasm", + "file:///%5c%5cserver/share/x.wasm", + "file:///C:/p%5Cx.wasm", + // Percent-encoded slashes. + "file:///%2F%2Fserver/share/x.wasm", + "file:///%2fserver/share/x.wasm", + "file:///C:/p%2Fx.wasm", + ] { + let e = file_url_path(no).expect_err(no); + assert!(e.starts_with("bad file URL"), "{no}: {e}"); + assert!(source(no, None).is_err(), "{no}"); + assert!(source(no, Some("file:///tmp/index.json")).is_err(), "{no}"); } } diff --git a/crates/host/tests/it/library.rs b/crates/host/tests/it/library.rs index 4cd94ecdd..35cbf74a7 100644 --- a/crates/host/tests/it/library.rs +++ b/crates/host/tests/it/library.rs @@ -156,6 +156,44 @@ fn a_wrong_checksum_or_a_bad_module_installs_nothing() { let _ = std::fs::remove_dir_all(&dir); } +#[test] +fn downloads_are_release_assets_of_the_package_repository() { + let dir = tmp("assets"); + let sum = "0".repeat(64); + let pkg = + |id: &str, repo: &str, url: &str| json!({"id": id, "name": id, "repo": repo, "versions": [{"version": "1", "api": 1, "url": url, "sha256": sum}]}); + let catalog = write_catalog( + &dir, + json!([ + pkg("org.test.other", "https://github.com/me/glow", "https://github.com/someone/else/releases/download/v1/glow.wasm"), + pkg("org.test.raw", "https://github.com/me/glow", "https://raw.githubusercontent.com/me/glow/main/glow.wasm"), + pkg("org.test.page", "", "https://github.com/me/glow/blob/main/glow.wasm"), + pkg("org.test.dots", "https://github.com/me/glow", "https://github.com/me/glow/releases/download/%2e%2e/%2E%2E/x/y/glow.wasm"), + pkg("org.test.tree", "https://github.com/me/glow/tree/main", "https://github.com/someone/else/releases/download/v1/glow.wasm"), + pkg("org.test.http", "http://github.com/me/glow", "https://github.com/me/glow/releases/download/v1/glow.wasm"), + pkg("org.test.blob", "https://github.com/me/glow/blob/main/README.md", "https://github.com/me/glow/releases/download/v1/glow.wasm"), + ]), + ); + let mut s = session(&dir); + s.execute("library.refresh", json!({"catalog": catalog, "wait": true})).unwrap(); + for (id, why) in [ + ("org.test.other", "isn't a release asset of the package's repository https://github.com/me/glow"), + ("org.test.raw", "isn't a release asset"), + ("org.test.page", "isn't a release asset"), + ("org.test.dots", "isn't a release asset"), + ("org.test.tree", "isn't a release asset of the package's repository https://github.com/me/glow/tree/main"), + ("org.test.http", "org.test.http: the package's `repo` http://github.com/me/glow isn't a GitHub repository URL"), + ("org.test.blob", "org.test.blob: the package's `repo` https://github.com/me/glow/blob/main/README.md isn't a GitHub repository URL"), + ] { + for c in ["library.install", "library.preview"] { + let e = s.execute(c, json!({"id": id, "wait": true})).unwrap_err().to_string(); + assert!(e.contains(why), "{c} {id}: {e}"); + } + } + assert!(!dir.join("Plug-ins").join("Library").join("installed.json").exists()); + let _ = std::fs::remove_dir_all(&dir); +} + #[test] fn installed_packages_load_at_start_and_changed_files_are_refused() { let dir = tmp("startup"); diff --git a/crates/media/Cargo.toml b/crates/media/Cargo.toml index 9ff04e0d5..c236cf294 100644 --- a/crates/media/Cargo.toml +++ b/crates/media/Cargo.toml @@ -24,8 +24,8 @@ filmcraft-codecs = { workspace = true } filmcraft-media = { workspace = true } craft-dpx = { workspace = true } craft-exr = { workspace = true, features = ["decode"] } -craft-gif = { workspace = true } -craft-webp = { workspace = true } +craft-gif = { workspace = true, features = ["frames"] } +craft-webp = { workspace = true, features = ["frames"] } craft-audio = { workspace = true } craft-media = { workspace = true } filmcraft-mpegts = { workspace = true } diff --git a/crates/media/src/gif_anim.rs b/crates/media/src/gif_anim.rs index 8453b50ac..dc5f55e27 100644 --- a/crates/media/src/gif_anim.rs +++ b/crates/media/src/gif_anim.rs @@ -5,11 +5,9 @@ //! delays), so uneven timing is kept exactly; [`Anim::frame_at`] looks the frame up by time. //! Animated WebP ([`crate::webp_anim`]) shares [`Anim`] and this decode path. -use std::io::Cursor; - use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; -use image::{AnimationDecoder, DynamicImage, codecs::gif::GifDecoder}; +use image::DynamicImage; use crate::{MediaError, Result}; @@ -26,6 +24,10 @@ pub(crate) const MAX_BYTES: usize = 256 << 20; /// Frames read from a GIF's or animated WebP's headers when probing. pub(crate) const MAX_FRAMES: usize = 100_000; +/// Frames kept when decoding a GIF or animated WebP: all of them. Only [`MAX_BYTES`] and the +/// canvas budget bound decoding, as before the shared frame readers; [`MAX_FRAMES`] bounds probing. +pub(crate) const DECODE_FRAMES: usize = usize::MAX; + /// Whether `f` is an animated GIF or WebP imported by [`probe`] or [`crate::webp_anim::probe`]: /// its frames come from an [`Anim`]. pub(crate) fn is_animated(f: &Footage) -> bool { @@ -86,43 +88,57 @@ impl Anim { if crate::webp_anim::is_webp(bytes) { return crate::webp_anim::load(bytes); } - let mut dec = GifDecoder::new(Cursor::new(bytes)).map_err(|e| MediaError::Decode(format!("GIF: {e}")))?; - // A frame may be far larger than the canvas, and the decoder allocates its buffer before - // decoding it: no single buffer may pass what all the frames may hold. - let mut limits = image::Limits::no_limits(); - limits.max_alloc = Some(MAX_BYTES as u64); - image::ImageDecoder::set_limits(&mut dec, limits).map_err(|e| MediaError::Decode(format!("GIF: {e}")))?; - // The decoder allocates the full logical canvas for the first frame, however small the - // frames themselves are: check it before decoding any. - let (w, h) = image::ImageDecoder::dimensions(&dec); - if u64::from(w) * u64::from(h) * 4 > MAX_BYTES as u64 { - return Err(MediaError::Unsupported(format!("GIF canvas of {w}×{h} is too large to hold in memory"))); - } - let (mut frames, mut starts) = (Vec::new(), Vec::new()); - let (mut at, mut size) = (0i64, 0usize); - for frame in dec.into_frames() { - let frame = match frame { - Ok(f) => f, - Err(e) if frames.is_empty() => return Err(MediaError::Decode(format!("GIF: {e}"))), - Err(e) => { - log::warn!("media: GIF stops after {} frames: {e}", frames.len()); - break; - } - }; - let (numer, denom) = frame.delay().numer_denom_ms(); - let cs = delay_cs(numer.checked_div(denom).unwrap_or(0) / 10); - let buf = frame.into_buffer(); - size = size.saturating_add(buf.as_raw().len()); - if size > MAX_BYTES { - return Err(MediaError::Unsupported("GIF is too large to hold in memory".into())); + // The frame reader scans every image descriptor before it checks the canvas: refuse a + // logical screen too large to hold first, as the former decoder did. + if let Some(&[w0, w1, h0, h1]) = bytes.get(6..10).filter(|_| bytes.starts_with(b"GIF8")) { + let (w, h) = (u16::from_le_bytes([w0, w1]), u16::from_le_bytes([h0, h1])); + if u64::from(w) * u64::from(h) * 4 > MAX_BYTES as u64 { + return Err(MediaError::Unsupported(format!("GIF canvas of {w}×{h} is too large to hold in memory"))); } + } + let mut limits = craft_gif::frames::FrameLimits::default(); + limits.max_frames = DECODE_FRAMES; + limits.max_bytes = MAX_BYTES as u64; + limits.max_canvas_bytes = MAX_BYTES as u64; + limits.max_decode_bytes = Some(MAX_BYTES as u64); + let decoded = craft_gif::frames::read_frames(bytes, &limits).map_err(|e| match e { + craft_gif::frames::FrameError::Malformed(m) => MediaError::Decode(format!("GIF: {m}")), + craft_gif::frames::FrameError::LimitExceeded(m) + if m.contains("cannot hold") || m.contains("decode-allocation limit") || m.to_ascii_lowercase().contains("memory limit") => + { + MediaError::Unsupported("GIF is too large to hold in memory".into()) + } + craft_gif::frames::FrameError::LimitExceeded(m) if m.contains("canvas is over") => { + MediaError::Unsupported("GIF canvas is too large to hold in memory".into()) + } + craft_gif::frames::FrameError::LimitExceeded(m) => MediaError::Unsupported(format!("GIF: {m}")), + })?; + if matches!(&decoded.stop, craft_gif::frames::Stop::ByteLimit | craft_gif::frames::Stop::FrameLimit) { + return Err(MediaError::Unsupported("GIF is too large to hold in memory".into())); + } + if let craft_gif::frames::Stop::Damaged(ref e) = decoded.stop { + log::warn!("media: GIF stops after {} frames: {e}", decoded.frames.len()); + } + let mut frames = Vec::with_capacity(decoded.frames.len()); + let mut starts = Vec::with_capacity(decoded.frames.len()); + let mut at = 0i64; + for frame in decoded.frames { + let cs = delay_cs(frame.delay_ms / 10); + let image = image::RgbaImage::from_raw(decoded.width, decoded.height, frame.rgba) + .ok_or_else(|| MediaError::Decode("GIF: invalid decoded frame dimensions".into()))?; starts.push(Tick::from_units(at, 100)); at = at.saturating_add(i64::from(cs)); - frames.push(DynamicImage::ImageRgba8(buf)); + frames.push(DynamicImage::ImageRgba8(image)); } Anim::new(frames, starts).ok_or_else(|| MediaError::Decode("GIF: no frames".into())) } + /// How many frames were decoded. + #[cfg(test)] + pub(crate) fn len(&self) -> usize { + self.frames.len() + } + /// The frame shown at source time `t` (the first one before the start, the last one past the /// end). pub(crate) fn frame_at(&self, t: Tick) -> Option<&DynamicImage> { @@ -133,9 +149,13 @@ impl Anim { #[cfg(test)] mod tests { + use std::io::Cursor; + use effectcraft_project::{Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; + use image::AnimationDecoder; + use super::MAX_FRAMES; use crate::{MediaPool, probe_bytes}; /// A 2×2 GIF with one solid-colour frame per `(rgb, delay)`. @@ -152,6 +172,15 @@ mod tests { out } + /// Preserve the old consumer path as a test oracle while the frame API is shared. + fn legacy_gif_frames(bytes: &[u8]) -> Vec { + image::codecs::gif::GifDecoder::new(Cursor::new(bytes)).unwrap().into_frames().map(|frame| frame.unwrap().into_buffer()).collect() + } + + fn legacy_gif_frames_until_error(bytes: &[u8]) -> Vec { + image::codecs::gif::GifDecoder::new(Cursor::new(bytes)).unwrap().into_frames().map_while(|frame| frame.ok()).map(|frame| frame.into_buffer()).collect() + } + const RED: [u8; 3] = [255, 0, 0]; const GREEN: [u8; 3] = [0, 255, 0]; const BLUE: [u8; 3] = [0, 0, 255]; @@ -201,6 +230,62 @@ mod tests { assert_eq!(f.duration, Tick::from_units(20, 100)); } + #[test] + fn shared_gif_frames_match_legacy_compositing_and_disposal() { + let mut bytes = Vec::new(); + { + let palette = [255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0]; + let mut enc = gif::Encoder::new(&mut bytes, 3, 2, &palette).unwrap(); + let first = gif::Frame { + width: 3, + height: 2, + buffer: vec![0; 6].into(), // red background + delay: 5, + dispose: gif::DisposalMethod::Keep, + ..gif::Frame::default() + }; + enc.write_frame(&first).unwrap(); + + let second = gif::Frame { + left: 1, + width: 1, + height: 1, + buffer: vec![1].into(), // green patch + delay: 7, + dispose: gif::DisposalMethod::Background, + ..gif::Frame::default() + }; + enc.write_frame(&second).unwrap(); + + let third = gif::Frame { + left: 2, + width: 1, + height: 1, + buffer: vec![2].into(), // blue patch after disposal + delay: 9, + dispose: gif::DisposalMethod::Previous, + ..gif::Frame::default() + }; + enc.write_frame(&third).unwrap(); + + let fourth = gif::Frame { + width: 1, + height: 1, + buffer: vec![3].into(), // black patch after restoring the previous canvas + delay: 11, + ..gif::Frame::default() + }; + enc.write_frame(&fourth).unwrap(); + } + let expected = legacy_gif_frames(&bytes); + let actual = super::Anim::load(&bytes).unwrap(); + assert_eq!(actual.frames.len(), expected.len()); + for (frame, old) in actual.frames.iter().zip(expected) { + assert_eq!(frame.to_rgba8(), old); + } + assert_eq!(actual.starts, vec![Tick::from_units(0, 100), Tick::from_units(5, 100), Tick::from_units(12, 100), Tick::from_units(21, 100)]); + } + #[test] fn a_single_frame_gif_stays_a_still() { let f = probe_bytes("a.gif", gif(&[(RED, 10)]).into()).unwrap(); @@ -228,6 +313,20 @@ mod tests { let _ = probe_bytes("a.gif", bytes.into()); } + #[test] + fn a_damaged_gif_tail_keeps_frames_already_decoded() { + let mut bytes = gif(&[(RED, 5), (GREEN, 5), (BLUE, 5)]); + let info = craft_gif::scan(&bytes, MAX_FRAMES).unwrap(); + assert_eq!(info.frames.len(), 3); + bytes.truncate(info.frames[1].offset); + + let legacy = legacy_gif_frames_until_error(&bytes); + assert_eq!(legacy.len(), 1); + let actual = super::Anim::load(&bytes).unwrap(); + assert_eq!(actual.frames.len(), legacy.len()); + assert_eq!(actual.frames[0].to_rgba8(), legacy[0]); + } + #[test] fn a_huge_canvas_is_refused_before_decoding() { // A 65535×65535 logical screen (16 GiB of RGBA) holding one 1×1 frame. @@ -239,6 +338,28 @@ mod tests { } } let e = super::Anim::load(&out).err().unwrap(); - assert!(e.to_string().contains("too large"), "{e}"); + assert!(e.to_string().contains("GIF canvas of 65535×65535 is too large"), "{e}"); + } + + /// A 1×1 GIF of `n` frames. + fn tiny_gif(n: usize) -> Vec { + let mut out = Vec::new(); + { + let mut enc = gif::Encoder::new(&mut out, 1, 1, &[]).unwrap(); + let frame = gif::Frame::from_rgb(1, 1, &RED); + for _ in 0..n { + enc.write_frame(&frame).unwrap(); + } + } + out + } + + #[test] + fn decoding_keeps_every_frame_past_the_probe_frame_count() { + // 1×1 frames fit the byte budget however many there are: the frame count refuses none. + for n in [MAX_FRAMES, MAX_FRAMES + 1] { + let anim = super::Anim::load(&tiny_gif(n)).unwrap(); + assert_eq!(anim.len(), n); + } } } diff --git a/crates/media/src/webp_anim.rs b/crates/media/src/webp_anim.rs index 147fe8264..bb2fdcc69 100644 --- a/crates/media/src/webp_anim.rs +++ b/crates/media/src/webp_anim.rs @@ -9,13 +9,11 @@ //! every delay is a whole number of frames at (1000 / the greatest common divisor of the delays), //! so it is kept exactly. A still WebP (no animation flag, or a single frame) stays a still. -use std::io::Cursor; - use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; -use image::{AnimationDecoder, DynamicImage, codecs::webp::WebPDecoder}; +use image::DynamicImage; -use crate::gif_anim::{Anim, MAX_BYTES, MAX_FRAMES, gcd}; +use crate::gif_anim::{Anim, DECODE_FRAMES, MAX_BYTES, MAX_FRAMES, gcd}; use crate::{MediaError, Result}; /// The `Footage::codec` of an animated WebP. @@ -121,29 +119,29 @@ pub(crate) fn load(bytes: &[u8]) -> Result { if frame_bytes.saturating_mul(h.delays.len()) > MAX_BYTES { return Err(MediaError::Unsupported(format!("animated WebP of {} frames of {}×{} is too large to hold in memory", h.delays.len(), h.width, h.height))); } - let dec = WebPDecoder::new(Cursor::new(bytes)).map_err(|e| MediaError::Decode(format!("WebP: {e}")))?; - // The budget above used the canvas this file's header scan found; the decoder must agree, or - // a second VP8X header could make it allocate a far larger canvas. - if image::ImageDecoder::dimensions(&dec) != (h.width, h.height) { + let mut limits = craft_webp::frames::FrameLimits::default(); + limits.max_frames = DECODE_FRAMES; + limits.max_bytes = MAX_BYTES as u64; + limits.max_canvas_bytes = MAX_BYTES as u64; + let decoded = craft_webp::frames::read_frames(bytes, &limits).map_err(|e| match e { + craft_webp::frames::FrameError::Malformed(m) => MediaError::Decode(format!("WebP: {m}")), + craft_webp::frames::FrameError::LimitExceeded(m) => MediaError::Unsupported(format!("WebP: {m}")), + })?; + if matches!(&decoded.stop, craft_webp::frames::Stop::ByteLimit | craft_webp::frames::Stop::FrameLimit) { + return Err(MediaError::Unsupported("animated WebP is too large to hold in memory".into())); + } + if let craft_webp::frames::Stop::Damaged(ref e) = decoded.stop { + log::warn!("media: WebP stops after {} frames: {e}", decoded.frames.len()); + } + if (decoded.width, decoded.height) != (h.width, h.height) { return Err(MediaError::Decode("WebP: conflicting canvas sizes".into())); } - let (mut frames, mut delays, mut size) = (Vec::new(), Vec::new(), 0usize); - for frame in dec.into_frames() { - let frame = match frame { - Ok(f) => f, - Err(e) if frames.is_empty() => return Err(MediaError::Decode(format!("WebP: {e}"))), - Err(e) => { - log::warn!("media: WebP stops after {} frames: {e}", frames.len()); - break; - } - }; - let (numer, denom) = frame.delay().numer_denom_ms(); - delays.push(numer.checked_div(denom).unwrap_or(0)); - let buf = frame.into_buffer(); - size = size.saturating_add(buf.as_raw().len()); - if size > MAX_BYTES { - return Err(MediaError::Unsupported("animated WebP is too large to hold in memory".into())); - } + let mut frames = Vec::with_capacity(decoded.frames.len()); + let mut delays = Vec::with_capacity(decoded.frames.len()); + for frame in decoded.frames { + delays.push(frame.delay_ms); + let buf = image::RgbaImage::from_raw(decoded.width, decoded.height, frame.rgba) + .ok_or_else(|| MediaError::Decode("WebP: invalid decoded frame dimensions".into()))?; frames.push(DynamicImage::ImageRgba8(buf)); } let starts = timing(&delays).starts; @@ -152,9 +150,11 @@ pub(crate) fn load(bytes: &[u8]) -> Result { #[cfg(test)] mod tests { + use std::io::Cursor; + use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; - use image::{ExtendedColorType, ImageEncoder, codecs::webp::WebPEncoder}; + use image::{AnimationDecoder, ExtendedColorType, ImageEncoder, codecs::webp::WebPDecoder, codecs::webp::WebPEncoder}; use super::timing; use crate::{MediaPool, probe_bytes}; @@ -204,6 +204,43 @@ mod tests { chunk(b"RIFF", &body) } + /// Build an animation whose frames may cover only part of the canvas. `x` and `y` are even, + /// as required by ANMF; bit 1 of `flags` selects no-blend and bit 0 selects disposal. + fn webp_subframes(canvas: (u32, u32), frames: &[(u32, u32, u32, u32, [u8; 4], u32, u8)]) -> Vec { + let (w, h) = canvas; + let mut vp8x = vec![0x12, 0, 0, 0]; + vp8x.extend_from_slice(&u24(w - 1)); + vp8x.extend_from_slice(&u24(h - 1)); + let mut body = b"WEBP".to_vec(); + body.extend(chunk(b"VP8X", &vp8x)); + body.extend(chunk(b"ANIM", &[0; 6])); + for &(x, y, fw, fh, rgba, delay, flags) in frames { + let mut anmf = Vec::new(); + anmf.extend_from_slice(&u24(x / 2)); + anmf.extend_from_slice(&u24(y / 2)); + anmf.extend_from_slice(&u24(fw - 1)); + anmf.extend_from_slice(&u24(fh - 1)); + anmf.extend_from_slice(&u24(delay)); + anmf.push(flags); + anmf.extend(vp8l(fw, fh, rgba)); + body.extend(chunk(b"ANMF", &anmf)); + } + chunk(b"RIFF", &body) + } + + fn anmf_offsets(bytes: &[u8]) -> Vec { + let mut offsets = Vec::new(); + let mut at = 12usize; + while at + 8 <= bytes.len() { + let size = u32::from_le_bytes(bytes[at + 4..at + 8].try_into().unwrap()) as usize; + if &bytes[at..at + 4] == b"ANMF" { + offsets.push(at); + } + at = at.saturating_add(8).saturating_add(size).saturating_add(size & 1); + } + offsets + } + const RED: [u8; 4] = [255, 0, 0, 255]; const GREEN: [u8; 4] = [0, 255, 0, 255]; const BLUE: [u8; 4] = [0, 0, 255, 128]; @@ -238,6 +275,38 @@ mod tests { assert_eq!(pixel_at(&pool, &f, 5.0), last); } + #[test] + fn shared_webp_frames_match_legacy_subrect_blending_and_disposal() { + // Includes a blended alpha patch, then a no-blend patch disposed to the background. + let bytes = + webp_subframes((4, 2), &[(0, 0, 4, 2, RED, 50, 0b10), (2, 0, 2, 2, BLUE, 60, 0b00), (0, 0, 2, 2, GREEN, 70, 0b11), (2, 0, 2, 2, RED, 80, 0b10)]); + let expected = WebPDecoder::new(Cursor::new(&bytes)).unwrap().into_frames().map(|frame| frame.unwrap().into_buffer()).collect::>(); + let actual = super::load(&bytes).unwrap(); + assert_eq!(expected.len(), 4); + for (index, (start_ms, old)) in [(0, &expected[0]), (50, &expected[1]), (110, &expected[2]), (180, &expected[3])].into_iter().enumerate() { + let tick = Tick::from_units(start_ms, 1000); + let frame = actual.frame_at(tick).unwrap().to_rgba8(); + assert_eq!(frame, *old, "frame {index} at {start_ms} ms"); + } + } + + #[test] + fn a_damaged_webp_tail_keeps_frames_already_decoded() { + let mut bytes = webp(4, 2, &[(RED, 50), (GREEN, 60), (BLUE, 70)]); + let offsets = anmf_offsets(&bytes); + assert_eq!(offsets.len(), 3); + bytes.truncate(offsets[2]); + + let legacy = + WebPDecoder::new(Cursor::new(&bytes)).unwrap().into_frames().map_while(|frame| frame.ok()).map(|frame| frame.into_buffer()).collect::>(); + assert_eq!(legacy.len(), 2); + let actual = super::load(&bytes).unwrap(); + for (index, old) in legacy.iter().enumerate() { + let tick = Tick::from_units(if index == 0 { 0 } else { 50 }, 1000); + assert_eq!(actual.frame_at(tick).unwrap().to_rgba8(), *old); + } + } + #[test] fn delays_rounded_to_milliseconds_read_as_the_standard_rate() { // 24 frames a second rounded to whole milliseconds, as ffmpeg writes them. @@ -312,4 +381,34 @@ mod tests { bytes[4..8].copy_from_slice(&riff.to_le_bytes()); assert!(super::load(&bytes).is_err()); } + + /// A 1×1 animated WebP of `n` identical frames. + fn tiny_webp(n: usize) -> Vec { + let mut anmf = vec![0; 6]; + anmf.extend_from_slice(&u24(0)); + anmf.extend_from_slice(&u24(0)); + anmf.extend_from_slice(&u24(50)); + anmf.push(0b10); + anmf.extend(vp8l(1, 1, RED)); + let frame = chunk(b"ANMF", &anmf); + let mut vp8x = vec![0x12, 0, 0, 0]; + vp8x.extend_from_slice(&u24(0)); + vp8x.extend_from_slice(&u24(0)); + let mut body = b"WEBP".to_vec(); + body.extend(chunk(b"VP8X", &vp8x)); + body.extend(chunk(b"ANIM", &[0; 6])); + for _ in 0..n { + body.extend_from_slice(&frame); + } + chunk(b"RIFF", &body) + } + + #[test] + fn decoding_keeps_every_frame_past_the_probe_frame_count() { + // 1×1 frames fit the byte budget however many there are: the frame count refuses none. + for n in [crate::gif_anim::MAX_FRAMES, crate::gif_anim::MAX_FRAMES + 1] { + let anim = super::load(&tiny_webp(n)).unwrap(); + assert_eq!(anim.len(), n); + } + } } diff --git a/crates/text/src/fonts/tests.rs b/crates/text/src/fonts/tests.rs index 2e04e5f0e..ba1e33b25 100644 --- a/crates/text/src/fonts/tests.rs +++ b/crates/text/src/fonts/tests.rs @@ -459,7 +459,9 @@ fn microsoft_families_resolve_to_metric_compatible_substitutes() { let resolved = resolve(requested, style); let family = &face(resolved.face).info.family; - if family.eq_ignore_ascii_case(requested) { + let installed = all_faces().iter().any(|f| f.info.family.eq_ignore_ascii_case(requested)); + if installed { + assert!(family.eq_ignore_ascii_case(requested), "an installed {requested} wins over {family}"); assert!(!resolved.missing, "an installed original family is available"); } else { assert_eq!(family, substitute); @@ -471,6 +473,24 @@ fn microsoft_families_resolve_to_metric_compatible_substitutes() { assert!(unknown.missing); } +/// An installed Microsoft family is used as is and not reported missing, even when its +/// substitute is also available (#1677). It runs in a child process so the Calibri fixture does +/// not reach the substitute test above. +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn an_installed_microsoft_family_wins_over_its_substitute() { + const CHILD: &str = "EFFECTCRAFT_TEST_ISOLATED_CALIBRI"; + if std::env::var_os(CHILD).is_none() { + run_in_child(CHILD, "fonts::tests::an_installed_microsoft_family_wins_over_its_substitute"); + return; + } + add_font_data(test_font("Carlito")); + add_font_data(test_font("Calibri")); + let resolved = resolve("Calibri", "Regular"); + assert_eq!(face(resolved.face).info.family, "Calibri"); + assert!(!resolved.missing, "the installed family is available"); +} + #[test] fn the_han_order_follows_the_cjk_locale() { // Chinese first for any Chinese tag, whether or not it names a script. diff --git a/crates/ui-egui/src/lifecycle_tests.rs b/crates/ui-egui/src/lifecycle_tests.rs index 6c9eb85d2..5b97b1961 100644 --- a/crates/ui-egui/src/lifecycle_tests.rs +++ b/crates/ui-egui/src/lifecycle_tests.rs @@ -224,6 +224,60 @@ fn workspace_layout_autosave_writes_on_a_hidden_tick() { assert_eq!(app.ui_passes(), 0); } +/// Whether a frame running `f` asked the root window to close. +#[cfg(not(target_arch = "wasm32"))] +fn asks_to_close(ctx: &egui::Context, mut f: impl FnMut(&egui::Context)) -> bool { + let mut out = ctx.run_ui(raw(egui::vec2(800.0, 480.0)), |ui| f(ui.ctx())); + out.textures_delta.clear(); + out.viewport_output.get(&egui::ViewportId::ROOT).is_some_and(|v| v.commands.contains(&egui::ViewportCommand::Close)) +} + +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn restart_to_update_with_unsaved_changes_opens_the_unsaved_changes_prompt() { + let ctx = egui::Context::default(); + let frame = eframe::Frame::_new_kittest(); + let mut app = app_with_comp(); + assert!(app.session.is_dirty(), "creating a comp and a layer leaves unsaved changes"); + app.updates_rt.manual_window_open = true; + assert!(asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, false)), "the window is asked to close"); + assert!(!app.updates_rt.manual_window_open, "the modal result dialog closes"); + let mut raw = raw(egui::vec2(800.0, 480.0)); + raw.viewports.insert(egui::ViewportId::ROOT, egui::ViewportInfo { events: vec![egui::ViewportEvent::Close], ..Default::default() }); + let out = tick_with(&mut app, &ctx, &frame, &raw); + assert!(app.dialog.is_some(), "the close opens the unsaved-changes prompt"); + assert!(out.viewport_commands.values().flatten().any(|c| matches!(c, egui::ViewportCommand::CancelClose))); +} + +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn restart_to_update_with_nothing_unsaved_leaves_the_close_to_the_updater() { + let ctx = egui::Context::default(); + let mut app = app_with_comp(); + app.updates_rt.manual_window_open = true; + assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, true))); + assert!(app.updates_rt.manual_window_open, "the result dialog stays until the updater closes the app"); +} + +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn restart_to_update_with_the_startup_prompt_open_leaves_the_window_open() { + let ctx = egui::Context::default(); + let mut app = app_with_comp(); + app.updates_rt.updater.offer(craft_update::Release { + tag: "v99.0.0".into(), + version: craft_update::parse_version("99.0.0"), + name: "EffectCraft 99.0.0".into(), + html_url: "https://github.com/storytold/effectcraft/releases/tag/v99.0.0".into(), + ..Default::default() + }); + assert!(app.updates_rt.updater.prompt_open()); + app.updates_rt.manual_window_open = true; + assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, false)), "the prompt carries the restart"); + assert!(!app.updates_rt.manual_window_open, "the result dialog closes"); + assert!(app.updates_rt.updater.prompt_open(), "the prompt stays"); +} + #[test] fn the_close_guard_answers_a_close_request_without_a_pass() { let ctx = egui::Context::default(); @@ -239,6 +293,29 @@ fn the_close_guard_answers_a_close_request_without_a_pass() { assert_eq!(app.ui_passes(), 0); } +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn the_update_result_dialog_shows_every_status_but_idle() { + use craft_update::updater::Status; + let shown = [ + Status::Checking, + Status::UpToDate, + Status::Failed("offline".into()), + Status::Installing, + Status::Ready, + Status::Managed, + Status::Updated("1.2.3".into()), + Status::InstallFailed("access denied".into()), + ]; + for status in &shown { + assert!(updates_ui::result_window_open(false, status, false), "{status:?} opens the dialog without a requested check"); + } + assert!(!updates_ui::result_window_open(false, &Status::Idle, false)); + assert!(!updates_ui::result_window_open(true, &Status::Idle, false), "a check that found a release closes it"); + assert!(updates_ui::result_window_open(true, &Status::Idle, true), "a queued check keeps it open"); + assert!(!updates_ui::result_window_open(false, &Status::Idle, true), "a queued check does not open it"); +} + // ---------------------------------------------------------------- screenshots fn screenshot_request(app: &mut EffectcraftApp, ctx: &egui::Context, path: Option<&str>, target: ShotTarget) -> std::sync::mpsc::Receiver { diff --git a/crates/ui-egui/src/panels/effect_controls/rows.rs b/crates/ui-egui/src/panels/effect_controls/rows.rs index b21021bb3..56cb32ff5 100644 --- a/crates/ui-egui/src/panels/effect_controls/rows.rs +++ b/crates/ui-egui/src/panels/effect_controls/rows.rs @@ -128,6 +128,18 @@ impl PropCx<'_> { } } +/// Shows property `uid` of layer `layer` in the Timeline: its layer and groups twirled open, the +/// property scrolled to and the Timeline brought forward (After Effects' Reveal in Timeline, +/// which a double-click on the property's name does; #1497). +fn reveal_in_timeline(app: &mut EffectcraftApp, ctx: &egui::Context, layer: u64, uid: u64) { + app.ui.timeline.search.clear(); + app.ui.timeline.scroll_to = Some(crate::state::ScrollTo::Property(uid)); + if let Err(e) = crate::menus::frontend(app, ctx, "timeline.revealProps", json!({"props": [{"layer": layer, "prop": uid}]})) { + app.ui.status = e; + } + app.show_panel(crate::dock::PanelKind::Timeline); +} + /// One property row: stopwatch, name, value control (and the keyframe navigator). Returns the /// value fields of a vector, one per dimension, for the pick whip. #[allow(clippy::too_many_arguments)] @@ -167,7 +179,16 @@ fn prop_row( }, ); app.auto.add(&format!("effectControls.prop.{uid}.stopwatch"), swr, &prop.name); - if resp.clicked() { + if resp.clicked() && ui.input(|i| i.modifiers.alt) { + // Alt+click adds an expression (or removes it), as in the Timeline. Effect Controls + // has no expression field: the property shows in the Timeline with its new + // expression's editor taking the keyboard, as After Effects does (#1460). + actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid}))); + if prop.expr.is_none() { + reveal_in_timeline(app, ui.ctx(), layer.id.0, uid); + } + crate::panels::timeline::expression_toggled(app, ui.ctx(), prop); + } else if resp.clicked() { actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid, "selected": true}))); } } @@ -201,12 +222,7 @@ fn prop_row( p.with_clip_rect(name_clip.intersect(p.clip_rect())).text(pos2(swr.max.x + 6.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(12.0), t.text); let name_response = ui.interact(name_clip, egui::Id::unique(("ec-prop-name", uid)), Sense::click()); if name_response.double_clicked() { - app.ui.timeline.search.clear(); - app.ui.timeline.scroll_to = Some(crate::state::ScrollTo::Property(uid)); - if let Err(e) = crate::menus::frontend(app, ui.ctx(), "timeline.revealProps", json!({"props": [{"layer": layer.id.0, "prop": uid}]})) { - app.ui.status = e; - } - app.show_panel(crate::dock::PanelKind::Timeline); + reveal_in_timeline(app, ui.ctx(), layer.id.0, uid); } app.auto.add(&format!("effectControls.prop.{uid}.name"), name_clip, &prop.name); // With several layers selected the edit applies to the same effect property of each (#491). diff --git a/crates/ui-egui/src/panels/fx_widgets.rs b/crates/ui-egui/src/panels/fx_widgets.rs index c39009fd3..20db3f98f 100644 --- a/crates/ui-egui/src/panels/fx_widgets.rs +++ b/crates/ui-egui/src/panels/fx_widgets.rs @@ -42,15 +42,15 @@ pub fn parse_angle(s: &str) -> Option { s.parse().ok() } -/// The angle after the degrees field of `v` (which shows `shown`, the remainder's size) went to +/// The angle after the degrees field of `v` (which shows `shown`, the signed remainder) went to /// `new`. A drag moves the angle by the pointer's distance, so it runs through zero into negative -/// angles; a typed number is a size, so the remainder keeps its sign. +/// angles; a typed number is the new remainder, its sign included (#3367). fn degrees_edit(v: f64, shown: f64, new: f64, dragging: bool) -> f64 { if dragging { return v + (new - shown); } - let (rev, deg) = split_angle(v); - rev as f64 * 360.0 + if deg < 0.0 || (deg == 0.0 && v < 0.0) { -new } else { new } + let (rev, _) = split_angle(v); + rev as f64 * 360.0 + new } /// An angle value, `0x+45.0°`, at `at` (top left): the revolutions and the degrees @@ -67,21 +67,16 @@ pub fn angle_field(ui: &mut egui::Ui, at: Pos2, id: egui::Id, v: f64, decimals: pub fn angle_field_step(ui: &mut egui::Ui, at: Pos2, id: egui::Id, v: f64, decimals: usize, t: &Tokens) -> (Rect, Rect, Option, Option) { let (rev, deg) = split_angle(v); let (rr, new_rev, _) = widgets::hot_int_at(ui, at, id.with("rev"), rev, 0.1, "x", t); - let sign = ui.painter().text(pos2(rr.max.x - 2.0, rr.center().y), Align2::LEFT_CENTER, if deg < 0.0 { "-" } else { "+" }, Tokens::ui(12.0), t.hot_text); - let (dr, new_deg, _, step) = widgets::hot_number_step_at( - ui, - pos2(sign.max.x - 2.0, at.y), - id, - deg.abs(), - &widgets::HotSpec { speed: 0.5, range: (-1e9, 1e9), decimals, suffix: "°" }, - t, - ); + // A negative remainder's minus sign is part of the degrees' text, so typing replaces it (#3367). + let sign = ui.painter().text(pos2(rr.max.x - 2.0, rr.center().y), Align2::LEFT_CENTER, if deg < 0.0 { "" } else { "+" }, Tokens::ui(12.0), t.hot_text); + let (dr, new_deg, _, step) = + widgets::hot_number_step_at(ui, pos2(sign.max.x - 2.0, at.y), id, deg, &widgets::HotSpec { speed: 0.5, range: (-1e9, 1e9), decimals, suffix: "°" }, t); let dragging = new_deg.is_some() && ui.ctx().is_being_dragged(id); let out = match (new_rev, new_deg, step) { (Some(r), _, _) => Some(r as f64 * 360.0 + deg), - // (The field shows the remainder's size; the step goes from the signed remainder.) + // A typed step goes from the signed remainder the field shows. (None, Some(_), Some(s)) => s.apply(deg).map(|d| rev as f64 * 360.0 + d), - (None, Some(d), None) => Some(degrees_edit(v, deg.abs(), d, dragging)), + (None, Some(d), None) => Some(degrees_edit(v, deg, d, dragging)), (None, None, _) => None, }; let step = step.filter(|s| matches!(s, Step::Add(_)) && new_rev.is_none() && out.is_some()); @@ -642,18 +637,19 @@ mod tests { #[test] fn dragging_degrees_crosses_zero_into_negative_angles() { - // The field shows the size (0.3), so a 1-degree drag left lands on -0.7, and keeps going. + // A 1-degree drag left from 0.3 lands on -0.7, and keeps going. let mut v = 0.3; for _ in 0..3 { let (_, deg) = split_angle(v); - v = degrees_edit(v, deg.abs(), deg.abs() - 1.0, true); + v = degrees_edit(v, deg, deg - 1.0, true); } assert!((v + 2.7).abs() < 1e-9, "{v}"); // And back up through zero. let (_, deg) = split_angle(v); - assert!((degrees_edit(v, deg.abs(), deg.abs() + 3.0, true) - 0.3).abs() < 1e-9); - // Typing keeps the sign shown. - assert_eq!(degrees_edit(-30.0, 30.0, 45.0, false), -45.0); + assert!((degrees_edit(v, deg, deg + 3.0, true) - 0.3).abs() < 1e-9); + // A typed number is the remainder with its sign; the revolutions stay (#3367). + assert_eq!(degrees_edit(-30.0, -30.0, 45.0, false), 45.0); + assert_eq!(degrees_edit(-30.0, -30.0, -45.0, false), -45.0); assert_eq!(degrees_edit(405.0, 45.0, 10.0, false), 370.0); } diff --git a/crates/ui-egui/src/panels/graph.rs b/crates/ui-egui/src/panels/graph.rs index 3b883d191..4a25295dd 100644 --- a/crates/ui-egui/src/panels/graph.rs +++ b/crates/ui-egui/src/panels/graph.rs @@ -208,6 +208,94 @@ fn speed_at(pr: &Property, spatial: bool, d: usize, lt: Tick) -> f64 { } } +/// How far either side of the key after a Hold key the step is sampled (seconds; far below a +/// pixel, far above the tick a stretched layer's time conversion can be off by). +const HOLD_EDGE: f64 = 1e-6; + +/// How many key samples one grid step of [`sample_times`] keeps as they are (a key and both +/// sides of a Hold step fit); past that only its earliest and latest are kept. +const BUCKET_KEEP: usize = 4; + +/// The key samples falling in one grid step of [`sample_times`]. +#[derive(Clone)] +struct Bucket { + few: Vec, + first: f64, + last: f64, + /// More than [`BUCKET_KEEP`] samples fell here. + full: bool, +} + +impl Default for Bucket { + fn default() -> Self { + Bucket { few: Vec::new(), first: f64::INFINITY, last: f64::NEG_INFINITY, full: false } + } +} + +impl Bucket { + fn add(&mut self, t: f64) { + self.first = self.first.min(t); + self.last = self.last.max(t); + if self.full { + return; + } + if self.few.len() < BUCKET_KEEP { + self.few.push(t); + } else { + self.full = true; + self.few = Vec::new(); + } + } +} + +/// The comp times (seconds) a curve is sampled at between `t0` and `t1`: `n` evenly spaced +/// times, plus every key time `keys` puts inside the span, and around the key after a key that +/// holds (its out side is Hold) the instants just before and after it. `keys` are the active +/// keys in key order, as (comp seconds, holds); on a reversed layer their comp times descend. +/// Without the key times the polyline only passes near the keys: keys closer together than a +/// sample step (a one-frame jump zoomed out) got cut across, missing their squares, and a Hold +/// step was drawn as a slope across one step instead of a vertical edge (#2720). With no keys +/// this is the plain even grid. Keys denser than the grid (baked keys zoomed out) add nothing +/// visible and would multiply the evaluations: in a grid step with more than [`BUCKET_KEEP`] +/// key samples only the earliest and latest are kept, so a curve has at most `5 * n` samples +/// and sparse keys elsewhere in view keep every sample. +fn sample_times(t0: f64, t1: f64, n: usize, keys: &[(f64, bool)]) -> Vec { + let n = n.max(2); + let mut ts: Vec = (0..n).map(|i| t0 + (t1 - t0) * i as f64 / (n - 1) as f64).collect(); + let (lo, hi) = (t0.min(t1), t0.max(t1)); + let inside = |t: f64| t > lo && t < hi; + // One bucket per grid step. + let steps = n - 1; + let mut buckets = vec![Bucket::default(); steps]; + let mut add = |t: f64| { + if !inside(t) { + return; + } + let b = (((t - lo) / (hi - lo) * steps as f64) as usize).min(steps - 1); + if let Some(bucket) = buckets.get_mut(b) { + bucket.add(t); + } + }; + for (i, &(kt, holds)) in keys.iter().enumerate() { + add(kt); + if holds && let Some(&(next, _)) = keys.get(i + 1) { + add(next - HOLD_EDGE); + add(next + HOLD_EDGE); + } + } + for b in &buckets { + if b.full { + ts.extend([b.first, b.last]); + } else { + ts.extend_from_slice(&b.few); + } + } + ts.retain(|t| t.is_finite()); + ts.sort_by(f64::total_cmp); + ts.dedup(); + ts +} + /// Build the curves for the visible time span. fn curves<'a>(app: &EffectcraftApp, comp: &'a Comp, ectx: &EvalCtx, tm: TMap, plot: Rect, speed: bool, pal: &GraphPalette) -> Vec> { let sel = &app.session.state.selected_keys; @@ -218,12 +306,14 @@ fn curves<'a>(app: &EffectcraftApp, comp: &'a Comp, ectx: &EvalCtx, tm: TMap, pl let Some(pr) = l.props.find(uid) else { continue }; let spatial = pr.spatial && matches!(pr.value, Value::Vec2(_) | Value::Vec3(_)); let dims = if speed && spatial { 1 } else { shown_dims(l, pr) }; + // The active keys (muted ones are skipped by evaluation) in comp seconds, and whether each + // holds its value up to the next one. + let active: Vec<(f64, bool)> = pr.keys.iter().filter(|k| !k.muted).map(|k| (l.comp_time(k.time).seconds(), k.out_interp == Interp::Hold)).collect(); + let times = sample_times(tm.t(plot.min.x), tm.t(plot.max.x), n, &active); for d in 0..dims { let color = if dims > 1 { pal.dims[d % pal.dims.len()] } else { pal.props[pi % pal.props.len()] }; - let mut pts = Vec::with_capacity(n); - for i in 0..n { - let x = plot.min.x + plot.width() * i as f32 / (n - 1) as f32; - let ct = tm.t(x); + let mut pts = Vec::with_capacity(times.len()); + for &ct in × { let tt = Tick::from_seconds_f64(ct); let v = if speed { speed_at(pr, spatial, d, l.layer_time(tt)) } else { ectx.at(tt).value(l, pr).components().get(d).copied().unwrap_or(0.0) }; pts.push((ct, v)); @@ -1044,7 +1134,108 @@ mod theme_tests { #[cfg(test)] mod tests { - use super::shift_axes; + use super::{HOLD_EDGE, sample_times, shift_axes}; + use effectcraft_engine::keyframe::{Keyframe, Value, evaluate}; + use effectcraft_engine::time::Tick; + + /// The value-graph polyline of `keys` (layer time = comp time) sampled at `times`. + fn polyline(keys: &[Keyframe], times: &[f64]) -> Vec<(f64, f64)> { + times + .iter() + .map(|&t| { + let v = evaluate(keys, Tick::from_seconds_f64(t), false).map(|v| v.components().first().copied().unwrap_or(f64::NAN)).unwrap_or(f64::NAN); + (t, v) + }) + .collect() + } + + fn active(keys: &[Keyframe]) -> Vec<(f64, bool)> { + keys.iter().map(|k| (k.time.seconds(), k.out_interp == effectcraft_engine::keyframe::Interp::Hold)).collect() + } + + /// #2720: a step one frame wide, zoomed out so it is narrower than a sample step. The curve + /// has to pass through every key square: the old even grid (`sample_times` with no keys) + /// never sampled 0.2 s or 0.2 s + 1 frame and drew a slope from 0 to 1 across the step. + #[test] + fn value_graph_passes_through_keys_narrower_than_a_sample_step() { + let keys = [ + Keyframe::new(Tick::from_seconds_f64(0.0), Value::Scalar(0.0)), + Keyframe::new(Tick::from_seconds_f64(0.2), Value::Scalar(0.0)), + Keyframe::new(Tick::from_seconds_f64(0.2 + 1.0 / 30.0), Value::Scalar(1.0)), + Keyframe::new(Tick::from_seconds_f64(0.9), Value::Scalar(1.0)), + ]; + let times = sample_times(0.0, 1.0, 4, &active(&keys)); + let pts = polyline(&keys, ×); + for k in &keys { + let (t, v) = (k.time.seconds(), k.value.components()[0]); + assert!(pts.iter().any(|p| p.0 == t && (p.1 - v).abs() < 1e-12), "no curve point on the key at {t} s ({v}): {pts:?}"); + } + // The spans between equal keys are flat: no sample between 0 and 0.2 s leaves 0, none + // between 0.2 s + 1 frame and 0.9 s leaves 1. + for &(t, v) in &pts { + if t <= 0.2 { + assert!(v.abs() < 1e-12, "{t} s: {v}"); + } else if (0.2 + 1.0 / 30.0..=0.9).contains(&t) { + assert!((v - 1.0).abs() < 1e-12, "{t} s: {v}"); + } + } + // Times are sorted and unique, the even grid is still there. + assert!(times.windows(2).all(|w| w[0] < w[1]), "{times:?}"); + assert!([0.0, 1.0 / 3.0, 2.0 / 3.0, 1.0].iter().all(|g| times.iter().any(|t| (t - g).abs() < 1e-12)), "{times:?}"); + } + + /// #2720: a Hold key draws a vertical step at the next key, not a slope across a sample step. + #[test] + fn hold_step_is_vertical() { + let keys = [Keyframe::new(Tick::from_seconds_f64(0.1), Value::Scalar(0.0)).hold(), Keyframe::new(Tick::from_seconds_f64(0.5), Value::Scalar(1.0))]; + let pts = polyline(&keys, &sample_times(0.0, 1.0, 4, &active(&keys))); + let at = pts.iter().position(|p| p.0 == 0.5).unwrap_or_else(|| panic!("no sample on the key at 0.5 s: {pts:?}")); + let before = pts[at - 1]; + assert!((0.5 - before.0 - HOLD_EDGE).abs() < 1e-12 && before.1.abs() < 1e-12, "the held value ends right before the next key: {pts:?}"); + assert!((pts[at].1 - 1.0).abs() < 1e-12, "{pts:?}"); + } + + #[test] + fn sample_times_keep_keys_inside_the_span_only() { + let times = sample_times(1.0, 2.0, 3, &[(0.5, true), (1.25, false), (2.5, false)]); + // 0.5 s and 2.5 s are off screen; the hold from 0.5 s ends at 1.25 s, inside it. + assert_eq!(times, vec![1.0, 1.25 - HOLD_EDGE, 1.25, 1.25 + HOLD_EDGE, 1.5, 2.0]); + // Degenerate input never panics: an empty span is one point, a NaN span has no points. + assert_eq!(sample_times(0.0, 0.0, 0, &[]), vec![0.0]); + assert!(sample_times(f64::NAN, 1.0, 4, &[(0.5, true)]).iter().all(|t| t.is_finite())); + } + + /// A reversed layer: its keys run backwards in comp time, and both sides of each step after + /// a Hold key are still sampled. + #[test] + fn sample_times_cover_hold_steps_on_a_reversed_layer() { + let times = sample_times(1.0, 2.0, 10, &[(1.8, true), (1.4, true), (1.1, false)]); + for t in [1.8, 1.4 - HOLD_EDGE, 1.4, 1.4 + HOLD_EDGE, 1.1 - HOLD_EDGE, 1.1, 1.1 + HOLD_EDGE] { + assert!(times.contains(&t), "{t} missing: {times:?}"); + } + assert!(times.windows(2).all(|w| w[0] < w[1]), "{times:?}"); + } + + /// Dense keys zoomed out (100 000 in one second, half of them Hold) don't multiply the samples. + #[test] + fn sample_times_stay_bounded_with_dense_keys() { + let keys: Vec<(f64, bool)> = (0..100_000).map(|i| (i as f64 / 100_000.0, i % 2 == 0)).collect(); + let times = sample_times(0.0, 1.0, 100, &keys); + assert!(times.len() <= 300, "{} samples", times.len()); + } + + /// A dense cluster of keys only thins its own grid steps: a Hold step elsewhere in view keeps + /// its key and both sides of the step. + #[test] + fn sample_times_keep_sparse_keys_beside_a_dense_cluster() { + let mut keys: Vec<(f64, bool)> = (0..100_000).map(|i| (0.1 * i as f64 / 100_000.0, i % 2 == 0)).collect(); + keys.extend([(0.5, true), (0.8, false)]); + let times = sample_times(0.0, 1.0, 100, &keys); + assert!(times.len() <= 500, "{} samples", times.len()); + for t in [0.5, 0.8 - HOLD_EDGE, 0.8, 0.8 + HOLD_EDGE] { + assert!(times.contains(&t), "{t} missing"); + } + } #[test] fn shift_locks_drag_to_dominant_axis() { diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index 9ec765bff..dd92ef941 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -325,9 +325,27 @@ fn expr_focus_id() -> egui::Id { egui::Id::unique("tl-expr-focus") } +/// Asks the expression editor of property `prop` to take the keyboard when the Timeline next +/// draws it, selecting `select` (counts of characters before the end). fn focus_expression(ctx: &egui::Context, prop: u64, select: [usize; 2]) { let pass = ctx.cumulative_pass_nr(); ctx.data_mut(|d| d.insert_temp(expr_focus_id(), ExprFocus { prop, select, pass })); + // The editor takes it in a later pass: make sure one comes without waiting for input. + ctx.request_repaint(); +} + +/// After a `prop.setExpression` toggle of `prop` was queued (an Alt-click on its stopwatch, in the +/// Timeline or in Effect Controls): adding one, its editor opens, comes into view and takes the +/// keyboard with the new expression selected (#1072, #1460); removing it, a pending request for +/// its editor goes, as nothing is left to take the keyboard. +pub(crate) fn expression_toggled(app: &mut EffectcraftApp, ctx: &egui::Context, prop: &Property) { + let uid = prop.uid; + if prop.expr.is_none() { + app.ui.timeline.expr_closed.remove(&uid); + focus_expression(ctx, uid, [usize::MAX, 0]); + } else if ctx.data(|d| d.get_temp::(expr_focus_id())).is_some_and(|f| f.prop == uid) { + ctx.data_mut(|d| d.remove::(expr_focus_id())); + } } #[derive(Clone, Debug, PartialEq)] @@ -4054,7 +4072,10 @@ fn expr_editor_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.expr_bg); let er = Rect::from_min_max(pos2(graph_x0 + 8.0, r.min.y + 3.0), pos2(rect.max.x - 14.0, r.max.y - 3.0)); let mut buf: String = ctx.data(|d| d.get_temp(buf_id)).unwrap_or_else(|| ex.text.clone()); - if let Some(f) = ctx.data(|d| d.get_temp::(expr_focus_id())).filter(|f| f.prop == *uid) { + // Not in the pass it was asked for in: a click that asked for it from another panel (an + // Alt-click on a stopwatch in Effect Controls, drawn before the Timeline) would take the + // keyboard straight back as a click elsewhere (#1460). + if let Some(f) = ctx.data(|d| d.get_temp::(expr_focus_id())).filter(|f| f.prop == *uid && ctx.cumulative_pass_nr() > f.pass) { // Asked for once (a pick whip put a reference in, or an Alt-click added the // expression): editing starts in the expression as it is now. ctx.data_mut(|d| d.remove::(expr_focus_id())); @@ -4277,19 +4298,6 @@ fn prop_context_menu( } } -/// An expression was just added to `prop` (it had none) or removed: adding one opens its -/// editor, which comes into view and takes the keyboard with the new expression selected -/// (#1072); removing it leaves nothing to take the keyboard. -fn expression_toggled(app: &mut EffectcraftApp, ctx: &egui::Context, prop: &Property) { - let uid = prop.uid; - if prop.expr.is_none() { - app.ui.timeline.expr_closed.remove(&uid); - focus_expression(ctx, uid, [usize::MAX, 0]); - } else if ctx.data(|d| d.get_temp::(expr_focus_id())).is_some_and(|f| f.prop == uid) { - ctx.data_mut(|d| d.remove::(expr_focus_id())); - } -} - /// The value editors and the property pick whip. fn prop_value_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, ectx: &EvalCtx<'_>, prop: &Property, name_x: f32) { let vis = g.tl.vis; diff --git a/crates/ui-egui/src/panels/viewer.rs b/crates/ui-egui/src/panels/viewer.rs index 04a6c7e4f..1fa58e635 100644 --- a/crates/ui-egui/src/panels/viewer.rs +++ b/crates/ui-egui/src/panels/viewer.rs @@ -1252,16 +1252,23 @@ fn phase_dragstart(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, }) } Tool::MaskFeather => ov::begin_feather(app, ectx, &paths, &map, press).map(Gesture::Overlay), - Tool::Rotate => pick(app, ectx, cpt, mods.shift).map(|l| { + // The layer under the press is the one that turns. + Tool::Rotate => pick(app, ectx, map.to_comp(press), mods.shift).map(|l| { let layer = comp.layer(l).cloned(); let sign = layer.as_ref().map_or(1.0, |l| rotation_sign(ectx, l)); let others = selected_others(app, comp, l) .into_iter() .filter_map(|o| Some((o.id, ectx.f(o, o.transform()?, "rotation", 0.0), rotation_sign(ectx, o) * sign))) .collect(); - let pivot = layer.as_ref().and_then(|l| anchor_in_comp(ectx, l)).unwrap_or(cpt); + let anchor = layer.as_ref().and_then(|l| anchor_in_comp(ectx, l)); + let pivot = anchor.unwrap_or(cpt); let rot = layer.as_ref().and_then(|l| l.transform().map(|tr| ectx.f(l, tr, "rotation", 0.0))).unwrap_or(0.0); - let last_angle = (cpt[1] - pivot[1]).atan2(cpt[0] - pivot[0]).to_degrees(); + // The turn counts from where the button went down, as in After Effects: by the + // time the drag registers the pointer has already swept some way round the anchor. + // A press on the anchor (or with no anchor to turn about) has no direction, so + // the turn then counts from where the drag registered. + let seed = if anchor.is_some() && press.distance(map.to_screen(pivot)) > 3.0 { map.to_comp(press) } else { cpt }; + let last_angle = (seed[1] - pivot[1]).atan2(seed[0] - pivot[0]).to_degrees(); Gesture::Rotate { layer: l, pivot, sign, last_angle, turned: 0.0, start_rot: rot, others } }), Tool::PanBehind => pick(app, ectx, cpt, false).and_then(|l| { diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs index 316e34ac4..1b2ce3347 100644 --- a/crates/ui-egui/src/updates_ui.rs +++ b/crates/ui-egui/src/updates_ui.rs @@ -9,7 +9,7 @@ use craft_update::updater::{Action, Status, Updater}; pub(crate) struct Runtime { #[cfg(not(target_arch = "wasm32"))] - updater: Updater, + pub(crate) updater: Updater, /// The desktop app turns the check at start on; tests and the web build leave it off. #[cfg(not(target_arch = "wasm32"))] startup_check: bool, @@ -44,6 +44,26 @@ impl EffectcraftApp { } } +/// Restart to Update. With unsaved changes the result dialog closes and the window is asked to +/// close, so the unsaved-changes prompt opens. Cancel there leaves the update ready. An open +/// startup prompt keeps its own Restart to Update and save-first note, so the window stays open. +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn restart_to_update(rt: &mut Runtime, ctx: &egui::Context, clean: bool) { + if clean { + rt.updater.restart_to_update(); + return; + } + rt.manual_window_open = false; + rt.updater.dismiss_status(); + if rt.updater.prompt_open() { + return; + } + // Without a prompt this only takes the close a finished installation queued, so a save after + // Cancel does not close the app. + let _ = rt.updater.show_if(ctx, true); + ctx.send_viewport_cmd(egui::ViewportCommand::Close); +} + pub(crate) fn check(app: &mut EffectcraftApp) { #[cfg(not(target_arch = "wasm32"))] { @@ -72,6 +92,15 @@ pub(crate) fn tick(app: &mut EffectcraftApp, ctx: &egui::Context) { let _ = (app, ctx); } +/// Whether the check result dialog shows this frame. It answers Help ▸ Check for Updates until the +/// requested check ends, and it shows whenever the status is not idle: at the first start after an +/// update, the check at start leaves `Updated` or `InstallFailed`. A check that finds a release +/// leaves the status idle and the startup prompt takes over, so the dialog closes then. +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn result_window_open(open: bool, status: &Status, check_requested: bool) -> bool { + !matches!(status, Status::Idle) || (open && check_requested) +} + pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { #[cfg(not(target_arch = "wasm32"))] { @@ -83,6 +112,7 @@ pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { Action::None => {} } let rt = &mut app.updates_rt; + rt.manual_window_open = result_window_open(rt.manual_window_open, rt.updater.status(), rt.check_requested); if rt.manual_window_open { match CheckResultDialog::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")).show(ctx, rt.updater.status()) { CheckResultResponse::None => {} @@ -91,11 +121,7 @@ pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { rt.updater.dismiss_status(); } CheckResultResponse::CheckAgain => rt.updater.check_now(ctx), - CheckResultResponse::RestartToUpdate => rt.updater.restart_to_update(), - } - // A check that found a release leaves the status idle and the startup prompt takes over. - if matches!(rt.updater.status(), Status::Idle) && !rt.check_requested { - rt.manual_window_open = false; + CheckResultResponse::RestartToUpdate => restart_to_update(rt, ctx, clean), } } } diff --git a/crates/ui-egui/tests/it/ui_angles.rs b/crates/ui-egui/tests/it/ui_angles.rs index 83fe55357..1f9845151 100644 --- a/crates/ui-egui/tests/it/ui_angles.rs +++ b/crates/ui-egui/tests/it/ui_angles.rs @@ -206,3 +206,25 @@ fn commit_edits(click_away: bool) { } } } + +/// #3367: on a negative angle the minus sign is part of the degrees typing replaces, so typing +/// 50 into `0x-20.0°` sets +50°. It used to keep the sign (-50°). Committing the text as it +/// opened keeps the angle. +#[test] +fn typing_into_a_negative_angle_replaces_its_sign() { + for panel in [Panel::EffectControls, Panel::Timeline, Panel::Properties] { + for (start, text, expected) in + [(-20.0, Some("50"), 50.0), (-20.0, Some("-50"), -50.0), (-20.0, None, -20.0), (-400.0, None, -400.0), (45.0, Some("-30"), -30.0)] + { + let (mut h, layer, uid) = harness(panel, start); + let p = component(&h, panel, uid, false); + click(&mut h, p); + if let Some(text) = text { + h.input_mut().events.push(Event::Text(text.into())); + h.step(); + } + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(angle(&h, layer, uid), expected, "{panel:?}: {start} then {text:?}"); + } + } +} diff --git a/crates/ui-egui/tests/it/ui_inline_edit.rs b/crates/ui-egui/tests/it/ui_inline_edit.rs index 60b18d8eb..dc7fd02e1 100644 --- a/crates/ui-egui/tests/it/ui_inline_edit.rs +++ b/crates/ui-egui/tests/it/ui_inline_edit.rs @@ -725,6 +725,54 @@ fn an_expression_added_at_the_bottom_of_the_timeline_comes_into_view() { assert_eq!(expression(&h, layer, opacity).as_deref(), Some("25")); } +/// #1460: Alt-clicking an effect property's stopwatch in Effect Controls adds an expression, as in +/// the Timeline (it toggled the animation instead). Effect Controls has no expression field, so, +/// as in After Effects, the property shows in the Timeline (its layer and effect twirled open, +/// scrolled into view) with the new expression's editor taking the keyboard: typing replaces +/// it. Another Alt-click removes it and leaves nothing holding the keyboard. +#[test] +fn alt_clicking_a_stopwatch_in_effect_controls_edits_the_expression_in_the_timeline() { + let (mut h, _) = harness(); + let (layer, slider) = { + let s = &mut h.state_mut().session; + let l = s.execute("layer.newSolid", json!({"name": "Plate", "color": "#406080"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("effect.apply", json!({"layers": [l], "effect": "Slider Control"})).unwrap(); + // Layers above push it below the bottom of the Timeline. + for i in 0..40 { + s.execute("layer.newSolid", json!({"name": format!("Layer {i}"), "color": "#204060"})).unwrap(); + } + s.execute("layer.select", json!({"layers": [l]})).unwrap(); + let slider = s.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(l)).unwrap().props.prop("effects/#1/slider").unwrap().uid; + (l, slider) + }; + h.state_mut().show_panel(effectcraft_ui_egui::dock::PanelKind::EffectControls); + h.run_steps(3); + let editor = format!("timeline.prop.{slider}.expression"); + assert!(h.state().auto.find(&format!("timeline.prop.{slider}.row")).is_none(), "the property is not in the Timeline yet"); + let alt = Modifiers { alt: true, ..Modifiers::NONE }; + let at = center(&h, &format!("effectControls.prop.{slider}.stopwatch")); + click_with(&mut h, at, alt); + assert!(expression(&h, layer, slider).is_some(), "an expression was added"); + let key = h.state().session.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(layer)).unwrap().props.find(slider).unwrap().is_animated(); + assert!(!key, "Alt-click doesn't turn on keyframing"); + assert!(h.state().ui.timeline.reveal_props.contains(&slider), "the property is revealed in the Timeline"); + let rows = h.state().auto.find("timeline.scroll").expect("the Timeline is shown").rect; + let e = h.state().auto.find(&editor).expect("the Timeline draws the expression editor").rect; + assert!(e[1] >= rows[1] - 0.5 && e[1] + e[3] <= rows[1] + rows[3] + 0.5, "the editor is in view: {e:?} in {rows:?}"); + type_text(&mut h, "42"); + commit_expression(&mut h); + assert_eq!(expression(&h, layer, slider).as_deref(), Some("42"), "typing replaced the new expression"); + // Alt-click again removes the expression and its editor with it (the keyboard stays free; + // the editor's focus request was taken when it was added, so this doesn't exercise the + // cancel path). + let at = center(&h, &format!("effectControls.prop.{slider}.stopwatch")); + click_with(&mut h, at, alt); + h.run_steps(5); + assert_eq!(expression(&h, layer, slider), None); + assert!(h.state().auto.find(&editor).is_none(), "the expression editor is gone"); + assert!(!h.ctx.egui_wants_keyboard_input(), "nothing has the keyboard"); +} + fn right_click(h: &mut Harness<'_, EffectcraftApp>, p: Pos2) { h.input_mut().events.push(Event::PointerMoved(p)); h.step(); diff --git a/crates/ui-egui/tests/it/ui_viewer.rs b/crates/ui-egui/tests/it/ui_viewer.rs index db171b635..6dee87535 100644 --- a/crates/ui-egui/tests/it/ui_viewer.rs +++ b/crates/ui-egui/tests/it/ui_viewer.rs @@ -3218,6 +3218,67 @@ fn rotate_tool_counts_revolutions_both_ways() { assert_eq!(h.state().session.history.undo.len(), undo_before + 1, "one drag, one undo step"); } +/// #2769: the Rotation tool counts the turn from where the button went down, as in After Effects, +/// not from where the drag registered: a first move that sweeps 60° round the anchor turns the +/// layer 60° (it used to drop that sweep, so near the anchor the tool lagged behind the pointer). +#[test] +fn rotate_tool_counts_the_turn_from_the_press() { + let mut h = harness(); + let box_id = h.state().session.active_comp().unwrap().layers[0].id; + h.state_mut().session.execute("layer.select", json!({"layers": [box_id.0]})).unwrap(); + h.state_mut().ui.tool = Tool::Rotate; + h.run_steps(2); + let center = screen(&h, [320.0, 180.0]); + let r = (screen(&h, [350.0, 180.0]) - center).x; + // Press on the box right of its anchor (0°), then one move to 60° clockwise, still on the box. + let press = center + vec2(r * 0.3, 0.0); + let to = center + vec2(r * 60f32.to_radians().cos(), r * 60f32.to_radians().sin()); + h.input_mut().events.push(Event::PointerMoved(press)); + h.input_mut().events.push(Event::PointerButton { pos: press, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.step(); + h.input_mut().events.push(Event::PointerMoved(to)); + h.step(); + // The gesture applies the previous frame's pointer: hold a frame. + h.step(); + h.input_mut().events.push(Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.run_steps(2); + let rot = h.state().session.active_comp().unwrap().layer(box_id).unwrap().props.prop("transform/rotation").unwrap().value.as_f64(); + assert!((rot - 60.0).abs() < 1.0, "the whole sweep from the press turns the layer: {rot}"); +} + +/// #2769: a press right on the anchor point has no direction to count the turn from, so the layer +/// doesn't jump on the first move; the turn counts from where the drag registered. +#[test] +fn rotate_tool_pressed_on_the_anchor_does_not_jump() { + let mut h = harness(); + let box_id = h.state().session.active_comp().unwrap().layers[0].id; + h.state_mut().session.execute("layer.select", json!({"layers": [box_id.0]})).unwrap(); + h.state_mut().ui.tool = Tool::Rotate; + h.run_steps(2); + let rotation = |h: &Harness<'_, EffectcraftApp>| { + h.state().session.active_comp().unwrap().layer(box_id).unwrap().props.prop("transform/rotation").unwrap().value.as_f64() + }; + let center = screen(&h, [320.0, 180.0]); + let r = (screen(&h, [350.0, 180.0]) - center).x; + let at = |deg: f32| center + vec2(r * deg.to_radians().cos(), r * deg.to_radians().sin()); + h.input_mut().events.push(Event::PointerMoved(center)); + h.input_mut().events.push(Event::PointerButton { pos: center, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.step(); + h.input_mut().events.push(Event::PointerMoved(at(60.0))); + h.step(); + // The gesture applies the previous frame's pointer: hold a frame. + h.step(); + let first = rotation(&h); + assert!(first.abs() < 1.0, "no jump on the first move: {first}"); + h.input_mut().events.push(Event::PointerMoved(at(90.0))); + h.step(); + h.step(); + let next = rotation(&h); + assert!((next - 30.0).abs() < 1.0, "then turns with the pointer: {next}"); + h.input_mut().events.push(Event::PointerButton { pos: at(90.0), button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.run_steps(2); +} + /// A harness whose Box is a child of Plate (anchor 320,180) with `plate` set on Plate first, at /// parent-space position (200, 120). Returns the two layers' ids. fn rotate_child_harness(plate: serde_json::Value) -> (Harness<'static, EffectcraftApp>, u64, u64) { diff --git a/docs/plugins.md b/docs/plugins.md index 290ed033c..67b19f0a2 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -388,12 +388,21 @@ package can't read files, open the network or crash the app. [`storytold/effectcraft-plugins`](https://github.com/storytold/effectcraft-plugins) repository; packages are added by pull request and reviewed there. The app has no field for another catalog; `library.refresh {catalog}` (for plug-in authors testing an entry) takes an `index.json` - on GitHub or a local file, and the page then says it shows a test catalog until Refresh. + on GitHub or a local file, and the page then says it shows a test catalog until Refresh. A file + URL that names a network path (`file:////server/share/…`) is refused. * **Nothing is downloaded until you ask.** Fetch Catalog (`library.refresh`) reads the catalog; Install (`library.install`) downloads the package's `.wasm`, checks its SHA-256 (and its size, when the catalog gives one) against the catalog and loads it. Downloads use the system's `curl`, `https://` only and starting on GitHub's hosts (redirects stay on `https://`; the SHA-256 check - is what guarantees the file). + is what guarantees the file). A package's `url` must be a release asset + (`https://github.com///releases/download/…`). When the package names a `repo`, the + asset must be in that repository. A `repo` that isn't `https://github.com//` (with + an optional trailing `/` or `.git`) or a folder in one (`https://github.com///tree//…`) + makes Install and Preview refuse every `https://` release of the package. These rules don't apply + to a release whose `url` is a local `file://` path, which only a local catalog may name (to test + an entry before its release is published). A catalog other than the community one is read only when + `library.refresh {catalog}` names it: an `index.json` on GitHub's hosts over `https://`, or a + local `file://` path. * **Where it goes.** `/Library///.wasm` (the `Plug-ins` folder next to the settings), listed in `Library/installed.json`. Installed packages load at start-up, each checked against the SHA-256 it was installed with. The catalog last fetched is kept as diff --git a/docs/publishing-plugins.md b/docs/publishing-plugins.md index bd76c3ab5..20f630e1c 100644 --- a/docs/publishing-plugins.md +++ b/docs/publishing-plugins.md @@ -181,7 +181,7 @@ Package fields: | `author` | no | You, or your group. | | `description` | no, but reviewed | One or two plain sentences that say what the effect does. | | `license` | no, but reviewed | The licence's SPDX id (`MIT`, `Apache-2.0`, `MIT OR Apache-2.0`…). | -| `repo` | no, but reviewed | The public source repository. The details' "Open on GitHub" opens it. | +| `repo` | no, but reviewed | The public source repository, as `https://github.com//` (a trailing `/` or `.git` is allowed), or a folder in it, `https://github.com///tree//`. The details' "Open on GitHub" opens it. When `repo` is given in any other form, Install and Preview refuse every release of the package. | | `tags` | no | Lower-case words for the tag filter (`blur`, `stylize`, `light`, `distort`…). Reuse tags the catalog already has. | | `preview.video` | no | An `https://` link to a short demo video on YouTube, Vimeo or GitHub. "Watch video" opens it in the browser. A link that isn't `https://` (or is longer than 500 characters) is left out. The live preview doesn't need it. | | `versions` | yes | One entry per release, newest or oldest first. | @@ -193,7 +193,7 @@ Release fields (one per entry in `versions`): | `version` | yes | Dotted numbers only, at most 32 characters: `1.0.0`, `1.2`. No `v` and no suffixes such as `-beta`. | | `api` | yes | The plug-in API the module implements: `1`. | | `minApp` | no | The oldest EffectCraft version the release needs (`0.17.0`). Leave it out if any version with this API works. | -| `url` | yes | The release asset's `https://` URL on GitHub. | +| `url` | yes | The release asset's `https://` URL on GitHub: `https://github.com///releases/download//`. When the package has a `repo`, the asset must be in that repository. Install and Preview refuse any other `https://` URL. | | `sha256` | yes | The file's SHA-256, 64 hex digits. | | `size` | no, but reviewed | The file's size in bytes. When it is given, a download of another size is refused. | | `effects` | yes | The effect ids the module registers (its manifest's `id`). EffectCraft uses them to find the package that provides an effect a project needs. | @@ -226,7 +226,9 @@ Make a folder with an `index.json` that holds only your package: ``` File URLs are absolute: `file:///home/me/glow-rings/index.json` on Linux and macOS, -`file:///C:/Users/me/glow-rings/index.json` on Windows. Write a space as `%20`. +`file:///C:/Users/me/glow-rings/index.json` on Windows. Write a space as `%20`. Separate folders +with `/`: a file URL that holds a `\` or a percent-encoded `/` or `\`, or names a network path +(`file:////server/share/…`), is refused. Use a separate settings folder, so the test doesn't touch your real installation: diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 247887345..09f9df6bc 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1,5 +1,6 @@ # Parity with After Effects +> **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-15 · **Change:** minor (ROADMAP sync over 5–15 November: .aep export, drag-and-drop import, hostile-input audit and loss reporting, effect placeholders and mappings, 2.6× GPU rendering, EXR output options, eighteen aligned effect ranges and a broad editor/expression fix batch; releases v0.22.0–v0.24.1. No parity numbers re-measured; the 10 October re-measure and all readiness estimates are unchanged) · **Target:** Adobe After Effects 2026 (26.5.0.89) > **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-12 · **Change:** minor (issue, catalog and export-format references re-audited against `upstream/main` 470ea7a3; the 10 October re-measure is otherwise unchanged) · **Target:** Adobe After Effects 2026 (26.5.0.89) The authoritative assessment of how close EffectCraft is to After Effects, and how much work is diff --git a/examples/plugin-catalog/schema.json b/examples/plugin-catalog/schema.json index a2d30676b..c31d57fea 100644 --- a/examples/plugin-catalog/schema.json +++ b/examples/plugin-catalog/schema.json @@ -12,9 +12,9 @@ }, "$defs": { "version": {"type": "string", "maxLength": 32, "pattern": "^[0-9]+(\\.[0-9]+)*$"}, - "github_url": { + "release_url": { "type": "string", - "pattern": "^https://(github\\.com|raw\\.githubusercontent\\.com|objects\\.githubusercontent\\.com|release-assets\\.githubusercontent\\.com)/[^\\s]+$" + "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s\\u0085]+(/[^/?#\\\\\\s\\u0085]+)+$" }, "package": { "type": "object", @@ -26,7 +26,7 @@ "author": {"type": "string"}, "description": {"type": "string"}, "license": {"type": "string"}, - "repo": {"type": "string", "pattern": "^https://"}, + "repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s\\u0085]+)+)?/?$"}, "tags": {"type": "array", "items": {"type": "string"}}, "preview": { "type": "object", @@ -44,7 +44,7 @@ "version": {"$ref": "#/$defs/version"}, "api": {"type": "integer", "minimum": 0, "maximum": 4294967295}, "minApp": {"$ref": "#/$defs/version"}, - "url": {"$ref": "#/$defs/github_url"}, + "url": {"$ref": "#/$defs/release_url"}, "sha256": {"type": "string", "pattern": "^[0-9a-fA-F]{64}$"}, "size": {"type": "integer", "minimum": 1, "maximum": 67108864}, "effects": {"type": "array", "minItems": 1, "items": {"type": "string", "pattern": "^(?!ec\\.)[A-Za-z0-9._-]+$"}} diff --git a/examples/plugin-catalog/scripts/validate.sh b/examples/plugin-catalog/scripts/validate.sh index 688ffdc26..5c1c443a0 100644 --- a/examples/plugin-catalog/scripts/validate.sh +++ b/examples/plugin-catalog/scripts/validate.sh @@ -42,7 +42,46 @@ dups=$(jq -r '.packages[].id' "$catalog" | sort | uniq -d) [[ -z "$dups" ]] || fail "duplicate package ids: $dups" echo "ok" -echo "== 3. downloads" +echo "== 3. release URLs" +# Every release that isn't a local file:// path must be a release asset, and when its package has +# a `repo`, an asset of that repository, as Install and Preview require (the loader step installs +# from file:// copies, which skip this check). +bad=$(jq -r ' + # A path segment EffectCraft refuses: empty, `.` or `..` (also percent-encoded). + def bad_segment: . == "" or (ascii_downcase | gsub("%2e"; ".") | . == "." or . == ".."); + # A `?`, `#`, `\` or white space character (Unicode, and U+FEFF), which EffectCraft refuses in a URL. + def bad_char: test("[?#\\\\\t\n\u000b\f\r \u0085   - 

   ]"); + # "owner/name" in lower case of a release asset, + # https://github.com///releases/download// (a tag may contain `/`), with + # no query, fragment, backslash, white space, or empty, `.` or `..` segment; "?" for anything else. + def asset_of: + if startswith("https://") and (.[8:19] | ascii_downcase) == "github.com/" then + .[19:] as $rest + | ($rest | split("/")) as $p + | if ($rest | bad_char) or ($p | length) < 6 or ($p | any(bad_segment)) + or ($p[0] | test("^[A-Za-z0-9._-]+$") | not) or ($p[1] | test("^[A-Za-z0-9._-]+$") | not) + or $p[2] != "releases" or $p[3] != "download" + then "?" else "\($p[0])/\($p[1])" | ascii_downcase end + else "?" end; + # Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case. + def repo_of: + if bad_char then "?" else + (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+?)(\\.git)?/?$") + // (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+)/tree/(?[^?#\\\\]+?)/?$") + | select(.f | split("/") | any(bad_segment) | not)) + | select((.h | ascii_downcase) == "https://github.com" and (.o | bad_segment | not) and (.n | bad_segment | not)) + | "\(.o)/\(.n)" | ascii_downcase) // "?" end; + .packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo + | (if $repo == "" then "" else $repo | repo_of end) as $want + | .versions[] | select(.url | startswith("file://") | not) + | (.url | asset_of) as $got + | if $got == "?" then "\($pkg.id) \(.version): \(.url) is not a release asset (https://github.com///releases/download//)" + elif $want != "" and ($want == "?" or $got != $want) then "\($pkg.id) \(.version): \(.url) is not a release asset of \($repo)" + else empty end' "$catalog") +[[ -z "$bad" ]] || fail "release URLs that Install and Preview refuse:"$'\n'"$bad" +echo "ok" + +echo "== 4. downloads" # The checked files are what the loader step installs: a copy of the catalog names them by file://. local_catalog=$(jq '.' "$catalog") while IFS=$'\t' read -r p r id version url sha size; do @@ -58,7 +97,7 @@ done < <(jq -r '.packages | to_entries[] | .key as $p | .value as $pkg | $pkg.ve | [$p, .key, $pkg.id, .value.version, .value.url, .value.sha256, (.value.size // "")] | @tsv' "$catalog") echo "ok" -echo "== 4. load with EffectCraft" +echo "== 5. load with EffectCraft" if [[ -z "${EFFECTCRAFT_CLI:-}" ]]; then echo "skipped (set EFFECTCRAFT_CLI to an effectcraft-cli build)" exit 0