diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock new file mode 100644 index 000000000..5e478baa9 --- /dev/null +++ b/.github/workflows/actions.lock @@ -0,0 +1,31 @@ +# This file is machine-generated by `gh actions-lock`. +# Do not edit by hand; run `gh actions-lock` to update. +# Docs: https://gh.io/actions-lockfile +version: 'v0.0.3' +workflows: + '.github/workflows/ci.yml': + - 'actions/checkout@v7.0.1' + - 'step-security/harden-runner@v2.22.4' + '.github/workflows/freebsd.yml': [] + '.github/workflows/house-rules.yml': [] + '.github/workflows/lockfile.yml': + - 'actions/checkout@v7.0.1' + - 'step-security/harden-runner@v2.22.4' + '.github/workflows/nix.yml': [] + '.github/workflows/packaging-lint.yml': + - 'actions/checkout@v7.0.1' + - 'step-security/harden-runner@v2.22.4' + '.github/workflows/release.yml': [] + '.github/workflows/sonarcloud.yml': [] + '.github/workflows/windows-arm64.yml': [] +dependencies: + 'actions/checkout@v7.0.1': + ref: 'v7.0.1' + commit: 'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1' + owner_id: 44036562 + repo_id: 197814629 + 'step-security/harden-runner@v2.22.4': + ref: 'v2.22.4' + commit: 'sha1-1d88384fd173af6ecb012dfd0264a306b711241a' + owner_id: 88700172 + repo_id: 422287306 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 073423629..82de4815f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,11 +27,11 @@ jobs: CRAFT_FONTS_REF: 37827adc41fd165f9a9234ac40f94dbad353aa69 steps: - name: Harden runner - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + uses: step-security/harden-runner@v2.22.4 with: egress-policy: audit - name: Check out craft-fonts - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + uses: actions/checkout@v7.0.1 with: repository: storytold/craft-fonts ref: ${{ env.CRAFT_FONTS_REF }} diff --git a/.github/workflows/lockfile.yml b/.github/workflows/lockfile.yml new file mode 100644 index 000000000..e630c9a8f --- /dev/null +++ b/.github/workflows/lockfile.yml @@ -0,0 +1,34 @@ +name: Lockfile + +# Fails when .github/workflows/actions.lock is out of sync with the workflows, or when a locked pin +# no longer verifies upstream, so a moved tag cannot slip a different commit into a run. +# Docs: https://gh.io/actions-lockfile +on: + pull_request: + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +env: + GH_TOKEN: ${{ github.token }} + +jobs: + lockfile: + name: Lockfile is in sync + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - name: Harden runner + uses: step-security/harden-runner@v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: Install gh-actions-lock + run: gh extension install github/gh-actions-lock --pin v0.4.1 + - name: Verify the lockfile + run: gh actions-lock --verify diff --git a/.github/workflows/packaging-lint.yml b/.github/workflows/packaging-lint.yml index 1771a35fe..fb9e3d4f7 100644 --- a/.github/workflows/packaging-lint.yml +++ b/.github/workflows/packaging-lint.yml @@ -28,10 +28,10 @@ jobs: runs-on: windows-latest steps: - name: Harden runner - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + uses: step-security/harden-runner@v2.22.4 with: egress-policy: audit - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@v7.0.1 with: persist-credentials: false - name: Install the pinned packaging toolchain diff --git a/AGENTS.md b/AGENTS.md index 88d84ec92..03fa547d3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -239,3 +239,7 @@ the `ROADMAP.md` progress log, and update each touched doc's status line and rev - Workflows in `.github/workflows/` call the shared workflows in [`storytold/craft-common-actions`](https://github.com/storytold/craft-common-actions) at `@main`, with their inputs and secrets. No other jobs: if no shared workflow does what's needed, it doesn't go here. - Don't add or change CI in a feature or fix PR. If the existing workflows can't build or test a change, link an existing craft-common-actions issue or PR, or open a new issue, or a PR only for a small fix that is safe for every app and does not increase CI time. - Some workflow files here still run their own jobs. Don't add to them. Moving a job into craft-common-actions is its own task, never part of another PR, and the job stays here until a shared workflow runs it. + +## Shared libraries + +Before adding or changing file-format, codec, protocol, or reusable UI code, check `storytold/craft-libs` and its open PRs first; reuse or extend the shared library rather than duplicating it locally, keep app-specific policy and model mapping in the app, and preserve behavior, security/resource limits, attribution, and regression coverage during cutovers. diff --git a/crates/pptx/src/custgeom.rs b/crates/pptx/src/custgeom.rs index 383113847..a3590de16 100644 --- a/crates/pptx/src/custgeom.rs +++ b/crates/pptx/src/custgeom.rs @@ -348,73 +348,7 @@ fn arc_to(d: &mut String, cur: (f64, f64), wr: f64, hr: f64, st: f64, sw: f64) - } /// Parse our path syntax into commands. -pub fn parse_path(d: &str) -> Vec<(char, Vec)> { - let mut out = vec![]; - let mut cmd: Option = None; - let mut nums: Vec = vec![]; - let flush = |cmd: Option, nums: &mut Vec, out: &mut Vec<(char, Vec)>| { - if let Some(c) = cmd { - let n = match c { - 'M' | 'L' => 2, - 'C' => 6, - 'Q' => 4, - _ => 0, - }; - if n == 0 { - out.push((c, vec![])); - } else { - for (i, chunk) in nums.chunks(n).enumerate() { - if chunk.len() == n && out.len() < 1_000_000 { - // Repeated coordinates after M continue as L. - let c2 = if c == 'M' && i > 0 { 'L' } else { c }; - out.push((c2, chunk.to_vec())); - } - } - } - } - nums.clear(); - }; - let mut token = String::new(); - let push_tok = |token: &mut String, nums: &mut Vec| { - if !token.is_empty() { - if let Ok(v) = token.parse::() - && v.is_finite() - { - nums.push(v); - } - token.clear(); - } - }; - let cs: Vec = d.chars().collect(); - for (i, &ch) in cs.iter().enumerate() { - match ch { - // An 'E' inside a number followed by a digit (or a sign and a digit) is an exponent, - // not the end command. - 'E' if !token.is_empty() && { - let n1 = cs.get(i + 1).copied().unwrap_or(' '); - let n2 = cs.get(i + 2).copied().unwrap_or(' '); - n1.is_ascii_digit() || ((n1 == '-' || n1 == '+') && n2.is_ascii_digit()) - } => - { - token.push(ch) - } - 'M' | 'L' | 'C' | 'Q' | 'Z' | 'm' | 'l' | 'c' | 'q' | 'z' | 'E' => { - push_tok(&mut token, &mut nums); - flush(cmd, &mut nums, &mut out); - cmd = Some(ch.to_ascii_uppercase()); - } - ' ' | ',' | '\t' | '\n' => push_tok(&mut token, &mut nums), - '-' if !token.is_empty() && !token.ends_with(['e', 'E']) => { - push_tok(&mut token, &mut nums); - token.push(ch); - } - c => token.push(c), - } - } - push_tok(&mut token, &mut nums); - flush(cmd, &mut nums, &mut out); - out -} +pub use craft_drawingml::custgeom::parse_path; /// Write custom paths as `a:custGeom`. Coordinates are integers in the file, so small path spaces /// are scaled up. @@ -596,3 +530,18 @@ mod tests { assert!(parse_path("garbage ### C 1").is_empty() || parse_path("garbage").is_empty()); } } + +#[cfg(test)] +mod shared_path_tests { + use super::parse_path; + + #[test] + fn shared_path_tokens_preserve_exponents_repeats_and_dropped_tails() { + assert_eq!( + parse_path("M1E2 -3E-1 4 5 L6-7 Q8 9 10 11 Z"), + vec![('M', vec![100.0, -0.3]), ('L', vec![4.0, 5.0]), ('L', vec![6.0, -7.0]), ('Q', vec![8.0, 9.0, 10.0, 11.0]), ('Z', vec![]),] + ); + assert_eq!(parse_path("M0 0 L1"), vec![('M', vec![0.0, 0.0])]); + assert_eq!(parse_path("MNaN 0 1 2"), vec![('M', vec![0.0, 1.0])]); + } +} diff --git a/crates/ui-egui/src/panels/fillui.rs b/crates/ui-egui/src/panels/fillui.rs index d1f807ae7..a8a29680d 100644 --- a/crates/ui-egui/src/panels/fillui.rs +++ b/crates/ui-egui/src/panels/fillui.rs @@ -232,6 +232,8 @@ pub fn gradient_editor(ui: &mut Ui, id: &str, g: &Gradient, sc: &ColorScheme) -> let (marks, _) = ui.allocate_exact_size(vec2(bar.width(), 14.0), Sense::hover()); let drag_id = ui.scope_id().with((id, "drag")); let mut dragging: Option<(usize, f64)> = ui.data_mut(|d| d.get_temp(drag_id)); + // A double-clicked stop opens its colour menu, as in PowerPoint (#2175). + let mut open_color = false; for (i, s) in g.stops.iter().enumerate() { let pos = dragging.filter(|d| d.0 == i).map_or(s.pos, |d| d.1); let x = bar.min.x + pos as f32 * bar.width(); @@ -245,6 +247,10 @@ pub fn gradient_editor(ui: &mut Ui, id: &str, g: &Gradient, sc: &ColorScheme) -> if resp.clicked() || resp.drag_started() { sel = i; } + if resp.double_clicked() { + sel = i; + open_color = true; + } if resp.dragged() && let Some(p) = resp.interact_pointer_pos() { @@ -287,7 +293,12 @@ pub fn gradient_editor(ui: &mut Ui, id: &str, g: &Gradient, sc: &ColorScheme) -> let (sw, _) = ui.allocate_exact_size(vec2(18.0, 18.0), Sense::hover()); ui.painter().rect(sw, CornerRadius::same(3), c32(&s.color, sc), Stroke::new(1.0, t.border), egui::StrokeKind::Inside); let r = widgets::drop_button(ui, "", vec2(24.0, 20.0), true); - widgets::color_popup(&r).show(|ui| { + r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, "Stop color")); + let mut popup = widgets::color_popup(&r); + if open_color { + popup = popup.open_memory(egui::SetOpenCommand::Bool(true)); + } + popup.show(|ui| { if let Some(Some(c)) = widgets::color_grid(ui, sc, None) { let mut ng = g.clone(); ng.stops[sel].color = with_alpha(c, alpha_of(&s.color)); @@ -516,7 +527,58 @@ pub fn pattern_editor(ui: &mut Ui, pt: &PatternFill, sc: &ColorScheme) -> Option #[cfg(test)] mod tests { + #![allow(clippy::unwrap_used, clippy::expect_used)] + use super::*; + use egui_kittest::Harness; + use egui_kittest::kittest::Queryable; + + /// #2175: double-clicking a gradient stop selects it and opens its colour menu; a colour + /// picked there colours that stop. + #[test] + fn double_clicking_a_stop_opens_its_color_menu() { + let sc = deckcraft_model::Theme::default().colors; + let start = Gradient { + stops: vec![ + GradientStop { pos: 0.0, color: ColorRef::scheme(SchemeSlot::Accent1) }, + GradientStop { pos: 1.0, color: ColorRef::scheme(SchemeSlot::Accent2) }, + ], + ..default_gradient(ColorRef::scheme(SchemeSlot::Accent1), 90.0) + }; + // The gradient, and whether the interface fonts are in (they apply from the next frame). + let mut h = Harness::builder().with_size(vec2(400.0, 700.0)).with_step_dt(1.0 / 60.0).build_ui_state( + move |ui, (g, fonts): &mut (Gradient, bool)| { + if !*fonts { + theme::install_fonts(ui.ctx()); + *fonts = true; + return; + } + if let Some(ng) = gradient_editor(ui, "test-grad", &g.clone(), &sc) { + *g = ng; + } + }, + (start, false), + ); + h.run_steps(3); + assert!(h.query_by_label("Theme Colors").is_none(), "the menu starts closed"); + let stop = h.get_by_label("Gradient stop 2").rect().center(); + h.hover_at(stop); + h.run_steps(1); + for _ in 0..2 { + for pressed in [true, false] { + h.event(egui::Event::PointerButton { pos: stop, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }); + h.run_steps(1); + } + } + h.run_steps(2); + assert!(h.query_by_label("Theme Colors").is_some(), "the colour menu opened"); + h.get_by_label(SchemeSlot::Accent6.label()).click(); + h.run_steps(2); + let g = &h.state().0; + assert_eq!(g.stops.len(), 2, "no stop was added"); + assert_eq!(g.stops[1].color, ColorRef::scheme(SchemeSlot::Accent6), "the double-clicked stop took the colour"); + assert_eq!(g.stops[0].color, ColorRef::scheme(SchemeSlot::Accent1)); + } #[test] fn gradient_json_retains_flip_mode() { diff --git a/crates/ui-egui/src/show.rs b/crates/ui-egui/src/show.rs index db7983c2b..64f0b4dc7 100644 --- a/crates/ui-egui/src/show.rs +++ b/crates/ui-egui/src/show.rs @@ -552,7 +552,8 @@ impl Show { true } - /// On entering a slide: auto-play its first step when it begins With/After Previous. + /// On entering a slide: auto-play its first step when it begins With/After Previous, once the + /// slide's transition is over. /// `ShowState` already starts such a step when it enters the slide (#631: asking it for the /// next step again finished the step at once, so the slide appeared fully built), so only /// its clock starts here. Autoplay previews start an On Click first step themselves. @@ -568,7 +569,9 @@ impl Show { None }; if let Some(k) = started { - self.step_start = now; + // The slide's transition plays first; its animations start when it has finished, as + // in PowerPoint (#2089). + self.step_start = self.trans.as_ref().map_or(now, |t| now.max(t.start + t.dur)); self.media_clock = Some((k, f64::NEG_INFINITY)); } } diff --git a/crates/ui-egui/src/show/tests.rs b/crates/ui-egui/src/show/tests.rs index a01989ac0..58fa5ffa3 100644 --- a/crates/ui-egui/src/show/tests.rs +++ b/crates/ui-egui/src/show/tests.rs @@ -516,6 +516,41 @@ fn a_transition_keeps_the_old_slide_in_its_own_texture() { assert!(show.tex.is_none(), "the new slide gets a texture of its own instead of overwriting the old one"); } +/// #2089: a slide's With Previous entrance waits for the slide's transition to finish, as in +/// PowerPoint, instead of playing under it. +#[test] +fn animations_start_after_the_slides_transition() { + let mut s = deckcraft_engine::Session::with_new(); + s.execute("slide.new", &json!({})).unwrap(); + s.execute("transition.set", &json!({"kind": "fade", "index": 1, "duration": 400})).unwrap(); + let id = s.active().unwrap().doc.slides[1].shapes[0].id; + s.execute("animation.add", &json!({"effect": "fade", "class": "entrance", "ids": [id.0], "start": "withPrevious", "duration": 500})).unwrap(); + let doc = s.active().unwrap().doc.clone(); + let mut show = Show::new(&doc, 0, false, false); + let a = show.state.next(&doc); + assert_eq!(a, ShowAction::Slide(1)); + assert!(show.apply(a, &doc, 10.0)); + assert!(show.trans.is_some(), "the fade plays"); + assert!(show.state.playing, "the With Previous step is under way"); + assert!((show.clock_snapshot().step_start - 10.4).abs() < 1e-9, "its clock starts when the 0.4 s fade ends"); + let tl = ShowState::timeline(&doc, 1); + let at = |now: f64| state_for(&tl, id, show.state.step, now - show.clock_snapshot().step_start, &[], &[]); + assert!(!at(10.3).visible, "hidden while the transition plays"); + assert!(at(10.6).visible && at(10.6).opacity < 1.0, "fading in after it"); + // The step is not cut short by the time the transition took. + let mut actions = Vec::new(); + assert!(show.queue_clock_actions(&doc, 10.8, &mut actions)); + assert!(actions.is_empty(), "0.4 s into a 0.5 s step: still playing"); + + // Without a transition the step starts at once, as before. + s.execute("transition.set", &json!({"kind": "none", "index": 1})).unwrap(); + let doc = s.active().unwrap().doc.clone(); + let mut show = Show::new(&doc, 0, false, false); + let a = show.state.next(&doc); + assert!(show.apply(a, &doc, 10.0)); + assert_eq!(show.clock_snapshot().step_start, 10.0); +} + #[test] fn going_back_plays_the_left_slides_transition_reversed() { // #1531: Back from B to A played A's own entrance transition. PowerPoint plays the one B came diff --git a/sonar-project.properties b/sonar-project.properties index 5d2418cb1..16a5e3800 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,2 +1,11 @@ sonar.projectKey=storytold_deckcraft sonar.organization=storytold + +# githubactions:S7637 asks for every action to be pinned to a commit SHA. A workflow covered by +# .github/workflows/actions.lock runs the commit the lockfile records, so its tag refs are pinned +# and the lockfile covers the actions those actions use too. Sonar does not read lockfiles yet, so +# the rule flags the tag refs anyway: +# https://community.sonarsource.com/t/githubactions-s7637-false-positives-for-actions-pinned-through-native-actions-lock/190814 +sonar.issue.ignore.multicriteria=gha-lockfile +sonar.issue.ignore.multicriteria.gha-lockfile.ruleKey=githubactions:S7637 +sonar.issue.ignore.multicriteria.gha-lockfile.resourceKey=.github/workflows/**