From e556406652b30cba1d61530d02a3c1b55a7c0dbd Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 2 Dec 2026 16:14:06 -0800 Subject: [PATCH 1/2] Scripts: loading the same built-in preset with or without brackets does not trace again `vectorcraft_trace::preset` accepts a built-in preset's name with or without brackets (`[Default]`), but `TracingOptions.loadFromPreset` compared the tracing's stored preset name with the requested one as given. Loading `[Default]` on a tracing made with `Default` (or the other way round) with unchanged options traced the image again and added an undo step. The comparison now strips the brackets from built-in preset names on both sides. Saved presets keep the exact comparison. The check came in with #9077. --- crates/engine/src/script/dom/tracing.rs | 6 ++++- crates/engine/src/tests/script_dom_tracing.rs | 25 +++++++++++++++++++ docs/mcp.md | 3 ++- docs/target-app-parity.md | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/script/dom/tracing.rs b/crates/engine/src/script/dom/tracing.rs index a37a062849..d25c7bcaa6 100644 --- a/crates/engine/src/script/dom/tracing.rs +++ b/crates/engine/src/script/dom/tracing.rs @@ -838,7 +838,11 @@ fn options_load(h: &Host, a: &[Data]) -> Answer { let wanted = vectorcraft_trace::preset(name).or_else(|| h.session.borrow().trace_preset(name).map(|q| q.params.clone())); let wanted = wanted.ok_or_else(|| HostError::Error("TracingOptions.loadFromPreset: no built-in or saved preset has that name".into()))?; let same = serde_json::to_value(&wanted).ok().as_ref().and_then(Value::as_object) == Some(¶ms); - if !(same && preset.eq_ignore_ascii_case(name)) { + // A built-in preset answers to its name with or without brackets (`[Default]`). + let key = |n: &str| { + if vectorcraft_trace::preset(n).is_some() { n.trim().trim_start_matches('[').trim_end_matches(']').to_string() } else { n.to_string() } + }; + if !(same && key(&preset).eq_ignore_ascii_case(&key(name))) { let mut p = Map::new(); p.insert("preset".into(), json!(name)); retrace(h, item, p)?; diff --git a/crates/engine/src/tests/script_dom_tracing.rs b/crates/engine/src/tests/script_dom_tracing.rs index 24223785dd..9e6a496790 100644 --- a/crates/engine/src/tests/script_dom_tracing.rs +++ b/crates/engine/src/tests/script_dom_tracing.rs @@ -1302,3 +1302,28 @@ fn retraced_plugin_is_the_same_object_as_its_collection_handle() { assert_eq!(out, vec![json!(true); 5]); let _ = std::fs::remove_dir_all(base); } + +#[test] +fn loading_the_same_preset_in_bracket_form_does_not_trace_again() { + let base = folder("retrace-bracket-preset"); + // Silhouettes then [Default] leaves the tracing with the stored name `[Default]`. + for (first, second) in [("Default", "[Default]"), ("Silhouettes', '[Default]", "Default"), ("Silhouettes", "[silhouettes]")] { + let (mut s, _) = session(&base, false); + let out = log( + &mut s, + &base, + &format!( + "var o = app.activeDocument.rasterItems[0].trace().tracing.tracingOptions, names = ['{first}'];\ + for (var i = 0; i < names.length; i++) o.loadFromPreset(names[i]); vc.log(o.preset);" + ), + ); + assert_eq!(out, [json!(first.rsplit('\'').next().unwrap())], "{first}"); + let before = vectorcraft_format::save(&s.active().unwrap().doc, false); + let steps = undo_steps(&s); + let out = log(&mut s, &base, &format!("vc.log(app.activeDocument.pageItems[0].tracing.tracingOptions.loadFromPreset('{second}'));")); + assert_eq!(out, [json!(true)], "{first} then {second}"); + assert!(vectorcraft_format::save(&s.active().unwrap().doc, false) == before, "{first} then {second}: the document changed"); + assert_eq!(undo_steps(&s), steps, "{first} then {second}"); + } + let _ = std::fs::remove_dir_all(base); +} diff --git a/docs/mcp.md b/docs/mcp.md index f3931f6fb1..de0c12ac79 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3427,7 +3427,8 @@ through `$`: count the seam fills of an Abutting trace, `usedColorCount` counts the different fill and stroke paints, and `imageResolution` is the image's pixels per inch as placed, an error for an image placed at different resolutions across and down. Assigning an option, or `loadFromPreset(name)`, traces again with `imageTrace.make`, keeps the - source image and the view, and a value the tracing already has runs no command. Assigning `viewRaster` or + source image and the view, and a value the tracing already has runs no command; a built-in preset's name with or + without brackets, such as `Default` and `[Default]`, counts as the same preset. Assigning `viewRaster` or `viewVector` does not trace again: it runs `imageTrace.setView`. The `PluginItem`, `TracingObject` and `TracingOptions` follow the new object, and a run traces again at most 10,000 times. Tracing again throws `Cannot retrace a tracing containing added artwork`, with nothing changed, when the tracing holds an object its trace diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index db62489888..69cae1b168 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1118,7 +1118,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Scripts: `app.preferences` reads, stores and removes values by key with the type they were set as, keeps them across runs and restarts, and turns the warning before a picked script on with the key `ShowExternalJSXWarning`, and off only after the person answers Yes to a confirm (https://ai-scripting.docsforadobe.dev/jsobjref/Preferences/; the confirm is VectorCraft's own rule); `app` makes, joins, inverts and compares `Matrix` records (https://ai-scripting.docsforadobe.dev/jsobjref/Matrix/), rounding each joined value once from its exact sum of products, and runs Copy, Cut and Paste on the active document inside the run's transaction (https://ai-scripting.docsforadobe.dev/jsobjref/Application/). `crates/engine/src/tests/script_dom_prefs.rs`. - Scripts: `Document.pathItems` lists the paths and makes rectangles, rounded rectangles, ellipses, polygons, stars and empty paths with the defaults the help page https://ai-scripting.docsforadobe.dev/jsobjref/PathItems/ gives; each path's points, closed state, fill rule, area, length, guide state, selected points, fill and stroke colors, stroke options and transforms read and change as https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/, https://ai-scripting.docsforadobe.dev/jsobjref/PathPoints/ and https://ai-scripting.docsforadobe.dev/jsobjref/PathPoint/ describe them, and `RGBColor`, `CMYKColor`, `GrayColor`, `LabColor` and `NoColor` make colors (`docs/mcp.md`). `pathItems["name"]` reads a path by name as `pageItems` does, and `removeAll()` deletes nothing and throws when any path is on a locked artboard. A path takes the page item transforms, and `resize` also sets its stroke weight to a `changeLineWidths` percent from 0 to 100000 (at most 1000 points; a member of a compound sets the compound's stroke); gradients move with positions, so a `changeFillGradients` different from `changePositions` throws an error, as do `changeFillPatterns` and `changeStrokePattern` given as different values (`docs/mcp.md` lists these limits). Gradient stops are not there yet. A `PathPoint` of a path in an Objects on Path group goes stale when an edit of another path in the group moves it. `crates/engine/src/tests/script_dom_paths.rs`. - Scripts: `Document.placedItems` and `Document.rasterItems` list a document's linked and embedded images; `placedItems.add()` with a `File` assigned to `file` places an image linked, and `PlacedItem.relink(file)` and `embed()` relink and embed it, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItems/, https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItem/, https://ai-scripting.docsforadobe.dev/jsobjref/RasterItems/ and https://ai-scripting.docsforadobe.dev/jsobjref/RasterItem/ describe them. A raster item's bits per channel, channels, color space and transparency come from its encoded pixels' header. Only files the script may read, of at most 256 MiB and holding an image, are placed or relinked. Rasterizing and capturing are not there yet. `crates/engine/src/tests/script_dom_images.rs`. - - Scripts: `PlacedItem.trace()` and `RasterItem.trace()` make an Image Trace object and return it as a `PluginItem` whose `tracing` gives its path, anchor and color counts, the source image's resolution, `expandTracing()`, `releaseTracing()` and its `TracingOptions`; assigning an option or loading a preset traces it again, except that the view options (`viewRaster` and `viewVector`) only change the view, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PluginItem/, https://ai-scripting.docsforadobe.dev/jsobjref/TracingObject/ and https://ai-scripting.docsforadobe.dev/jsobjref/TracingOptions/ describe them. Option values are checked for type and range before any trace, a script cannot save a preset, and the options without a VectorCraft setting throw. The source image of a traced item is left out of `pageItems`, `placedItems` and `rasterItems`; a script reaches it through `PluginItem.tracing.sourceArt`. Renaming an ordinary group that holds an image first to `Image Trace`, or moving or duplicating an image to the bottom of an ordinary group with that name, throws an error. `crates/engine/src/tests/script_dom_tracing.rs`. + - Scripts: `PlacedItem.trace()` and `RasterItem.trace()` make an Image Trace object and return it as a `PluginItem` whose `tracing` gives its path, anchor and color counts, the source image's resolution, `expandTracing()`, `releaseTracing()` and its `TracingOptions`; assigning an option or loading a preset traces it again, except that the view options (`viewRaster` and `viewVector`) only change the view, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PluginItem/, https://ai-scripting.docsforadobe.dev/jsobjref/TracingObject/ and https://ai-scripting.docsforadobe.dev/jsobjref/TracingOptions/ describe them. Loading the built-in preset the tracing already has, by its name with or without brackets (`[Default]`), with unchanged options does not trace again. Option values are checked for type and range before any trace, a script cannot save a preset, and the options without a VectorCraft setting throw. The source image of a traced item is left out of `pageItems`, `placedItems` and `rasterItems`; a script reaches it through `PluginItem.tracing.sourceArt`. Renaming an ordinary group that holds an image first to `Image Trace`, or moving or duplicating an image to the bottom of an ordinary group with that name, throws an error. `crates/engine/src/tests/script_dom_tracing.rs`. - Scripts: a document's `default*` members (https://ai-scripting.docsforadobe.dev/jsobjref/Document/) read and set the fill, stroke and stroke options of the next object drawn through `appearance.setNewArt`, leaving the selection and its art as they were, and `scaleFactor` reads 1 (`docs/mcp.md`). `crates/engine/src/tests/script_dom_defaults.rs`. - Scripts: `app.undo()` and `app.redo()` undo and redo the edits the run made, and each document open before and after the run that it changed gets one undo step. `crates/engine/src/tests/script_dom.rs`. - Scripts: `document.textFrames` makes point type, area type and type on a path, and each text frame gives its kind, its contents, its text as text ranges with their characters, words and paragraphs (which can add text), their character attributes (size, leading, tracking, baseline shift, scales, rotation, underline, strikethrough, font) and paragraph attributes (alignment, indents, space before and after), outlines and point and area conversion; `app.textFonts` lists the fonts, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/TextFrameItems/, https://ai-scripting.docsforadobe.dev/jsobjref/TextFrameItem/, https://ai-scripting.docsforadobe.dev/jsobjref/TextRange/ and https://ai-scripting.docsforadobe.dev/jsobjref/TextFonts/ describe them (`docs/mcp.md`). Offsets count UTF-16 units, VectorCraft's own rule. Lines, tab stops and colors are not there yet. `crates/engine/src/tests/script_text.rs`. From 061a03686582773f46bb875c26b40feb39c5a0ed Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 09:25:47 -0800 Subject: [PATCH 2/2] Docs: loadFromPreset skips the trace only when the parameters match docs/mcp.md now says that loadFromPreset(name) runs no command only when the tracing's preset matches name (ignoring letter case and, for a built-in preset, brackets) and its current parameters equal the preset's, as options_load in crates/engine/src/script/dom/tracing.rs checks. --- docs/mcp.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/mcp.md b/docs/mcp.md index e98f4784e1..709c8c9505 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3621,8 +3621,10 @@ through `$`: count the seam fills of an Abutting trace, `usedColorCount` counts the different fill and stroke paints, and `imageResolution` is the image's pixels per inch as placed, an error for an image placed at different resolutions across and down. Assigning an option, or `loadFromPreset(name)`, traces again with `imageTrace.make`, keeps the - source image and the view, and a value the tracing already has runs no command; a built-in preset's name with or - without brackets, such as `Default` and `[Default]`, counts as the same preset. Assigning `viewRaster` or + source image and the view, and a value the tracing already has runs no command. `loadFromPreset(name)` runs no + command only when the tracing's preset is `name` and its current parameters equal that preset's. Preset names match + without regard to letter case, and a built-in preset's name with or without brackets, such as `Default` and + `[Default]`, counts as the same preset. Assigning `viewRaster` or `viewVector` does not trace again: it runs `imageTrace.setView`. The `PluginItem`, `TracingObject` and `TracingOptions` follow the new object, and a run traces again at most 10,000 times. Tracing again throws `Cannot retrace a tracing containing added artwork`, with nothing changed, when the tracing holds an object its trace