From b41cd40be92b5551e30d91ecdc64cfcf2aba7ae3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 23 Nov 2026 10:20:23 -0800 Subject: [PATCH] Scripts: app.startupPresetsList lists the startup presets addDocument takes app.startupPresetsList gives a new array of the startup preset names each read: the New Document profiles in the order the New Document dialog lists them, then Basic CMYK and Basic RGB. documents.addDocument and app.getPresetSettings take every name in it. --- crates/engine/src/script/dom/perspective.rs | 16 ++++++++++++-- .../src/tests/script_dom_perspective.rs | 22 +++++++++++++++++++ .../tests/it/script_host_vs_scriptcheck.rs | 3 ++- docs/mcp.md | 10 ++++++--- docs/target-app-parity.md | 2 +- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/script/dom/perspective.rs b/crates/engine/src/script/dom/perspective.rs index 6a697234d4..8521fff8f1 100644 --- a/crates/engine/src/script/dom/perspective.rs +++ b/crates/engine/src/script/dom/perspective.rs @@ -26,6 +26,10 @@ //! of more than 100 artboards, and the layout of a grid by column that no row count lays out the //! same. Changing the result changes nothing else. Each result counts toward the run's limit //! of `DocumentPreset` objects, as `new DocumentPreset()` does. +//! - `startupPresetsList` is an array of the startup preset names, each of which +//! `documents.addDocument` and `getPresetSettings` take: the New Document profiles in the order +//! the New Document dialog lists them, then `Basic CMYK` and `Basic RGB`. Each read gives a new +//! array, so changing it changes nothing else. //! - The workspace methods, `loadColorSettings`, `showPresets` and the perspective grid preset //! files are not available yet. @@ -33,7 +37,7 @@ use serde_json::json; use vectorcraft_js::{Data, HostError, HostMember}; use vectorcraft_tools::distort::perspective::{PerspectiveGrid, Plane}; -use super::{Answer, MAX_TEXT_BYTES, arg, later, method, named, num, on_doc, startup_preset, text, this_doc, with_doc}; +use super::{Answer, MAX_TEXT_BYTES, arg, get, later, method, named, num, on_doc, startup_preset, text, this_doc, with_doc}; use crate::script::{Host, Link}; type Result = std::result::Result; @@ -234,6 +238,14 @@ fn preset_settings(h: &Host, a: &[Data]) -> Answer { super::add_preset(h, out) } +/// The startup presets besides the New Document profiles, which give a document of one color mode. +const BASIC_PRESETS: [&str; 2] = ["Basic CMYK", "Basic RGB"]; + +/// `app.startupPresetsList`: the names of the startup presets, as a new array. +fn startup_presets(_: &Host, _: &[Data]) -> Answer { + Ok(Data::Array(crate::cmd::newdoc::profile_names().chain(BASIC_PRESETS).map(text).collect())) +} + /// The members this module adds to `Document`'s. pub(super) fn document_members(l: &Link) -> Vec<(String, HostMember)> { let mut m = named(vec![ @@ -249,7 +261,7 @@ pub(super) fn document_members(l: &Link) -> Vec<(String, HostMember)> { /// The members this module adds to `Application`'s. pub(super) fn application_members(l: &Link) -> Vec<(String, HostMember)> { - let mut m = named(vec![("getPresetSettings", method(l, preset_settings))]); + let mut m = named(vec![("getPresetSettings", method(l, preset_settings)), ("startupPresetsList", get(l, startup_presets))]); let missing = ["saveWorkspace", "switchWorkspace", "deleteWorkspace", "resetWorkspace", "loadColorSettings", "showPresets"]; m.extend(missing.into_iter().map(|n| later(l, "Application", n))); m diff --git a/crates/engine/src/tests/script_dom_perspective.rs b/crates/engine/src/tests/script_dom_perspective.rs index eebea33e7e..f8196d6663 100644 --- a/crates/engine/src/tests/script_dom_perspective.rs +++ b/crates/engine/src/tests/script_dom_perspective.rs @@ -276,6 +276,28 @@ fn get_preset_settings_given_back_to_add_document_makes_the_same_document() { } } +#[test] +fn startup_presets_list_names_presets_add_document_takes() { + let mut s = Session::new(); + let out = log( + &mut s, + "var l = app.startupPresetsList; vc.log(l); l.push('Mine'); l[0] = 'x'; vc.log(app.startupPresetsList.length === l.length - 1);\ + vc.log(app.startupPresetsList[0] !== 'x');\ + for (var i = 0; i < l.length - 1; i++) { var n = app.startupPresetsList[i]; var p = app.getPresetSettings(n);\ + var d = app.documents.addDocument(n); vc.log([n, d.width === p.width && d.documentColorSpace === p.colorMode]); }", + ); + let names: Vec<&str> = out[0].as_array().map(|a| a.iter().filter_map(Value::as_str).collect()).unwrap_or_default(); + for name in ["Print", "Web", "Basic CMYK", "Basic RGB"] { + assert!(names.contains(&name), "{name}: {names:?}"); + } + assert_eq!(out[1..3], [json!(true), json!(true)]); + assert_eq!(out.len(), 3 + names.len()); + for (name, made) in names.iter().zip(&out[3..]) { + assert_eq!(made, &json!([name, true]), "{name}"); + } + assert_eq!(s.documents().len(), names.len()); +} + #[test] fn members_not_built_yet_say_so() { let mut s = doc(); diff --git a/crates/engine/tests/it/script_host_vs_scriptcheck.rs b/crates/engine/tests/it/script_host_vs_scriptcheck.rs index b76b8fb37a..7ac23d41ae 100644 --- a/crates/engine/tests/it/script_host_vs_scriptcheck.rs +++ b/crates/engine/tests/it/script_host_vs_scriptcheck.rs @@ -84,7 +84,8 @@ const INSIDE: &[(&str, &str)] = &[ "Application.prototype.", "activeDocument activeDocument= beep beep= constructor coordinateSystem coordinateSystem= deleteWorkspace \ deleteWorkspace= documents getIsFileOpen getPresetSettings loadColorSettings loadColorSettings= resetWorkspace \ - resetWorkspace= saveWorkspace saveWorkspace= selection showPresets showPresets= switchWorkspace switchWorkspace= \ + resetWorkspace= saveWorkspace saveWorkspace= selection showPresets showPresets= startupPresetsList switchWorkspace \ + switchWorkspace= \ typename", ), ("DocumentPreset.", "prototype"), diff --git a/docs/mcp.md b/docs/mcp.md index b879148df5..39a91da05b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2741,8 +2741,8 @@ app through the global object `vc`, and writes to the Script Console and runs ot `GroupItems.createFromFile` throw an error that says they are not available yet. - A document also has `showPerspectiveGrid()`, `hidePerspectiveGrid()`, `getPerspectiveActivePlane()`, `setActivePlane(gridPlane)` and `selectPerspectivePreset(gridType, presetName)` - (https://ai-scripting.docsforadobe.dev/jsobjref/Document/), and `app` has `getPresetSettings(preset)` - (https://ai-scripting.docsforadobe.dev/jsobjref/Application/). `showPerspectiveGrid` and `hidePerspectiveGrid` + (https://ai-scripting.docsforadobe.dev/jsobjref/Document/), and `app` has `getPresetSettings(preset)` and + `startupPresetsList` (https://ai-scripting.docsforadobe.dev/jsobjref/Application/). `showPerspectiveGrid` and `hidePerspectiveGrid` run `perspective.grid.show`, and `setActivePlane` runs `perspective.plane.set`; none of them adds an undo step, and a failed run puts the grid back. `selectPerspectivePreset` runs `perspective.grid.preset` with a built-in or saved preset of `perspective.presets.list` (its name in any case), which shows the grid and is part of the run's undo @@ -2758,7 +2758,11 @@ app through the global object `vc`, and writes to the Script Console and runs ot preset's units are not one of the six `RulerUnits` values a new document takes, `rasterResolution` when the preset's PPI is not 72, 150 or 300, `numArtboards` and `artboardRowsOrCols` when the preset has more than 100 artboards, and `artboardRowsOrCols` alone for a grid by column that no row count lays out the same, so - `addDocument` with the same preset keeps the preset's own. As the Document page describes, + `addDocument` with the same preset keeps the preset's own. `startupPresetsList` is a read-only array of the + startup preset names, each of which `addDocument` and `getPresetSettings` take: the New Document profiles in the + order the New Document dialog lists them (`Mobile`, `Web`, `Print`, `Film & Video`, `Art & Illustration`, + `Branding`, `Social`), then `Basic CMYK` and `Basic RGB`. This order is VectorCraft's own. Each read gives a new + array, so changing it changes nothing else. As the Document page describes, `showPerspectiveGrid` and `setActivePlane` give `true` on success, and `hidePerspectiveGrid` gives `true` when it hides a grid and `false` when the grid was already hidden. VectorCraft's own rules: `showPerspectiveGrid` and `setActivePlane` also give `true` when nothing changed. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 2d098d4977..0e25ded443 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1026,7 +1026,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Scripts: File › Scripts › Other Script… and `script.run` run a JavaScript file against the open documents as one transaction with one undo step for each changed document. A failed or stopped run puts every document back. `crates/engine/src/tests/script_run.rs`. - Scripts: the global `app` gives the open documents, new documents from a startup preset and a `DocumentPreset`, the active document, each document's selection and its page items with their names, notes, visibility, lock, opacity, position, size, bounds and stacking order, and moves and copies them into or beside other objects, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Application/, https://ai-scripting.docsforadobe.dev/jsobjref/Documents/, https://ai-scripting.docsforadobe.dev/jsobjref/DocumentPreset/, https://ai-scripting.docsforadobe.dev/jsobjref/Document/, https://ai-scripting.docsforadobe.dev/jsobjref/PageItems/, https://ai-scripting.docsforadobe.dev/jsobjref/PageItem/ and https://ai-scripting.docsforadobe.dev/jsobjref/GroupItem/ describe them; each change runs a command inside the run's transaction (`docs/mcp.md`). Paths, type and the other classes are not there yet, except that `CompoundPathItem.pathItems` reads the paths of a compound path. `crates/engine/src/tests/script_dom.rs`. - Scripts: a document's layers and sublayers with their options, stacking and current layer, its groups and compound paths with clipping masks and new empty groups, and its artboards with their rectangles, names, ruler origins and display options, added, inserted, removed and made active, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Layer/, https://ai-scripting.docsforadobe.dev/jsobjref/Layers/, https://ai-scripting.docsforadobe.dev/jsobjref/GroupItems/, https://ai-scripting.docsforadobe.dev/jsobjref/CompoundPathItem/, https://ai-scripting.docsforadobe.dev/jsobjref/Artboard/ and https://ai-scripting.docsforadobe.dev/jsobjref/Artboards/ describe them (`docs/mcp.md`). Views are not there yet. `crates/engine/src/tests/script_dom.rs`, `crates/ui-egui/src/tests/script_run.rs`. - - Scripts: a document's perspective grid is shown, hidden, given its active plane and reset to a built-in or saved preset of the type the script names, and `app.getPresetSettings` gives the settings of a startup preset as a `DocumentPreset`, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Document/ and https://ai-scripting.docsforadobe.dev/jsobjref/Application/ list them (`docs/mcp.md`). Showing, hiding and the active plane add no undo step in a script run, as outside one. Workspaces, `loadColorSettings`, `showPresets` and perspective grid preset files are not there yet. `crates/engine/src/tests/script_dom_perspective.rs`. + - Scripts: a document's perspective grid is shown, hidden, given its active plane and reset to a built-in or saved preset of the type the script names, and `app.getPresetSettings` gives the settings of a startup preset as a `DocumentPreset`, and `app.startupPresetsList` lists the startup presets' names, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Document/ and https://ai-scripting.docsforadobe.dev/jsobjref/Application/ list them (`docs/mcp.md`). Showing, hiding and the active plane add no undo step in a script run, as outside one. Workspaces, `loadColorSettings`, `showPresets` and perspective grid preset files are not there yet. `crates/engine/src/tests/script_dom_perspective.rs`. - Scripts: Window › Script Console shows each run's `$.write` and `$.writeln` output, `vc.log` entries, uncaught error with the script's name, line and column, and a report of its time, host calls and slowest commands, keeping at most 2,048 lines and counting the lines it dropped. `script.run`'s report carries the same data, and `script.console`, `script.console.clear` and `ui.copyScriptConsole` read, clear and copy it. `crates/engine/src/tests/script_console.rs`. - Scripts: the status bar translates its own words around a failed run's error and the app's own error messages, and shows text the script threw itself (a value, an error it made, or an error whose name or message it changed) as it is, even when that text reads like one of the app's messages. `script.run`'s report gives `messageOrigin` (`script` or `built-in`), and the advice about objects other applications give their scripts follows only the app's own reference errors. VectorCraft's own rule. `crates/js/src/interp_tests.rs`, `crates/engine/src/tests/script_run.rs`, `crates/ui-egui/src/chrome/tests.rs`. - Scripts: the `$` object has the other members the Dollar object page lists (https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/), from `$.about()` to `$.version`, and scripts have the global `localize(object, ...values)` (https://extendscript.docsforadobe.dev/extendscript-tools-features/localizing-extendscript-strings/), `toSource(value)` and `Object.prototype.toSource()`. Each run starts with the interface's locale, and what a script changes in `$` lasts only for that run. `crates/engine/src/tests/script_dollar.rs`, `crates/js/src/extension_tests.rs`.