diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index 4fc1b83c29..c7988b1731 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -225,7 +225,7 @@ pub fn specs() -> Vec { "Clear", ["Edit"], Some("Delete"), - "{ids?, guides?: bool (with ids: also delete the selected ruler guides), keepJoined?: bool (without ids: the direct-selected anchors of a path with no selected segment are removed as path.removeAnchors removes them, without opening the path, and the next anchor along is selected (the one before at an open path's end); default: prefs deleteKeepsPathsJoined), keepEmpty?: bool (keep a compound path left with no members)} delete the objects `ids`, else the selection (fully selected objects and direct-selected anchors together, else ruler guides; a compound-path member selected on its own is deleted alone, and a compound left with no members goes too unless keepEmpty); without ids, refused while an object of a symbol instance's art is selected", + "{ids?, guides?: bool (with ids: also delete the selected ruler guides), keepJoined?: bool (without ids: the direct-selected anchors of a path with no selected segment are removed as path.removeAnchors removes them, without opening the path, and the next anchor along is selected (the one before at an open path's end); default: prefs deleteKeepsPathsJoined), keepEmpty?: bool (keep a compound path left with no members)} delete the objects `ids`, else the selection (fully selected objects and direct-selected anchors together, else ruler guides; a compound-path member selected on its own is deleted alone, and a compound left with no members goes too unless keepEmpty); a clipping group or layer left without art releases its mask in the same undo step; without ids, refused while an object of a symbol instance's art is selected", has_selection_or_guides, clear ), @@ -1255,6 +1255,20 @@ fn cut_direct_selection(s: &mut Session, roots: &[NodeId]) -> Result { ok() } +pub(super) fn clipped_ancestors(d: &Document, ids: impl IntoIterator) -> BTreeSet { + ids.into_iter().flat_map(|id| d.ancestry(id).unwrap_or_default()).filter(|id| d.node(*id).is_some_and(Node::clips)).collect() +} + +pub(super) fn release_empty_clips(d: &mut Document, ids: BTreeSet) { + for id in ids { + if let Some(n) = d.node_mut(id) + && n.children().is_some_and(|c| c.iter().all(|n| n.is_ruler_guide())) + { + n.set_clips(false); + } + } +} + fn clear(s: &mut Session, p: &Value) -> Result { let guides = switch_or(p, "guides", false, "edit.clear")?; let keep_empty = switch_or(p, "keepEmpty", false, "edit.clear")?; @@ -1291,6 +1305,7 @@ fn clear(s: &mut Session, p: &Value) -> Result { return ok(); } s.edit("Clear", |d, sel| { + let clipped = clipped_ancestors(d, ids.iter().copied()); let parents: Vec<_> = if keep_empty { Vec::new() } else { @@ -1306,6 +1321,7 @@ fn clear(s: &mut Session, p: &Value) -> Result { let gone = sel.guides.clone(); d.retain_guides(sel, |g| !g.id.is_some_and(|id| gone.contains(&id))); } + release_empty_clips(d, clipped); if is_explicit { sel.remove_all(ids.iter().copied()); sel.prune(d); diff --git a/crates/engine/src/cmd/path.rs b/crates/engine/src/cmd/path.rs index a6f85d0c46..190c8b5810 100644 --- a/crates/engine/src/cmd/path.rs +++ b/crates/engine/src/cmd/path.rs @@ -1921,6 +1921,7 @@ pub(crate) fn delete_anchors_joined(s: &mut Session, p: &Value, keep_joined: boo .copied() .filter(|id| !d.ancestry(*id).unwrap_or_default().iter().rev().skip(1).any(|ancestor| targets.contains(ancestor))) .collect(); + let clipped = super::edit::clipped_ancestors(d, whole_ids.iter().chain(sel.keys()).chain(segments.keys()).copied()); // The compound paths that hold a deleted object; one left with no members goes too, unless `keepEmpty`. let compounds: BTreeSet = if keep_empty { BTreeSet::new() @@ -2002,6 +2003,7 @@ pub(crate) fn delete_anchors_joined(s: &mut Session, p: &Value, keep_joined: boo d.remove(p)?; } } + super::edit::release_empty_clips(d, clipped); selection.set(survivors); for (id, next) in following { if !next.is_empty() { diff --git a/crates/engine/src/script/actions.rs b/crates/engine/src/script/actions.rs index 88b531cd30..8728bd76fb 100644 --- a/crates/engine/src/script/actions.rs +++ b/crates/engine/src/script/actions.rs @@ -256,9 +256,8 @@ fn do_script(h: &Host, a: &[Data]) -> std::result::Result { // A document whose active artboard the script chose uses that choice, not the one the run // started with. let chosen = h.session.borrow().active().and_then(|st| { - let (_, index) = h.dom.chosen_artboards.borrow().iter().find(|(uid, _)| *uid == st.uid).copied()?; - let index = st.active_artboard.and_then(|id| st.doc.artboards.iter().position(|a| a.id == id)).unwrap_or(index); - Some((st.uid, index)) + h.dom.chosen_artboards.borrow().iter().find(|(uid, reverts)| *uid == st.uid && *reverts == st.reverts)?; + Some((st.uid, super::dom::active_artboard(st))) }); let active = match &chosen { Some(chosen) => std::slice::from_ref(chosen), diff --git a/crates/engine/src/script/dom.rs b/crates/engine/src/script/dom.rs index 0c35c7ec20..dbb8c9aff3 100644 --- a/crates/engine/src/script/dom.rs +++ b/crates/engine/src/script/dom.rs @@ -218,8 +218,8 @@ pub(super) struct State { layers: RefCell>, /// The uids of the documents whose active artboard `setActiveArtboardIndex` changed. pub(super) active_artboards: RefCell>, - /// Each document's uid and the index last chosen with `setActiveArtboardIndex`, changed or not. - pub(super) chosen_artboards: RefCell>, + /// Each document's uid and revert generation when `setActiveArtboardIndex` last chose it. + pub(super) chosen_artboards: RefCell>, /// Each open document's uid and the index of its active artboard when the run started. pub(super) boards_at_start: Vec<(u64, usize)>, text: text::TextState, @@ -2012,7 +2012,7 @@ fn items_doc(h: &Host, a: &[Data]) -> std::result::Result { } fn items_length(h: &Host, a: &[Data]) -> Answer { - if layers::is_scoped(a) { + if layers::is_scoped(a, "PageItems") { return layers::scoped_length(h, a); } let doc = items_doc(h, a)?; @@ -2021,7 +2021,7 @@ fn items_length(h: &Host, a: &[Data]) -> Answer { } fn items_typename(h: &Host, a: &[Data]) -> Answer { - if layers::is_scoped(a) { + if layers::is_scoped(a, "PageItems") { return layers::scoped_typename(h, a); } items_doc(h, a)?; @@ -2029,12 +2029,16 @@ fn items_typename(h: &Host, a: &[Data]) -> Answer { } fn items_to_string(h: &Host, a: &[Data]) -> Answer { + if layers::is_scoped(a, "PageItems") { + layers::scoped_typename(h, a)?; + return Ok(text("[PageItems]")); + } items_doc(h, a)?; Ok(text("[PageItems]")) } fn items_parent(h: &Host, a: &[Data]) -> Answer { - if layers::is_scoped(a) { + if layers::is_scoped(a, "PageItems") { return layers::scoped_parent(h, a); } let doc = items_doc(h, a)?; @@ -2056,7 +2060,7 @@ fn position(n: f64) -> Option { /// number but not an array index, such as `-1` or `1.5`, reaches the indexer as a number and is /// looked up as that name, giving `undefined` when no object has it. fn items_at(h: &Host, a: &[Data]) -> Answer { - if layers::is_scoped(a) { + if layers::is_scoped(a, "PageItems") { return layers::scoped_at(h, a); } let doc = items_doc(h, a)?; @@ -2082,7 +2086,7 @@ fn item_at(h: &Host, doc: Doc, i: usize) -> Data { } fn items_by_name(h: &Host, a: &[Data]) -> Answer { - if layers::is_scoped(a) { + if layers::is_scoped(a, "PageItems") { return layers::scoped_by_name(h, a); } let doc = items_doc(h, a)?; @@ -2101,7 +2105,7 @@ fn items_named(h: &Host, doc: Doc, name: &str) -> Answer { } fn items_index(h: &Host, a: &[Data]) -> Answer { - if layers::is_scoped(a) { + if layers::is_scoped(a, "PageItems") { return layers::scoped_index(h, a); } match arg(a, 1) { @@ -2121,7 +2125,7 @@ fn items_index(h: &Host, a: &[Data]) -> Answer { /// locked object, or one in a hidden or locked layer or group, stops it before anything is deleted, /// and so does an object on a locked artboard. fn items_remove_all(h: &Host, a: &[Data]) -> Answer { - if layers::is_scoped(a) { + if layers::is_scoped(a, "PageItems") { return layers::scoped_remove_all(h, a); } let doc = items_doc(h, a)?; diff --git a/crates/engine/src/script/dom/colors.rs b/crates/engine/src/script/dom/colors.rs index b9f0bb3a30..4de02e881b 100644 --- a/crates/engine/src/script/dom/colors.rs +++ b/crates/engine/src/script/dom/colors.rs @@ -39,7 +39,7 @@ const CLASSES: &[(&str, &[&str])] = &[ ("PatternColor", &[]), ]; -fn color_object(class: &str, values: &[(&str, f64)]) -> Data { +pub(super) fn color_object(class: &str, values: &[(&str, f64)]) -> Data { let mut items = vec![("typename".to_string(), text(class))]; items.extend(values.iter().map(|(k, v)| ((*k).to_string(), num(*v)))); Data::Object(items) diff --git a/crates/engine/src/script/dom/layers.rs b/crates/engine/src/script/dom/layers.rs index 3cb0686be9..cf06be541a 100644 --- a/crates/engine/src/script/dom/layers.rs +++ b/crates/engine/src/script/dom/layers.rs @@ -20,7 +20,7 @@ //! - `locked` true means the layer is locked. //! - `clipped = true` makes the group's topmost object, which must be a path, a compound path or //! type, its clipping path, as the Layers panel's clipping mask button does; `false` releases it. -//! - A layer's `color` is an object `{red, green, blue}` with values from 0 to 255. +//! - A layer's `color` is an `RGBColor` object with values from 0 to 255. //! - `CompoundPathItems.add()` makes an empty compound path. The first path a script moves into it //! gives it its paint, as Make Compound Path takes the paint of a path it joins. //! - `artboards.add` and `artboards.insert` stop at [`super::MAX_ARTBOARDS`] artboards in a @@ -66,6 +66,8 @@ enum Kind { Group, /// Compound paths (`CompoundPathItem`). Compound, + /// Paths (`PathItem`). + Path, } impl Kind { @@ -74,6 +76,7 @@ impl Kind { Kind::Any => "PageItems", Kind::Group => "GroupItems", Kind::Compound => "CompoundPathItems", + Kind::Path => "PathItems", } } @@ -82,6 +85,7 @@ impl Kind { Kind::Any => typename(n).is_some(), Kind::Group => typename(n) == Some("GroupItem"), Kind::Compound => typename(n) == Some("CompoundPathItem"), + Kind::Path => typename(n) == Some("PathItem"), } } } @@ -247,8 +251,7 @@ fn layer_set_opacity(h: &Host, a: &[Data]) -> Answer { fn layer_color(h: &Host, a: &[Data]) -> Answer { read_layer(h, a, |_, n| { let [r, g, b] = layer_flags(n).3.rgb(); - let item = |k: &str, v: u8| (k.to_string(), num(f64::from(v))); - Ok(Data::Object(vec![item("red", r), item("green", g), item("blue", b)])) + Ok(super::colors::color_object("RGBColor", &[("red", f64::from(r)), ("green", f64::from(g)), ("blue", f64::from(b))])) }) } @@ -290,9 +293,13 @@ fn layer_to_string(h: &Host, a: &[Data]) -> Answer { fn layer_z_position(h: &Host, a: &[Data]) -> Answer { let (doc, id) = this_layer(h, a)?; let at = with_doc(h, doc, |_, st| { - let list = layer_list(&st.doc, st.doc.parent_of(id)); - list.iter().position(|l| *l == id).map(|i| list.len() - i) - }); + let parent = st.doc.parent_of(id); + let count = parent.map_or(st.doc.layers.len(), |p| st.doc.children(Some(p)).map_or(0, Vec::len)); + h.charge_call(count as u64)?; + let list = layer_list(&st.doc, parent); + h.charge_call(list.len() as u64)?; + Ok::<_, HostError>(list.iter().position(|l| *l == id).map(|i| list.len() - i)) + })?; at.map(|i| num(float(i as u64))).ok_or_else(|| HostError::Error(STALE_LAYER.into())) } @@ -687,10 +694,13 @@ fn art_list(h: &Host, st: &DocState, kind: Kind, container: Option) -> R Ok(ids) } -/// The `PageItems` of a layer, group or compound path: a [`super`] `PageItems` object whose handle -/// names the container. -pub(super) fn is_scoped(a: &[Data]) -> bool { - host_ref_parts(arg(a, 0)).is_some_and(|(c, handle)| c == "PageItems" && handle.len() == 5) +/// Whether a `PageItems` or `PathItems` object's handle names its container. +pub(super) fn is_scoped(a: &[Data], class: &str) -> bool { + host_ref_parts(arg(a, 0)).is_some_and(|(c, handle)| c == class && handle.len() == 5) +} + +fn scoped_kind(a: &[Data]) -> Kind { + if host_ref_parts(arg(a, 0)).is_some_and(|(c, _)| c == "PathItems") { Kind::Path } else { Kind::Any } } /// How many times File › Revert has reloaded the document with uid `uid`. @@ -804,30 +814,29 @@ fn art_remove_all(h: &Host, a: &[Data], kind: Kind) -> Answer { Ok(Data::Undefined) } -/// The scoped `PageItems` of a container, which `PageItems`' members hand over to when their -/// handle names one ([`is_scoped`]). +/// The scoped art of a container, read by `PageItems` and `PathItems` ([`is_scoped`]). pub(super) fn scoped_length(h: &Host, a: &[Data]) -> Answer { - art_length(h, a, Kind::Any) + art_length(h, a, scoped_kind(a)) } pub(super) fn scoped_parent(h: &Host, a: &[Data]) -> Answer { - art_parent(h, a, Kind::Any) + art_parent(h, a, scoped_kind(a)) } pub(super) fn scoped_at(h: &Host, a: &[Data]) -> Answer { - art_at(h, a, Kind::Any) + art_at(h, a, scoped_kind(a)) } pub(super) fn scoped_by_name(h: &Host, a: &[Data]) -> Answer { - art_by_name(h, a, Kind::Any) + art_by_name(h, a, scoped_kind(a)) } pub(super) fn scoped_index(h: &Host, a: &[Data]) -> Answer { - art_index(h, a, Kind::Any) + art_index(h, a, scoped_kind(a)) } pub(super) fn scoped_remove_all(h: &Host, a: &[Data]) -> Answer { - art_remove_all(h, a, Kind::Any) + art_remove_all(h, a, scoped_kind(a)) } fn groups_length(h: &Host, a: &[Data]) -> Answer { @@ -868,14 +877,12 @@ fn compounds_remove_all(h: &Host, a: &[Data]) -> Answer { } fn art_typename(h: &Host, a: &[Data], kind: Kind) -> Answer { - let (doc, c) = art_scope(h, arg(a, 0), kind.class())?; - // A compound path's `pathItems` are its `PageItems`: it holds only paths. - let compound = c.is_some_and(|c| with_doc(h, doc, |_, st| st.doc.node(c).is_some_and(|n| matches!(n.kind, NodeKind::Compound { .. })))); - Ok(text(if compound && kind == Kind::Any { "PathItems" } else { kind.class() })) + art_scope(h, arg(a, 0), kind.class())?; + Ok(text(kind.class())) } pub(super) fn scoped_typename(h: &Host, a: &[Data]) -> Answer { - art_typename(h, a, Kind::Any) + art_typename(h, a, scoped_kind(a)) } fn groups_typename(h: &Host, a: &[Data]) -> Answer { art_typename(h, a, Kind::Group) @@ -938,6 +945,10 @@ fn held_page_items(h: &Host, a: &[Data]) -> Answer { held(h, a, Kind::Any) } +fn held_paths(h: &Host, a: &[Data]) -> Answer { + held(h, a, Kind::Path) +} + fn held_groups(h: &Host, a: &[Data]) -> Answer { held(h, a, Kind::Group) } @@ -977,6 +988,7 @@ fn group_set_clipped(h: &Host, a: &[Data]) -> Answer { if now == on { return Ok(Data::Undefined); } + super::refuse_protected_edit(h, item)?; if !ok { return Err(HostError::Error(format!("Cannot change GroupItem {}: it is hidden or locked", item.id.0))); } @@ -1002,7 +1014,7 @@ pub(super) fn members(class: &str, l: &Link) -> Vec { m.extend(["pathItems", "textFrames", "symbolItems", "placedItems", "rasterItems"].map(|m| later(l, "GroupItem", m))); m } - "CompoundPathItem" => named(vec![("pathItems", get(l, held_page_items), listed("PathItems"))]), + "CompoundPathItem" => named(vec![("pathItems", get(l, held_paths), listed("PathItems"))]), _ => Vec::new(), } } @@ -1390,10 +1402,11 @@ fn boards_set_active(h: &Host, a: &[Data]) -> Answer { } { let mut chosen = h.dom.chosen_artboards.borrow_mut(); - if let Some((_, index)) = chosen.iter_mut().find(|(uid, _)| *uid == doc.uid) { - *index = i; + let reverts = reverts_of(h, doc.uid); + if let Some((_, generation)) = chosen.iter_mut().find(|(uid, _)| *uid == doc.uid) { + *generation = reverts; } else { - chosen.push((doc.uid, i)); + chosen.push((doc.uid, reverts)); } } if i != now { diff --git a/crates/engine/src/script/dom/paths.rs b/crates/engine/src/script/dom/paths.rs index e4f6bb203e..4de44ee6c2 100644 --- a/crates/engine/src/script/dom/paths.rs +++ b/crates/engine/src/script/dom/paths.rs @@ -385,26 +385,41 @@ pub(super) fn doc_path_items(h: &super::Host, a: &[Data]) -> Answer { } fn items_doc(h: &super::Host, a: &[Data]) -> std::result::Result { + if super::layers::is_scoped(a, "PathItems") { + return Err(HostError::Error("creating paths in a compound path is not available yet; move a path into it".into())); + } doc_of(h, arg(a, 0), "PathItems") } /// `typename` of the paths of a document that is still open. fn items_typename(h: &super::Host, a: &[Data]) -> Answer { + if super::layers::is_scoped(a, "PathItems") { + return super::layers::scoped_typename(h, a); + } items_doc(h, a)?; Ok(Data::String("PathItems".into())) } fn items_length(h: &super::Host, a: &[Data]) -> Answer { + if super::layers::is_scoped(a, "PathItems") { + return super::layers::scoped_length(h, a); + } let doc = items_doc(h, a)?; Ok(num(float(with_doc(h, doc, |_, st| path_items(h, st).len()) as u64))) } fn items_parent(h: &super::Host, a: &[Data]) -> Answer { + if super::layers::is_scoped(a, "PathItems") { + return super::layers::scoped_parent(h, a); + } let doc = items_doc(h, a)?; Ok(host_ref("Document", &[float(h.run), float(doc.uid)])) } fn items_at(h: &super::Host, a: &[Data]) -> Answer { + if super::layers::is_scoped(a, "PathItems") { + return super::layers::scoped_at(h, a); + } let doc = items_doc(h, a)?; let Data::Number(n) = arg(a, 1) else { return Ok(Data::Undefined) }; let Some(i) = whole(*n).and_then(|i| usize::try_from(i).ok()) else { return Ok(Data::Undefined) }; @@ -412,6 +427,9 @@ fn items_at(h: &super::Host, a: &[Data]) -> Answer { } fn items_by_name(h: &super::Host, a: &[Data]) -> Answer { + if super::layers::is_scoped(a, "PathItems") { + return super::layers::scoped_by_name(h, a); + } let doc = items_doc(h, a)?; let Data::String(name) = arg(a, 1) else { return Err(HostError::Type("give a name, as a string".into())) }; with_doc(h, doc, |_, st| { @@ -436,6 +454,9 @@ fn items_index(h: &super::Host, a: &[Data]) -> Answer { /// `pathItems.removeAll()`: deletes every path of the document in one command. A hidden or locked /// path, or one in a hidden or locked layer or group, stops it before anything is deleted. fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer { + if super::layers::is_scoped(a, "PathItems") { + return super::layers::scoped_remove_all(h, a); + } let doc = items_doc(h, a)?; let (ids, refused) = with_doc(h, doc, |_, st| { let ids = path_items(h, st); @@ -1885,6 +1906,7 @@ pub(super) fn classes(l: &Link) -> Vec { None, named(vec![ ("typename", get(l, items_typename), typed("string")), + ("toString", super::class_text("PathItems"), returns("string", &[])), ("length", get(l, items_length), typed("number")), ("parent", get(l, items_parent), typed("Document")), ("index", method(l, items_index), returns("PathItem", &[("itemKey", "*")])), diff --git a/crates/engine/src/tests/script_actions.rs b/crates/engine/src/tests/script_actions.rs index 507c866ee4..ea399d2fd2 100644 --- a/crates/engine/src/tests/script_actions.rs +++ b/crates/engine/src/tests/script_actions.rs @@ -300,11 +300,42 @@ fn steps_use_the_chosen_index_when_the_chosen_artboard_is_deleted() { let was: Vec<_> = s.active().unwrap().doc.artboards.iter().map(|a| a.rect).collect(); make_active(&mut s, 2); let actions = set(&[("Fit", vec![json!({"command": "artboard.fitToSelection"})])]); - log_with(&mut s, "var b = app.activeDocument.artboards; b.setActiveArtboardIndex(2); b.remove(2); app.doScript('Fit', 'Set');", &actions); + let report = run_with( + &mut s, + "var b = app.activeDocument.artboards; b.setActiveArtboardIndex(2); b.remove(2);\ + vc.log(b.getActiveArtboardIndex()); app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;\ + vc.log(app.activeDocument.selection[0].position); app.doScript('Fit', 'Set');", + &actions, + ) + .unwrap(); + assert_eq!(report["log"], json!([0, [10, 10]])); + assert_eq!(report["activeArtboards"], json!([{"document": 0, "artboard": 0}])); let now: Vec<_> = s.active().unwrap().doc.artboards.iter().map(|a| a.rect).collect(); assert_eq!(now.len(), 2); - assert_eq!(now[0], was[0], "the first artboard is unchanged"); - assert_ne!(now[1], was[1], "the last remaining artboard is fitted"); + assert_ne!(now[0], was[0], "the fallback artboard is fitted"); + assert_eq!(now[1], was[1], "the other artboard is unchanged"); +} + +#[test] +fn steps_discard_the_chosen_artboard_after_revert() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 100, "height": 100, "units": "Points", "artboards": 3})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 20, "height": 30})).unwrap(); + let folder = vectorcraft_testkit::TempDir::new("script-actions-revert-artboard"); + let path = folder.join("saved.vectorcraft"); + s.execute("document.save", &json!({"path": path.to_string_lossy()})).unwrap(); + let was: Vec<_> = s.active().unwrap().doc.artboards.iter().map(|a| a.rect).collect(); + make_active(&mut s, 2); + let actions = set(&[("Fit", vec![json!({"command": "artboard.fitToSelection"})])]); + log_with( + &mut s, + "app.activeDocument.artboards.setActiveArtboardIndex(0); app.activeDocument.pageItems[0].name = 'changed'; vc.run('file.revert');\ + app.activeDocument.selection = app.activeDocument.pageItems[0]; app.doScript('Fit', 'Set');", + &actions, + ); + let now: Vec<_> = s.active().unwrap().doc.artboards.iter().map(|a| a.rect).collect(); + assert_eq!(now[..2], was[..2]); + assert_ne!(now[2], was[2], "playback uses the run's original index after revert"); } /// A recorded `command.batch` step that names its `artboard` gives it to its steps that name none, diff --git a/crates/engine/src/tests/script_dom.rs b/crates/engine/src/tests/script_dom.rs index 215217d011..0945618b88 100644 --- a/crates/engine/src/tests/script_dom.rs +++ b/crates/engine/src/tests/script_dom.rs @@ -2633,6 +2633,71 @@ fn scoped_collections_index_by_number() { assert!(e.contains("Not found"), "{e}"); } +#[test] +fn scoped_collection_methods_reject_the_other_collection_class() { + let (mut s, a, b) = doc(); + s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + s.execute("object.compoundPath.make", &json!({})).unwrap(); + rect(&mut s, 200.0, 20.0, 30.0, 40.0); + let before = s.active().unwrap().doc.clone(); + let steps = undo_steps(&s); + for (class, receiver) in + [("PathItems", "app.activeDocument.layers[0].pageItems"), ("PageItems", "app.activeDocument.compoundPathItems[0].pathItems")] + { + for call in ["removeAll.call(r)", "getByName.call(r, '')", "index.call(r, 0)"] { + let source = format!("var r = {receiver}; {class}.prototype.{call};"); + let error = failure(&mut s, &source); + assert!(error.contains(&format!("not a {class}")), "{source}: {error}"); + assert_eq!(s.active().unwrap().doc, before); + assert_eq!(undo_steps(&s), steps); + } + for property in ["typename", "length", "parent"] { + let source = format!("Object.getOwnPropertyDescriptor({class}.prototype, '{property}').get.call({receiver});"); + let error = failure(&mut s, &source); + assert!(error.contains(&format!("not a {class}")), "{source}: {error}"); + } + } + assert_eq!(s.active().unwrap().doc, before); + assert_eq!(undo_steps(&s), steps); +} + +#[test] +fn clear_releases_a_group_after_removing_its_last_compound_mask_member() { + for mode in ["whole", "anchors", "mixed"] { + let (mut s, a, b) = doc(); + s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + s.execute("object.compoundPath.make", &json!({})).unwrap(); + let compound = s.active().unwrap().doc.parent_of(a).unwrap(); + s.execute("edit.clear", &json!({"ids": [b.0]})).unwrap(); + s.execute("select.set", &json!({"ids": [compound.0]})).unwrap(); + let group = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap()); + run(&mut s, "app.activeDocument.groupItems[0].clipped = true;").unwrap(); + let other = rect(&mut s, 200.0, 20.0, 30.0, 40.0); + s.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + if mode == "anchors" { + s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 0], [0, 1], [0, 2]]})).unwrap(); + } else if mode == "mixed" { + s.execute("select.anchors", &json!({"id": other.0, "anchors": [[0, 0]], "mode": "add"})).unwrap(); + } + let before = s.active().unwrap().doc.clone(); + let selection = s.active().unwrap().selection.clone(); + let steps = undo_steps(&s); + s.execute("edit.clear", &json!({})).unwrap(); + let d = &s.active().unwrap().doc; + assert!(d.node(a).is_none() && d.node(compound).is_none(), "{mode}"); + assert!(d.node(other).is_some(), "{mode}"); + assert!(d.node(group).unwrap().children().unwrap().is_empty(), "{mode}"); + assert!(!d.node(group).unwrap().clips(), "{mode}"); + assert_eq!(undo_steps(&s), steps + 1, "{mode}"); + let after = d.clone(); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(s.active().unwrap().doc, before, "{mode}"); + assert_eq!(s.active().unwrap().selection, selection, "{mode}"); + s.execute("edit.redo", &json!({})).unwrap(); + assert_eq!(s.active().unwrap().doc, after, "{mode}"); + } +} + /// Ruler guides left in a clipped layer do not count as other objects: `removeAll()` deletes the /// layer's clipping compound path. #[test] @@ -2646,6 +2711,93 @@ fn scoped_remove_all_deletes_a_clipping_path_beside_ruler_guides() { s.execute("layer.clippingMask.toggle", &json!({"id": layer.0})).unwrap(); run(&mut s, "app.activeDocument.layers[0].compoundPathItems.removeAll();").unwrap(); assert!(s.active().unwrap().doc.node(cid).is_none()); + assert!(!s.active().unwrap().doc.node(layer).unwrap().clips()); + let added = rect(&mut s, 200.0, 20.0, 30.0, 40.0); + assert_eq!(s.active().unwrap().doc.parent_of(added), Some(layer)); + assert!(!s.active().unwrap().doc.node(layer).unwrap().clips()); + s.execute("edit.undo", &json!({})).unwrap(); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(s.active().unwrap().doc.node(cid).is_some()); + assert!(s.active().unwrap().doc.node(layer).unwrap().clips()); + s.execute("edit.redo", &json!({})).unwrap(); + rect(&mut s, 200.0, 20.0, 30.0, 40.0); + assert!(!s.active().unwrap().doc.node(layer).unwrap().clips()); +} + +#[test] +fn scoped_remove_all_releases_an_empty_clipping_group_in_one_step() { + let (mut s, a, b) = doc(); + s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + s.execute("object.group", &json!({})).unwrap(); + run(&mut s, "app.activeDocument.groupItems[0].clipped = true;").unwrap(); + let steps = undo_steps(&s); + let out = log(&mut s, "var g = app.activeDocument.groupItems[0]; g.pageItems.removeAll(); vc.log(g.clipped); vc.log(g.pageItems.length);"); + assert_eq!(out, [json!(false), json!(0)]); + assert_eq!(undo_steps(&s), steps + 1); + s.execute("edit.undo", &json!({})).unwrap(); + let out = log(&mut s, "var g = app.activeDocument.groupItems[0]; vc.log(g.clipped); vc.log(g.pageItems.length);"); + assert_eq!(out, [json!(true), json!(2)]); +} + +#[test] +fn clipped_setter_refuses_locked_artboards_layers_and_groups() { + for target in ["artboard", "layer", "group"] { + for clipped in [false, true] { + let (mut s, a, b) = doc(); + s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + let g = s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap(); + if clipped { + run(&mut s, "app.activeDocument.groupItems[0].clipped = true;").unwrap(); + } + let layer = s.active().unwrap().doc.layer_containing(NodeId(g)).unwrap(); + s.edit("Lock", |d, _| { + match target { + "artboard" => d.artboards[0].locked = true, + "layer" => d.node_mut(layer).unwrap().locked = true, + _ => d.node_mut(NodeId(g)).unwrap().locked = true, + } + Ok(()) + }) + .unwrap(); + let steps = undo_steps(&s); + let src = format!( + "var g = app.activeDocument.groupItems[0]; try {{ g.clipped = {}; vc.log('changed'); }} catch (e) {{ vc.log(e.message); }} vc.log(g.clipped);", + !clipped + ); + let out = log(&mut s, &src); + assert!(out[0].as_str().unwrap().contains("locked"), "{target}: {out:?}"); + assert_eq!(out[1], json!(clipped)); + assert_eq!(undo_steps(&s), steps); + } + } +} + +#[test] +fn scoped_collections_convert_to_strings() { + let (mut s, ..) = doc(); + let out = log( + &mut s, + "var l = app.activeDocument.layers[0], g = l.groupItems.add(), c = g.compoundPathItems.add();\ + var lists = [l.pageItems, g.pageItems, l.layers, l.groupItems, g.groupItems, l.compoundPathItems, g.compoundPathItems, c.pathItems];\ + for (var i = 0; i < lists.length; i++) { vc.log(String(lists[i])); vc.log(lists[i].toString()); }", + ); + let expected: Vec<_> = ["PageItems", "PageItems", "Layers", "GroupItems", "GroupItems", "CompoundPathItems", "CompoundPathItems", "PathItems"] + .into_iter() + .flat_map(|name| [json!(format!("[{name}]")), json!(format!("[{name}]"))]) + .collect(); + assert_eq!(out, expected); +} + +#[test] +fn layer_color_can_be_assigned_to_path_paint() { + let (mut s, ..) = doc(); + let out = log( + &mut s, + "var l = app.activeDocument.layers[0]; l.color = {red: 10, green: 20, blue: 30};\ + var c = l.color; vc.log(c.typename); var p = l.pageItems[0]; p.fillColor = c;\ + vc.log([p.fillColor.red, p.fillColor.green, p.fillColor.blue]);", + ); + assert_eq!(out, [json!("RGBColor"), json!([10, 20, 30])]); } /// `removeAll()` refuses to delete the compound path that clips a group while the group keeps @@ -2735,7 +2887,11 @@ fn a_path_moved_into_a_pixel_aligned_compound_path_is_snapped() { let d = &s.active().unwrap().doc; assert!(d.node(to).unwrap().extras().pixel_aligned); let after = d.bounds_of(&[r], false).unwrap(); + assert_ne!(after, before); + assert!(!d.node(r).unwrap().extras().pixel_aligned); assert!([after.x0, after.y0, after.x1, after.y1].iter().all(|v| (v * 2.0).fract().abs() < 1e-9), "not snapped: {after:?}"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(s.active().unwrap().doc.bounds_of(&[r], false).unwrap(), before); } #[test] @@ -2746,9 +2902,24 @@ fn a_compound_paths_path_items_are_path_items() { let out = log( &mut s, "var d = app.activeDocument, p = d.compoundPathItems[0].pathItems; vc.log(p.typename); vc.log(p.length);\ - vc.log(p[0].typename); vc.log(d.layers[0].pageItems.typename);", + vc.log(p[0].typename); vc.log(d.layers[0].pageItems.typename); vc.log(p instanceof PathItems);\ + vc.log(p instanceof PageItems); vc.log(p.parent === d.compoundPathItems[0]);\ + p[0].name = 'member'; vc.log(p.getByName('member') === p[0]); vc.log(p.index(0) === p[0]);", ); - assert_eq!(out, [json!("PathItems"), json!(2), json!("PathItem"), json!("PageItems")]); + assert_eq!( + out, + [json!("PathItems"), json!(2), json!("PathItem"), json!("PageItems"), json!(true), json!(false), json!(true), json!(true), json!(true)] + ); + for call in ["add()", "rectangle(100, 100, 10, 10)", "roundedRectangle(100, 100, 10, 10)", "ellipse(100, 100, 10, 10)", "polygon()", "star()"] { + let source = format!( + "var p = app.activeDocument.compoundPathItems[0].pathItems; try {{ p.{call}; vc.log('made'); }} catch (e) {{ vc.log(e.message); }} vc.log(p.length);" + ); + let out = log(&mut s, &source); + assert!(out[0].as_str().unwrap().contains("not available yet"), "{call}: {out:?}"); + assert_eq!(out[1], json!(2)); + } + run(&mut s, "var c = app.activeDocument.compoundPathItems[0]; c.pathItems.removeAll(); vc.log(c.pathItems.length);").unwrap(); + assert!(s.active().unwrap().doc.node(a).is_none() && s.active().unwrap().doc.node(b).is_none()); } #[test] @@ -2818,6 +2989,43 @@ fn scoped_name_searches_are_charged_each_time() { assert_eq!(layer_cost, doc_cost); } +#[test] +fn layer_z_order_scans_are_charged_each_time() { + let (mut s, ..) = doc(); + let repeated = "var l = app.activeDocument.layers[0]; for (var i = 0; i < 512; i++) l.zOrderPosition;"; + crate::script::TEST_BRIDGE_BYTES.with(|b| b.set(Some(1 << 16))); + let small = run(&mut s, repeated); + crate::script::TEST_BRIDGE_BYTES.with(|b| b.set(None)); + small.unwrap(); + for _ in 0..100 { + s.execute("layer.new", &json!({})).unwrap(); + } + crate::script::TEST_BRIDGE_BYTES.with(|b| b.set(Some(1 << 16))); + let once = run(&mut s, "var l = app.activeDocument.layers[0]; l.zOrderPosition;"); + let large = run(&mut s, repeated); + crate::script::TEST_BRIDGE_BYTES.with(|b| b.set(None)); + once.unwrap(); + let error = large.unwrap_err().to_string(); + assert!(error.contains("passed more data"), "{error}"); +} + +#[test] +fn has_selected_artwork_keeps_selected_objects_in_other_layers() { + let (mut s, a, b) = doc(); + s.execute("layer.new", &json!({})).unwrap(); + let other = rect(&mut s, 220.0, 30.0, 10.0, 10.0); + s.execute("select.set", &json!({"ids": [a.0, other.0]})).unwrap(); + for (operation, a_selected, b_selected) in + [("vc.log(l.hasSelectedArtwork)", true, false), ("l.hasSelectedArtwork = false", false, false), ("l.hasSelectedArtwork = true", true, true)] + { + let source = format!("var l = app.activeDocument.layers.getByName('Layer 1'); {operation};"); + run(&mut s, &source).unwrap(); + assert!(s.active().unwrap().selection.objects.contains(&other), "{operation}"); + let selected = &s.active().unwrap().selection.objects; + assert_eq!((selected.contains(&a), selected.contains(&b)), (a_selected, b_selected), "{operation}"); + } +} + #[test] fn group_items_remove_all_refuses_locked_groups() { let (mut s, a, b) = doc(); diff --git a/crates/engine/tests/it/script_host_vs_scriptcheck.rs b/crates/engine/tests/it/script_host_vs_scriptcheck.rs index f1515c5e64..766969a0f9 100644 --- a/crates/engine/tests/it/script_host_vs_scriptcheck.rs +++ b/crates/engine/tests/it/script_host_vs_scriptcheck.rs @@ -171,7 +171,10 @@ const INSIDE: &[(&str, &str)] = &[ width width= wrapInside wrapInside= wrapOffset wrapOffset= wrapped wrapped= zOrder zOrderPosition", ), ("PathItems.", "prototype"), - ("PathItems.prototype.", "add constructor ellipse getByName index length parent polygon rectangle removeAll roundedRectangle star typename"), + ( + "PathItems.prototype.", + "add constructor ellipse getByName index length parent polygon rectangle removeAll roundedRectangle star toString typename", + ), ("PathItem.", "prototype"), ( "PathItem.prototype.", diff --git a/docs/mcp.md b/docs/mcp.md index 67de11e0b9..e9a28ed6bf 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3132,21 +3132,27 @@ through `$`: `pageItems`, `groupItems` and `compoundPathItems`, and a compound path's `pathItems`, list the objects directly in it, topmost first. The document's `groupItems` and `compoundPathItems` hold every group or compound path at any depth, in the order of the document's `pageItems`. A layer's `pageItems` leave out its sublayers, and a compound - path's `pathItems` have the typename `PathItems`. A layer's or artboard's `name` takes a number or a boolean as - `String()` writes it. `locked` true means the layer is locked. `color` is an object `{red, green, blue}` of whole + path's `pathItems` are `PathItems` objects with `length`, `[i]`, `index`, `getByName`, `removeAll` and string conversion. + Their path creation methods throw an error; a script can move existing paths into the compound path. + Scoped collections support `toString()` and `String()`. A layer's or artboard's `name` takes a number or a boolean as + `String()` writes it. `locked` true means the layer is locked. `color` is an `RGBColor` object with `typename` and `{red, green, blue}` of whole numbers from 0 to 255. A layer's name is from 1 to 512 characters. A layer's `zOrderPosition` counts the layers - beside it from 1 at the bottom, leaving out art, and `zOrder` with `BRINGFORWARD` or `SENDBACKWARD` moves it past + beside it from 1 at the bottom, leaving out art; each scan counts toward the script's operation budget. + `zOrder` with `BRINGFORWARD` or `SENDBACKWARD` moves it past the next layer beside it and any art between them. `hasSelectedArtwork = true` adds the layer's shown, unlocked art to the selection (`select.add`), and `false` deselects only the layer's art (`select.toggle`); the rest of the selection, ruler guides included, stays. A layer with nothing to add or deselect runs no command. `clipped = true` makes the group's topmost object, which must be a path, a compound path or type, its clipping - path; `false` releases the mask; the group keeps its id. `groupItems.add()` makes an empty group on top of the + path; `false` releases the mask; the group keeps its id. Changes are refused when the group or its layer is + hidden or locked, or its artboard is locked. A scoped `removeAll()` that leaves a clipping group or layer + without art releases its mask in the same undo step. `groupItems.add()` makes an empty group on top of the layer's or group's contents, or of the current layer's for the document's collection, and `compoundPathItems.add()` makes an empty compound path in the same place (https://ai-scripting.docsforadobe.dev/jsobjref/CompoundPathItems/). A path that `move` or `duplicate` puts into a compound path becomes one of its paths and gives up its own paint, as Make Compound Path leaves its paths. The - compound path becomes pixel-aligned when the path was, or when the compound path it leaves was. An empty + compound path becomes pixel-aligned when the path was, or when the compound path it leaves was. A path moved + into an already pixel-aligned compound path is snapped to the pixel grid. An empty compound path takes the paint the first path that goes in was drawn with: the path's own, or the paint of the compound path it leaves. Other objects are refused. A path that `move` takes out of a compound path into a layer or a group takes the compound path's paint and pixel alignment, as Release Compound Path gives them to its paths. @@ -3417,8 +3423,9 @@ through `$`: Distribute Spacing to the artboard, Select › All on Active Artboard, Edit Symbol, Fit to Artwork Bounds and Fit to Selected Art) and does not name one acts on the active document's active artboard. Once the script has called `setActiveArtboardIndex` on that document, it is the artboard the script chose while that artboard exists. If it - has been deleted, the step uses the artboard at the index last chosen by the script, or the last artboard past - the end. If the script has not chosen an artboard on that document, the step uses the index of its active artboard + has been deleted, playback uses the same fallback as `getActiveArtboardIndex()`, script coordinates and the view: + the saved active artboard if it still exists, otherwise index 0. File > Revert discards the script's stored choice. + If the script has not chosen an artboard on that document since its last revert, the step uses the index of its active artboard as the run started: after the script deletes artboards, the artboard now at that index, or the last one past the end. While the Artboard tool has several artboards selected as the run starts, a paste step and a Fit to Artwork Bounds step act on those instead, as in the panel's playback. A step of a recorded `command.batch` step that @@ -4488,6 +4495,7 @@ Without `ids`, direct-selected anchors or selected ruler guides retain their usu With `ids`, `guides: true` also deletes the selected ruler guides. The command rejects a `guides` value that is not a boolean. A compound path left with no paths is deleted too, unless `keepEmpty: true` is given, which keeps it, empty, also when the deleted parts are direct-selected anchors; a `keepEmpty` value that is not a boolean is rejected. +A clipping group or layer left without art releases its mask in the same undo step. Without `ids`, `keepJoined: true` removes the direct-selected anchors of each path that has no selected segment as `path.removeAnchors` does (see Removing anchor points): the path stays joined, and the next anchor along is selected (the one before at an open path's end). When no subpath that lost an anchor keeps two anchors, the path stays selected diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index df94565ef0..2d9a75efb6 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1127,12 +1127,12 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Scripts: `document.characterStyles` and `document.paragraphStyles` add, find, rename, redefine, apply and remove character and paragraph styles, with the Normal styles listed first and kept, and a text range lists the styles its text is in, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/CharacterStyles/, https://ai-scripting.docsforadobe.dev/jsobjref/CharacterStyle/, https://ai-scripting.docsforadobe.dev/jsobjref/ParagraphStyles/, https://ai-scripting.docsforadobe.dev/jsobjref/ParagraphStyle/ and https://ai-scripting.docsforadobe.dev/jsobjref/TextRange/ describe them (`docs/mcp.md`). Style names of 1 to 256 characters without control characters, and at most 4,096 styles named in one run, are VectorCraft's own rules. Load Character Styles, Load Paragraph Styles and Load All Styles refuse a file larger than 64 MB. A paragraph style's character attributes are not there yet. `crates/engine/src/tests/script_styles.rs`. - Scripts: a text frame's `nextFrame` and `previousFrame` read and set its links to the frames before and after it, `areaText` and `pathText` thread a new frame to a base frame, and `document.stories` lists the stories, each with its frames in thread order and its text across them as one text range with its characters, words and paragraphs, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/TextFrameItem/, https://ai-scripting.docsforadobe.dev/jsobjref/Story/ and https://ai-scripting.docsforadobe.dev/jsobjref/Stories/ describe them; `text.thread.setNeighbor` links or unlinks two frames by id (`docs/mcp.md`). Which links are refused, and how a story is listed and found, are VectorCraft's own rules. `crates/engine/src/tests/script_threads.rs`. - Scripts: `PageItem.tags` reads, adds, renames and deletes an object's tags, name and value pairs that the native file keeps, and `Document.tags` reads, renames and deletes the tags of every page item but adds none (its `add` throws; a script adds a tag through the page item's `tags`), as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Tags/ and https://ai-scripting.docsforadobe.dev/jsobjref/Tag/ describe them, through `object.tags` and the `object.tag.*` commands, at most 64 tags an object (`docs/mcp.md`). `crates/engine/src/tests/script_tags.rs`. - - Scripts: a document's layers and sublayers with their options, stacking and current layer, its groups and compound paths with clipping masks, new empty groups and compound paths and paths moved into compound paths, 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/CompoundPathItems/, https://ai-scripting.docsforadobe.dev/jsobjref/Artboard/ and https://ai-scripting.docsforadobe.dev/jsobjref/Artboards/ describe them (`docs/mcp.md`). `crates/engine/src/tests/script_dom.rs`, `crates/ui-egui/src/tests/script_run.rs`. + - Scripts: a document's layers and sublayers with their options, stacking and current layer, its groups and compound paths with clipping masks, new empty groups and compound paths and paths moved into compound paths, 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/CompoundPathItems/, https://ai-scripting.docsforadobe.dev/jsobjref/Artboard/ and https://ai-scripting.docsforadobe.dev/jsobjref/Artboards/ describe them (`docs/mcp.md`). Scoped collections support string conversion; compound paths expose `PathItems` objects and reject unsupported path creation. Empty clipping containers release their masks in the deletion's undo step, and `clipped` changes check locks. Layer selection changes keep unrelated selected objects, layer colors are assignable `RGBColor` values, stacking scans count toward the script budget, and paths moved into pixel-aligned compound paths are snapped. `crates/engine/src/tests/script_dom.rs`, `crates/ui-egui/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`). A script can check a member with `hasOwnProperty`, and can read a collection by name and name `activeDocument`, `documents` and `selection` without `app.` (https://ai-scripting.docsforadobe.dev/scriptingJavascript/objectReferences/). A key such as `1` is an array index and reads that position; in `pageItems` and `documents`, a number that is not an array index, such as `-1` or `1.5`, is looked up by name when the key is the text JavaScript writes for that number. VectorCraft's own rule. `app.executeMenuCommand` runs the menu items Select All, Deselect, Group, Ungroup, Make and Release Clipping Mask, Make and Release Compound Path, and Fit to Artwork Bounds by their menu command names (https://community.adobe.com/questions-652/a-list-of-illustrator-menu-commands-we-can-call-from-javascript-769510, https://gist.github.com/shalakolee/df3246659d4289eb99149b9ed00a00ee). The `parent` of a page item at the top of a layer is a `Layer` with `name`, `typename` and `toString`. A page item's `blendingMode` reads and sets its blend mode with the `BlendModes` values (https://ai-scripting.docsforadobe.dev/jsobjref/scripting-constants/). `Document.views` lists the document's drawn windows with their bounds, center, zoom and screen mode (https://ai-scripting.docsforadobe.dev/jsobjref/View/). Zoom follows each window's displayed percentage, including display density with Display Print Size at 100% Zoom enabled; bounds retain the physical camera scale. View objects keep their targets when windows are renumbered. View changes run no command, add no undo step, and remain when a script fails. A center outside the canvas after coordinate conversion throws a `RangeError`. Type and the other classes are not there yet. `crates/engine/src/tests/script_dom.rs`. - Scripts: `app.redraw()` (https://ai-scripting.docsforadobe.dev/jsobjref/Application/) returns without changing the documents or adding an undo step; the app goes on drawing the documents as they were before the run until the run ends. VectorCraft's own rule. `crates/engine/src/tests/script_dom.rs`. - Scripts: a document's variables and data sets, the variables its page items are bound to, Lock Variables, and importing and exporting a variable library through a `File`, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Variables/, https://ai-scripting.docsforadobe.dev/jsobjref/Variable/, https://ai-scripting.docsforadobe.dev/jsobjref/Datasets/ and https://ai-scripting.docsforadobe.dev/jsobjref/Dataset/ describe them; `variable.setBinding` binds one object for one slot, and `dataset.update {name}` updates a data set that is not the active one (`docs/mcp.md`). `crates/engine/src/tests/script_variables.rs`. - - Scripts: `app.doScript(action, set, dialogs?)` plays an action of the Actions panel inside the run, as the `DoScript` method of the scripting reference https://web.archive.org/web/20170621180804/https://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2015_3/Illustrator%20VBScript%20Reference.pdf describes it: its steps join the run's one undo step and keep the script's file limits, and a stop or a step a script may not run, or that plays an action or runs a script, is refused before any step runs (`docs/mcp.md`). `app.loadAction` and `app.unloadAction` are not there yet. `crates/engine/src/tests/script_actions.rs`. + - Scripts: `app.doScript(action, set, dialogs?)` plays an action of the Actions panel inside the run, as the `DoScript` method of the scripting reference https://web.archive.org/web/20170621180804/https://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2015_3/Illustrator%20VBScript%20Reference.pdf describes it: its steps join the run's one undo step and keep the script's file limits, and a stop or a step a script may not run, or that plays an action or runs a script, is refused before any step runs (`docs/mcp.md`). After deletion of an artboard chosen by the script, playback uses the same fallback as script coordinates, `getActiveArtboardIndex()` and the view; File > Revert discards that stored choice. `app.loadAction` and `app.unloadAction` are not there yet. `crates/engine/src/tests/script_actions.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 warning before File › Scripts › Other Script… runs a script lists what `script.check` finds the script reaches outside the document (files it writes, moves or deletes, other apps, the network, native code, environment variables, preferences, code the checker can't read), the files and dialogs it needs, features only the reference app has and its included files, read without running it. It says when the script is too large to check, compiled, not a script or not read, and when a list was cut short. VectorCraft's own rule. `crates/ui-egui/src/tests/script_run.rs`.