Merge feat/scripts-api-d2-paths-colors into feat/scripts-text-paint

This commit is contained in:
dotCooCoo committed 2026-11-25 18:16:05 -08:00
commit bc731da716
10 files changed
+605 -60

No files matched your search

+4 -4
View File
@@ -118,10 +118,10 @@ const ARTBOARD_COORDS: &str = "CoordinateSystem.ARTBOARDCOORDINATESYSTEM";
/// What the object model keeps for one run: its coordinate system, the lists of page items and the
/// answers of which objects are on a locked artboard for the last [`ITEM_LISTS`] documents read,
/// each kept while its document is unchanged, the point changes of a path not written yet, how
/// many times each path's points went stale and each path as the run last saw its points, whether
/// a call's own savepoint ([`atomically`]) is open, and the settings of each `DocumentPreset` the
/// run made.
/// each kept while its document is unchanged, the point changes of a path not written yet, how many
/// times each path's points went stale and each path as the run last saw its points, whether a
/// call's own savepoint ([`atomically`]) is open, and the settings of each `DocumentPreset` the run
/// made.
#[derive(Default)]
pub(super) struct State {
coords: Cell<Coords>,
+223 -25
View File
@@ -39,6 +39,17 @@
//! says it is not available yet. `rotateAbout` and `scaleAbout` default to
//! `Transformation.CENTER`. A transform that leaves the path where it is (`rotate(360)`,
//! `resize(100, 100)`) checks its arguments and runs no command, on a path with no points too.
//! - `PathPoint.selected` and `selectedPathPoints` count every point of a path selected as a whole
//! as a selected anchor point, and not the endpoints of selected segments; a path in a selected
//! group or compound path is selected as a whole. Direction handles are not selected on their
//! own, so `LEFTDIRECTION`, `RIGHTDIRECTION` and `LEFTRIGHTPOINT` throw an error that says they
//! are not available yet, and so does `NOSELECTION` on a point of a path in a selected group or
//! compound path. Selecting a point of a path with selected segments replaces that path's
//! segment selection. Selecting a point of a guide while guides are locked throws an error. A
//! clipping path cannot be made a guide. Assigning `guides` a value the path does not have
//! throws an error that says it is not available yet on a path inside a compound path, throws
//! `Cannot edit` on a path that cannot be edited or selected, and throws an error while guides
//! are locked; assigning the value the path has runs no command.
//! - The transforms take one setting for fill and stroke patterns, so `changeFillPatterns` and
//! `changeStrokePattern` given as different values throw an error; gradients move with the art,
//! so `changeFillGradients` false throws an error that says it is not available yet.
@@ -56,9 +67,9 @@ use vectorcraft_js::{Data, HostClass, HostError, HostItem, HostMember, Realm, Ru
use vectorcraft_tools::params::gradient_params;
use super::{
Answer, Coords, Doc, Item, Link, NOT_FOUND, STALE_ITEM, arg, boolean, class, colors, command, coordinate, doc_of, edit_item, editable, find_doc,
float, frame, get, given, handle_of, id_of, id_parts, item_of, item_rect, later, method, named, num, number, on_doc, pair, point, point_get,
point_method, point_property, property, this_doc, typename_of, whole, with_doc,
Answer, Coords, Doc, Item, Link, NOT_FOUND, ON_LOCKED_ARTBOARD, STALE_ITEM, arg, boolean, class, colors, command, coordinate, doc_of, edit_item,
editable, find_doc, float, frame, get, given, handle_of, id_of, id_parts, item_of, item_rect, later, method, named, num, number, on_doc, pair,
point, point_get, point_method, point_property, property, this_doc, typename_of, whole, with_doc,
};
use crate::{DocState, NodeId, NodeKind};
@@ -299,8 +310,15 @@ fn items_parent(h: &super::Host, a: &[Data]) -> Answer {
Ok(host_ref("Document", &[float(h.run), float(doc.uid)]))
}
/// `pathItems[i]`, and `pathItems["name"]` as `getByName` reads it.
fn items_at(h: &super::Host, a: &[Data]) -> Answer {
let doc = items_doc(h, a)?;
if let Data::String(_) = arg(a, 1) {
return match items_by_name(h, a) {
Err(HostError::Error(e)) if e == NOT_FOUND && super::probing(a) => Ok(Data::Undefined),
r => r,
};
}
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) };
Ok(with_doc(h, doc, |_, st| path_items(h, st).get(i).map_or(Data::Undefined, |id| super::item_ref(h, st, *id))))
@@ -329,18 +347,25 @@ 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.
/// path, one in a hidden or locked layer or group, or one on a locked artboard stops it before
/// anything is deleted, as `pageItems.removeAll()` is stopped.
fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
let doc = items_doc(h, a)?;
let (ids, refused) = with_doc(h, doc, |_, st| {
let (ids, refused, on_locked) = with_doc(h, doc, |_, st| {
let ids = path_items(h, st);
let refused: Vec<u64> = ids.iter().filter(|i| !editable(&st.doc, **i)).map(|i| i.0).take(20).collect();
(ids, refused)
let locks = st.doc.locked_artboards();
let on_locked: Vec<u64> = ids.iter().filter(|i| locks.holds_id(**i)).map(|i| i.0).take(20).collect();
(ids, refused, on_locked)
});
if !refused.is_empty() {
let list = refused.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
return Err(HostError::Error(format!("cannot delete hidden or locked paths: {list}")));
}
if !on_locked.is_empty() {
let list = on_locked.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
return Err(HostError::Error(format!("{ON_LOCKED_ARTBOARD}: {list}")));
}
if !ids.is_empty() {
on_doc(h, doc.uid, true, |h| command(h, "edit.clear", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})))?;
}
@@ -585,6 +610,56 @@ fn path_guides(h: &super::Host, a: &[Data]) -> Answer {
read_path(h, item, |_, n, _| Data::Bool(matches!(n.kind, NodeKind::Path { guide: true, .. })))
}
/// The error of assigning `guides` on a path inside a compound path.
pub const COMPOUND_MEMBER_GUIDES: &str = "Changing guides on a path inside a compound path is not available yet";
/// `guides = true` makes the path a guide with `view.guides.make`, and `false` makes it a path again
/// with `view.guides.release`; the selection stays as it was. A value the path has already runs no
/// command and throws no error. Otherwise a clipping path cannot be a guide, a path inside a
/// compound path throws [`COMPOUND_MEMBER_GUIDES`], and while guides are locked both values throw
/// an error.
fn path_set_guides(h: &super::Host, a: &[Data]) -> Answer {
let on = boolean(arg(a, 1), "guides")?;
let item = this_path(h, a)?;
let (now, clipping) = read_path(h, item, |_, n, _| match &n.kind {
NodeKind::Path { guide, clipping, .. } => (*guide, *clipping),
_ => (false, false),
})?;
if now == on {
return Ok(Data::Undefined);
}
let (member, editable, selectable) = with_doc(h, item.doc, |_, st| {
let member = st.doc.parent_of(item.id).and_then(|p| st.doc.node(p)).is_some_and(|p| matches!(p.kind, NodeKind::Compound { .. }));
let selectable = crate::cmd::select::is_selectable(&st.doc, st.isolation, &st.doc.locked_artboards(), item.id);
(member, editable(&st.doc, item.id), selectable)
});
if member {
return Err(HostError::Error(COMPOUND_MEMBER_GUIDES.into()));
}
if !editable || !selectable {
return Err(cannot_edit(item.id));
}
if h.session.borrow().menu.guides_locked {
return Err(HostError::Error(format!("Cannot change guides on PathItem {}: guides are locked", item.id.0)));
}
if !on {
edit_path(h, item, "view.guides.release", json!({}))?;
return Ok(Data::Undefined);
}
if clipping {
return Err(HostError::Error(format!("Cannot make PathItem {} a guide: it is a clipping path", item.id.0)));
}
see_all_points(h);
let kept = h.dom.editing.replace(Some(item));
let r = on_doc(h, item.doc.uid, true, |h| {
command(h, "select.set", &json!({"ids": [item.id.0]}))?;
command(h, "view.guides.make", &json!({}))
});
h.dom.editing.set(kept);
r?;
Ok(Data::Undefined)
}
fn path_clipping(h: &super::Host, a: &[Data]) -> Answer {
let item = this_path(h, a)?;
read_path(h, item, |_, n, _| Data::Bool(matches!(n.kind, NodeKind::Path { clipping: true, .. })))
@@ -1008,8 +1083,9 @@ fn path_rotate(h: &super::Host, a: &[Data]) -> Answer {
let place = about_name(arg(a, 6))?;
let mut params = json!({"angle": angle});
transform_options(a, 2, &mut params)?;
if angle.rem_euclid(360.0) != 0.0 {
let (r, _) = item_rect(h, item, false)?;
if angle.rem_euclid(360.0) != 0.0
&& let (Some(r), _) = item_rect(h, item, false)?
{
let origin = about(h, item, place, r)?;
params["origin"] = json!([origin.x, origin.y]);
edit_path(h, item, "object.rotate", params)?;
@@ -1038,8 +1114,9 @@ fn path_resize(h: &super::Host, a: &[Data]) -> Answer {
if new_width.is_some_and(|w| w > MAX_STROKE_WIDTH) {
return Err(HostError::Range("changeLineWidths would make the stroke weight more than 1000 points".into()));
}
if sx != 100.0 || sy != 100.0 {
let (r, _) = item_rect(h, item, false)?;
if (sx != 100.0 || sy != 100.0)
&& let (Some(r), _) = item_rect(h, item, false)?
{
let origin = about(h, item, place, r)?;
params["origin"] = json!([origin.x, origin.y]);
edit_path(h, item, "object.scale", params)?;
@@ -1323,6 +1400,129 @@ fn pt_parent(h: &super::Host, a: &[Data]) -> Answer {
Ok(path_ref(h, item))
}
/// Whether a group or compound path that holds the path `id` is selected, which selects the path
/// as a whole whatever the path's own selection is.
fn held_selected(d: &crate::Document, sel: &crate::doc::Selection, id: NodeId) -> bool {
d.ancestry(id).is_some_and(|a| a.iter().any(|i| *i != id && sel.contains(*i) && d.node(*i).is_some_and(|n| !n.is_layer())))
}
/// The point at index `i` of `subs` is a selected anchor point of the path `id` in `sel`: every
/// point of a path selected as a whole is (a path is when a group or compound path that holds it
/// is selected, `held`), and of a path with direct-selected anchors only those anchors are. The
/// endpoints of selected segments are not.
fn anchor_selected(sel: &crate::doc::Selection, id: NodeId, held: bool, subs: &[SubPath], i: usize) -> bool {
if held {
return true;
}
if !sel.contains(id) || sel.segments.contains_key(&id) {
return false;
}
match sel.partial(id) {
None => true,
Some(picked) => locate(subs, i).is_some_and(|r| picked.contains(&r)),
}
}
/// Whether the subpaths `a` and `b` have the same number of points in the same subpaths, so that a
/// point index names the same anchor in both.
fn same_layout(a: &[SubPath], b: &[SubPath]) -> bool {
a.len() == b.len() && a.iter().zip(b).all(|(x, y)| x.anchors.len() == y.anchors.len())
}
/// `selected`: `PathPointSelection.ANCHORPOINT` when the point is a selected anchor point
/// ([`anchor_selected`]), otherwise `PathPointSelection.NOSELECTION`. The point changes waiting in
/// [`super::State`] are written first only when they add or remove points of this path, since
/// the selection names anchors by their place in the document's path.
fn pt_selected(h: &super::Host, a: &[Data]) -> Answer {
let (item, i) = this_point(h, a)?;
let moved = match &*h.dom.pending.borrow() {
Some((waiting, subs)) if same_path(*waiting, item) => !read_path(h, item, |_, _, pd| same_layout(subs, &pd.subpaths))?,
_ => false,
};
if moved {
super::flush(h)?;
}
let on =
read_path(h, item, |st, _, pd| anchor_selected(&st.selection, item.id, held_selected(&st.doc, &st.selection, item.id), &pd.subpaths, i))?;
Ok(Data::String(if on { "PathPointSelection.ANCHORPOINT" } else { "PathPointSelection.NOSELECTION" }.into()))
}
/// The `PathPointSelection` values that select a point's direction handles.
const HANDLE_SELECTIONS: &[&str] = &["PathPointSelection.LEFTDIRECTION", "PathPointSelection.RIGHTDIRECTION", "PathPointSelection.LEFTRIGHTPOINT"];
/// `selected = PathPointSelection.ANCHORPOINT` adds the point to the direct-selected anchors, and
/// `NOSELECTION` removes it, with `select.anchorsMany`; the other selected objects and anchors stay
/// selected, except that selecting an anchor of a path with selected segments replaces that path's
/// segment selection, as `select.anchorsMany` does. A value the point has already runs no command.
/// Direction handles cannot be selected, so `LEFTDIRECTION`, `RIGHTDIRECTION` and
/// `LEFTRIGHTPOINT` throw an error, and so does `NOSELECTION` on a path selected through a group or
/// compound path that holds it, and `ANCHORPOINT` on a guide while guides are locked. The setter
/// writes the waiting point changes first, as every member that is not a point function does.
fn pt_set_selected(h: &super::Host, a: &[Data]) -> Answer {
let on = match arg(a, 1) {
Data::String(s) if s == "PathPointSelection.ANCHORPOINT" => true,
Data::String(s) if s == "PathPointSelection.NOSELECTION" => false,
Data::String(s) if HANDLE_SELECTIONS.contains(&s.as_str()) => {
return Err(HostError::Error(format!("PathPoint.selected = {s} is not available yet: only anchor points can be selected")));
}
_ => return Err(HostError::Type("selected must be a PathPointSelection value".into())),
};
let (item, i) = this_point(h, a)?;
let (now, at, selectable, held, guide) = with_doc(h, item.doc, |_, st| {
let node = st.doc.node(item.id);
let subs = node.and_then(|n| n.path_data()).map_or(&[][..], |pd| &pd.subpaths[..]);
let guide = node.is_some_and(|n| matches!(n.kind, NodeKind::Path { guide: true, .. }));
let selectable = crate::cmd::select::is_selectable(&st.doc, st.isolation, &st.doc.locked_artboards(), item.id);
let held = held_selected(&st.doc, &st.selection, item.id);
(anchor_selected(&st.selection, item.id, held, subs, i), locate(subs, i), selectable, held, guide)
});
if now == on {
return Ok(Data::Undefined);
}
let Some((s, j)) = at else { return Err(HostError::Error(STALE_POINT.into())) };
if held {
return Err(HostError::Error(format!(
"PathPoint.selected = PathPointSelection.NOSELECTION is not available yet on PathItem {}: the group or compound path that holds it is selected",
item.id.0
)));
}
if on && !selectable {
return Err(HostError::Error(format!("Cannot select PathItem {}", item.id.0)));
}
if on && guide && h.session.borrow().menu.guides_locked {
return Err(HostError::Error(format!("Cannot select PathItem {}: guides are locked", item.id.0)));
}
let params = json!({"items": [{"id": item.id.0, "anchors": [[s, j]]}], "mode": if on { "add" } else { "subtract" }});
on_doc(h, item.doc.uid, false, |h| command(h, "select.anchorsMany", &params))?;
Ok(Data::Undefined)
}
/// `selectedPathPoints`: the points that are selected anchor points ([`anchor_selected`]), in the
/// order of `pathPoints`.
fn path_selected_points(h: &super::Host, a: &[Data]) -> Answer {
let item = this_path(h, a)?;
let picked: Vec<usize> = read_path(h, item, |st, _, pd| {
let sel = &st.selection;
let held = held_selected(&st.doc, sel, item.id);
if !held && (!sel.contains(item.id) || sel.segments.contains_key(&item.id)) {
return Vec::new();
}
let mut out = Vec::new();
let mut first = 0;
for (s, sp) in pd.subpaths.iter().enumerate() {
let n = sp.anchors.len();
out.extend((0..n).filter(|j| held || sel.partial(item.id).is_none_or(|p| p.contains(&(s, *j)))).map(|j| first + j));
first += n;
}
out
})?;
h.charge_call(picked.len() as u64)?;
let [high, low] = id_parts(item.id);
let cuts = float(point_cuts(h, item));
let points = picked.into_iter().map(|i| host_ref("PathPoint", &[float(h.run), float(item.doc.uid), high, low, float(i as u64), cuts])).collect();
Ok(Data::Array(points))
}
/// `remove()`: deletes the point; a subpath left with no points goes too.
fn pt_remove(h: &super::Host, a: &[Data]) -> Answer {
let (item, i) = this_point(h, a)?;
@@ -1350,7 +1550,7 @@ pub(super) fn path_item_members(l: &Link) -> Vec<(String, HostMember)> {
("evenodd", property(l, path_evenodd, path_set_evenodd)),
("area", get(l, path_area)),
("length", get(l, path_length)),
("guides", get(l, path_guides)),
("guides", property(l, path_guides, path_set_guides)),
("clipping", get(l, path_clipping)),
("setEntirePath", point_method(l, path_set_entire)),
("filled", property(l, path_filled, path_set_filled)),
@@ -1368,8 +1568,9 @@ pub(super) fn path_item_members(l: &Link) -> Vec<(String, HostMember)> {
("translate", method(l, path_translate)),
("rotate", method(l, path_rotate)),
("resize", method(l, path_resize)),
("selectedPathPoints", get(l, path_selected_points)),
]);
m.extend(["selectedPathPoints", "polarity", "resolution"].into_iter().map(|n| later(l, "PathItem", n)));
m.extend(["polarity", "resolution"].into_iter().map(|n| later(l, "PathItem", n)));
m
}
@@ -1411,19 +1612,16 @@ pub(super) fn classes(l: &Link) -> Vec<HostClass> {
class(
"PathPoint",
None,
{
let mut m = named(vec![
("typename", typename_of("PathPoint")),
("parent", point_get(l, pt_parent)),
("anchor", point_property(l, pt_anchor, pt_set_anchor)),
("leftDirection", point_property(l, pt_left, pt_set_left)),
("rightDirection", point_property(l, pt_right, pt_set_right)),
("pointType", point_property(l, pt_type, pt_set_type)),
("remove", point_method(l, pt_remove)),
]);
m.push(later(l, "PathPoint", "selected"));
m
},
named(vec![
("typename", typename_of("PathPoint")),
("parent", point_get(l, pt_parent)),
("anchor", point_property(l, pt_anchor, pt_set_anchor)),
("leftDirection", point_property(l, pt_left, pt_set_left)),
("rightDirection", point_property(l, pt_right, pt_set_right)),
("pointType", point_property(l, pt_type, pt_set_type)),
("selected", HostMember::Property { get: super::point_function(l, pt_selected), set: super::function(l, pt_set_selected) }),
("remove", point_method(l, pt_remove)),
]),
None,
),
]
+3 -3
View File
@@ -717,10 +717,10 @@ fn selecting_an_item_keeps_the_direct_selected_anchors_of_others() {
s.execute("select.add", &json!({"ids": [b.0]})).unwrap();
let anchors = s.active().unwrap().selection.anchors.clone();
assert!(anchors.contains_key(&a));
log(&mut s, "app.activeDocument.pageItems[1].selected = false;");
log(&mut s, "app.activeDocument.pageItems[0].selected = false;");
let sel = &s.active().unwrap().selection;
assert_eq!((sel.objects.clone(), sel.anchors.clone()), (vec![a], anchors.clone()));
log(&mut s, "app.activeDocument.pageItems[1].selected = true;");
log(&mut s, "app.activeDocument.pageItems[0].selected = true;");
let sel = &s.active().unwrap().selection;
assert_eq!((sel.objects.clone(), sel.anchors.get(&a)), (vec![a, b], anchors.get(&a)));
}
@@ -1511,7 +1511,7 @@ fn page_items_report_their_available_members_as_their_own() {
vc.log([p.hasOwnProperty('opacity'), p.hasOwnProperty('typename'), p.hasOwnProperty('duplicate'),\
Object.prototype.hasOwnProperty.call(p, 'name'), p.propertyIsEnumerable('opacity'), d.hasOwnProperty('selection'),\
app.hasOwnProperty('activeDocument')]);\
vc.log([p.hasOwnProperty('blendingMode'), p.hasOwnProperty('rotate'), d.hasOwnProperty('layers'),\
vc.log([p.hasOwnProperty('blendingMode'), p.hasOwnProperty('transform'), d.hasOwnProperty('layers'),\
p.hasOwnProperty('nosuch'), p.hasOwnProperty('hasOwnProperty'), p.hasOwnProperty('constructor')]);\
vc.log([keys.indexOf('opacity') >= 0, keys.indexOf('typename') >= 0, keys.indexOf('duplicate'), keys.indexOf('blendingMode')]);",
);
+330 -3
View File
@@ -26,12 +26,12 @@ fn rect(s: &mut Session, x: f64, y: f64, w: f64, h: f64) -> NodeId {
NodeId(s.execute("shape.rectangle", &json!({"x": x, "y": y, "width": w, "height": h})).unwrap()["id"].as_u64().unwrap())
}
/// A 400 × 300 pt document with two rectangles.
/// A 400 × 300 pt document with two rectangles, `a` on top, so `pathItems[0]` is `a`.
fn doc() -> (Session, NodeId, NodeId) {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
let a = rect(&mut s, 10.0, 20.0, 30.0, 40.0);
let b = rect(&mut s, 100.0, 100.0, 50.0, 50.0);
let a = rect(&mut s, 10.0, 20.0, 30.0, 40.0);
s.execute("select.none", &json!({})).unwrap();
(s, a, b)
}
@@ -97,6 +97,47 @@ fn path_items_remove_all_refuses_locked_paths_and_changes_nothing() {
assert_eq!(log(&mut s, "vc.log(app.activeDocument.pathItems.length);"), vec![json!(0)]);
}
/// `pathItems` read with a name gives what `getByName` gives, and throws as it does for no match,
/// as `pageItems` does.
#[test]
fn path_items_read_with_a_name_give_the_named_path() {
let (mut s, a, _) = doc();
s.execute("object.setProps", &json!({"ids": [a.0], "name": "n"})).unwrap();
let out = log(
&mut s,
"var p = app.activeDocument.pathItems, m = [];\
vc.log([p['n'] === p.getByName('n'), p['n'].name, 'n' in p, 'nosuch' in p, p['length'] === p.length]);\
try { p['nosuch']; } catch (e) { m.push(e.message); }\
vc.log(m);",
);
assert_eq!(out, vec![json!([true, "n", true, false, true]), json!(["Not found"])]);
}
/// Paths on a locked artboard stay, a path in a group included: `removeAll()` throws and deletes
/// nothing, as `pageItems.removeAll()` and `remove()` do.
#[test]
fn path_items_remove_all_refuses_paths_on_a_locked_artboard() {
let (mut s, a, b) = doc();
s.execute("object.group", &json!({"ids": [b.0]})).unwrap();
s.execute("select.none", &json!({})).unwrap();
let lock = |s: &mut Session, locked: bool| {
s.edit("Lock Artboard", |d, _| {
d.artboards[0].locked = locked;
Ok(())
})
.unwrap();
};
lock(&mut s, true);
let (before, steps) = (art(&s), undo_steps(&s));
let e = failure(&mut s, "app.activeDocument.pathItems.removeAll();");
assert!(e.contains("cannot delete objects on a locked artboard") && e.contains(&a.0.to_string()) && e.contains(&b.0.to_string()), "{e}");
assert_eq!(art(&s), before);
assert_eq!(undo_steps(&s), steps);
lock(&mut s, false);
log(&mut s, "app.activeDocument.pathItems.removeAll();");
assert_eq!(log(&mut s, "vc.log(app.activeDocument.pathItems.length);"), vec![json!(0)]);
}
#[test]
fn shape_creators_use_documented_defaults_and_y_up() {
let mut s = Session::new();
@@ -807,7 +848,7 @@ fn locked_paths_and_wrong_objects_are_refused() {
}
assert_eq!(art(&s), before);
s.execute("text.create", &json!({"x": 10, "y": 250, "text": "hi"})).unwrap();
let e = failure(&mut s, "var t = app.activeDocument.pageItems[2]; Object.getOwnPropertyDescriptor(PathItem.prototype, 'closed').get.call(t);");
let e = failure(&mut s, "var t = app.activeDocument.pageItems[0]; Object.getOwnPropertyDescriptor(PathItem.prototype, 'closed').get.call(t);");
assert!(e.contains("not a PathItem"), "{e}");
let e = failure(&mut s, "Object.getOwnPropertyDescriptor(PathPoint.prototype, 'anchor').get.call({});");
assert!(e.contains("not a PathPoint"), "{e}");
@@ -880,3 +921,289 @@ fn many_path_edits_are_one_undo_step() {
assert!((node(&s, id).appearance.stroke_width() - 1.0).abs() < 1e-9);
}
}
fn selected_anchors(s: &Session, id: NodeId) -> Option<Vec<(usize, usize)>> {
s.active().unwrap().selection.anchors.get(&id).map(|set| set.iter().copied().collect())
}
#[test]
fn path_point_selected_selects_and_deselects_anchor_points() {
let (mut s, a, b) = doc();
s.execute("select.set", &json!({"ids": [b.0]})).unwrap();
let steps = undo_steps(&s);
let out = log(
&mut s,
"var p = app.activeDocument.pathItems[0], pp = p.pathPoints;\
vc.log(pp[1].selected); vc.log(p.selectedPathPoints.length);\
pp[1].selected = PathPointSelection.ANCHORPOINT; pp[2].selected = PathPointSelection.ANCHORPOINT;\
vc.log(pp[1].selected); vc.log(pp[0].selected); vc.log(p.selected);\
var sp = p.selectedPathPoints; vc.log(sp.length); vc.log(sp[1].anchor.join() == pp[2].anchor.join());",
);
assert_eq!(
out,
vec![
json!("PathPointSelection.NOSELECTION"),
json!(0),
json!("PathPointSelection.ANCHORPOINT"),
json!("PathPointSelection.NOSELECTION"),
json!(true),
json!(2),
json!(true)
]
);
assert_eq!(selected_anchors(&s, a), Some(vec![(0, 1), (0, 2)]));
assert!(s.active().unwrap().selection.contains(b), "the other selected object stays selected");
assert_eq!(undo_steps(&s), steps, "a selection change is not an undo step");
let r = run(
&mut s,
"var pp = app.activeDocument.pathItems[0].pathPoints;\
pp[1].selected = PathPointSelection.ANCHORPOINT; pp[0].selected = PathPointSelection.NOSELECTION;",
)
.unwrap();
assert_eq!((undo_steps(&s), &r["slowestCommands"]), (steps, &json!([])), "a value the point has runs no command");
log(&mut s, "app.activeDocument.pathItems[0].pathPoints[1].selected = PathPointSelection.NOSELECTION;");
assert_eq!(selected_anchors(&s, a), Some(vec![(0, 2)]));
}
#[test]
fn a_path_selected_as_a_whole_has_every_point_selected() {
let (mut s, a, _) = doc();
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
let out = log(
&mut s,
"var p = app.activeDocument.pathItems[0]; vc.log(p.selectedPathPoints.length); vc.log(p.pathPoints[3].selected);\
p.pathPoints[0].selected = PathPointSelection.NOSELECTION; vc.log(p.selectedPathPoints.length);\
vc.log(app.activeDocument.pathItems[1].selectedPathPoints.length);",
);
assert_eq!(out, vec![json!(4), json!("PathPointSelection.ANCHORPOINT"), json!(3), json!(0)]);
assert_eq!(selected_anchors(&s, a), Some(vec![(0, 1), (0, 2), (0, 3)]));
}
#[test]
fn a_path_in_a_selected_group_or_compound_path_is_selected_as_a_whole() {
for make in ["object.group", "object.compoundPath.make"] {
let (mut s, a, b) = doc();
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
s.execute(make, &json!({})).unwrap();
let sel = format!("{:?}", s.active().unwrap().selection);
let steps = undo_steps(&s);
let out = log(
&mut s,
"var ps = app.activeDocument.pathItems; vc.log([ps[0].selectedPathPoints.length, ps[1].selectedPathPoints.length]);\
vc.log(ps[0].pathPoints[2].selected); ps[0].pathPoints[2].selected = PathPointSelection.ANCHORPOINT;\
try { ps[0].pathPoints[2].selected = PathPointSelection.NOSELECTION; } catch (e) { vc.log(e.message); }",
);
assert_eq!(out[..2], [json!([4, 4]), json!("PathPointSelection.ANCHORPOINT")], "{make}");
assert!(out[2].as_str().is_some_and(|m| m.contains("not available yet")), "{make}: {out:?}");
assert_eq!(format!("{:?}", s.active().unwrap().selection), sel, "{make}: the selection stays as it was");
assert_eq!(undo_steps(&s), steps, "{make}");
}
}
#[test]
fn a_path_in_a_selected_group_reads_as_a_whole_when_its_own_anchors_are_also_picked() {
let (mut s, a, b) = doc();
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
s.execute("object.group", &json!({})).unwrap();
let group = s.active().unwrap().doc.parent_of(a).unwrap();
s.execute("select.set", &json!({"ids": [group.0, a.0]})).unwrap();
s.execute("select.anchorsMany", &json!({"items": [{"id": a.0, "anchors": [[0, 1]]}], "mode": "subtract"})).unwrap();
assert!(s.active().unwrap().selection.contains(group), "the group stays selected");
assert!(s.active().unwrap().selection.partial(a).is_some(), "the path has its own anchor selection");
let out = log(&mut s, "var p = app.activeDocument.pathItems[0]; vc.log([p.selectedPathPoints.length, p.pathPoints[1].selected]);");
assert_eq!(out, vec![json!([4, "PathPointSelection.ANCHORPOINT"])]);
}
#[test]
fn reading_selected_while_moving_points_writes_the_path_once() {
let (mut s, a, _) = doc();
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
let r = run(
&mut s,
"var pp = app.activeDocument.pathItems[0].pathPoints;\
for (var i = 0; i < pp.length; i++) if (pp[i].selected == PathPointSelection.ANCHORPOINT) pp[i].anchor = [pp[i].anchor[0] + 1, pp[i].anchor[1]];",
)
.unwrap();
let calls: Vec<u64> =
r["slowestCommands"].as_array().unwrap().iter().filter(|c| c["id"] == "path.setAnchors").map(|c| c["calls"].as_u64().unwrap()).collect();
assert_eq!(calls, vec![1], "{r}");
}
#[test]
fn selection_reads_and_writes_see_points_the_script_added() {
let (mut s, a, _) = doc();
let out = log(
&mut s,
"var p = app.activeDocument.pathItems[0], q = p.pathPoints.add(); q.selected = PathPointSelection.ANCHORPOINT;\
vc.log(q.selected); vc.log(p.selectedPathPoints.length);",
);
assert_eq!(out, vec![json!("PathPointSelection.ANCHORPOINT"), json!(1)]);
assert_eq!(selected_anchors(&s, a), Some(vec![(0, 4)]));
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
let out = log(&mut s, "var p = app.activeDocument.pathItems[0]; p.pathPoints.add(); vc.log([p.selectedPathPoints.length, p.pathPoints.length]);");
assert_eq!(out, vec![json!([6, 6])]);
}
#[test]
fn selecting_a_point_of_a_path_with_selected_segments_replaces_the_segments() {
let (mut s, a, _) = doc();
s.execute("select.segments", &json!({"id": a.0, "segments": [[0, 1]], "mode": "set"})).unwrap();
let out = log(
&mut s,
"var p = app.activeDocument.pathItems[0]; vc.log(p.selectedPathPoints.length);\
p.pathPoints[1].selected = PathPointSelection.NOSELECTION;",
);
assert_eq!(out, vec![json!(0)]);
assert!(s.active().unwrap().selection.segments.contains_key(&a), "a value the point has leaves the segments selected");
log(&mut s, "app.activeDocument.pathItems[0].pathPoints[0].selected = PathPointSelection.ANCHORPOINT;");
let sel = &s.active().unwrap().selection;
assert!(!sel.segments.contains_key(&a));
assert_eq!(selected_anchors(&s, a), Some(vec![(0, 0)]));
}
#[test]
fn path_point_selected_refuses_handles_bad_values_and_locked_paths() {
let (mut s, a, _) = doc();
let e = failure(&mut s, "app.activeDocument.pathItems[0].pathPoints[0].selected = PathPointSelection.LEFTDIRECTION;");
assert!(e.contains("not available yet"), "{e}");
let e = failure(&mut s, "app.activeDocument.pathItems[0].pathPoints[0].selected = true;");
assert!(e.contains("PathPointSelection"), "{e}");
s.execute("object.setProps", &json!({"ids": [a.0], "locked": true})).unwrap();
let e = failure(&mut s, "app.activeDocument.pathItems[0].pathPoints[0].selected = PathPointSelection.ANCHORPOINT;");
assert!(e.contains("Cannot select"), "{e}");
assert!(s.active().unwrap().selection.is_empty());
}
/// The ways an editable path cannot be selected: on a locked artboard, and outside the isolated
/// object.
const UNSELECTABLE: [&str; 2] = ["locked artboard", "isolation"];
/// Makes the paths of [`doc`] other than `b` editable but not selectable, as `case` names.
fn lock_out(s: &mut Session, case: &str, b: NodeId) {
if case == "isolation" {
s.execute("object.isolate", &json!({"id": b.0})).unwrap();
} else {
s.execute("artboard.setProps", &json!({"index": 0, "locked": true})).unwrap();
}
}
#[test]
fn path_point_selected_refuses_paths_on_locked_artboards_and_outside_isolation() {
for case in UNSELECTABLE {
let (mut s, a, b) = doc();
lock_out(&mut s, case, b);
let e = failure(&mut s, "app.activeDocument.pathItems[0].pathPoints[0].selected = PathPointSelection.ANCHORPOINT;");
assert!(e.contains("Cannot select"), "{case}: {e}");
assert!(!s.active().unwrap().selection.contains(a), "{case}");
}
}
#[test]
fn selecting_a_point_of_a_guide_throws_while_guides_are_locked() {
let (mut s, a, _) = doc();
log(&mut s, "app.activeDocument.pathItems[0].guides = true;");
s.set_guides_locked(true);
let e = failure(&mut s, "app.activeDocument.pathItems[0].pathPoints[0].selected = PathPointSelection.ANCHORPOINT;");
assert!(e.contains("guides are locked"), "{e}");
assert!(!s.active().unwrap().selection.contains(a));
}
#[test]
fn assigning_guides_refuses_paths_that_cannot_be_selected() {
for case in UNSELECTABLE {
let (mut s, a, b) = doc();
lock_out(&mut s, case, b);
let e = failure(&mut s, "app.activeDocument.pathItems[0].guides = true;");
assert!(e.contains("Cannot edit"), "{case}: {e}");
assert!(!is_guide(&s, a), "{case}");
}
// A guide is on no locked artboard, so only isolation keeps a guide from being released.
let (mut s, a, b) = doc();
log(&mut s, "app.activeDocument.pathItems[0].guides = true;");
assert!(is_guide(&s, a));
lock_out(&mut s, "isolation", b);
let steps = undo_steps(&s);
let e = failure(&mut s, "app.activeDocument.pathItems[0].guides = false;");
assert!(e.contains("Cannot edit"), "{e}");
assert_eq!((is_guide(&s, a), undo_steps(&s)), (true, steps), "the guide stays a guide");
}
fn is_guide(s: &Session, id: NodeId) -> bool {
matches!(node(s, id).kind, NodeKind::Path { guide: true, .. })
}
#[test]
fn assigning_guides_makes_and_releases_a_guide() {
let (mut s, a, b) = doc();
s.execute("select.set", &json!({"ids": [b.0]})).unwrap();
let steps = undo_steps(&s);
let out = log(&mut s, "var p = app.activeDocument.pathItems[0]; p.guides = true; vc.log(p.guides);");
assert_eq!(out, vec![json!(true)]);
assert!(is_guide(&s, a));
assert_eq!(s.active().unwrap().selection.objects, vec![b], "the selection stays as it was");
assert_eq!(undo_steps(&s), steps + 1);
let r = run(&mut s, "app.activeDocument.pathItems[0].guides = true;").unwrap();
assert_eq!((undo_steps(&s), &r["slowestCommands"]), (steps + 1, &json!([])), "a value the path has runs no command");
log(&mut s, "app.activeDocument.pathItems[0].guides = false;");
assert!(!is_guide(&s, a));
assert_eq!(s.active().unwrap().selection.objects, vec![b]);
let out = log(&mut s, "try { app.activeDocument.pathItems[0].guides = 1; } catch (e) { vc.log(e.name); }");
assert_eq!(out, vec![json!("TypeError")]);
assert!(!is_guide(&s, a));
// A path in a group becomes a guide on its own; the other path in the group stays a path.
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
s.execute("object.group", &json!({})).unwrap();
s.execute("select.none", &json!({})).unwrap();
log(&mut s, "var p = app.activeDocument.pathItems[1]; p.name = 'assigned'; p.guides = true;");
let (assigned, other) = if node(&s, a).name.as_deref() == Some("assigned") { (a, b) } else { (b, a) };
assert_eq!(node(&s, assigned).name.as_deref(), Some("assigned"));
assert_eq!((is_guide(&s, assigned), is_guide(&s, other)), (true, false), "only the assigned path in the group is a guide");
assert!(s.active().unwrap().selection.is_empty(), "the selection stays as it was");
}
#[test]
fn assigning_guides_refuses_compound_members_clipping_paths_and_paths_that_cannot_be_edited() {
let (mut s, a, b) = doc();
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
s.execute("object.compoundPath.make", &json!({})).unwrap();
s.execute("select.none", &json!({})).unwrap();
let before = art(&s);
let e = failure(&mut s, "app.activeDocument.pathItems[0].guides = true;");
assert!(e.contains("compound path"), "{e}");
assert_eq!((art(&s), is_guide(&s, a), is_guide(&s, b)), (before, false, false), "no member of the compound path changed");
let (mut s, a, b) = doc();
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
s.execute("object.clippingMask.make", &json!({})).unwrap();
s.execute("select.none", &json!({})).unwrap();
let before = art(&s);
let e = failure(&mut s, "var ps = app.activeDocument.pathItems; for (var i = 0; i < ps.length; i++) if (ps[i].clipping) ps[i].guides = true;");
assert!(e.contains("clipping path"), "{e}");
assert_eq!(art(&s), before);
for cmd in ["object.lock", "object.hide"] {
let (mut s, a, _) = doc();
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
s.execute(cmd, &json!({})).unwrap();
s.execute("select.none", &json!({})).unwrap();
let e = failure(&mut s, "app.activeDocument.pathItems[0].guides = true;");
assert!(e.contains("Cannot edit"), "{cmd}: {e}");
assert!(!is_guide(&s, a), "{cmd}");
}
}
#[test]
fn assigning_guides_throws_in_both_directions_while_guides_are_locked() {
let (mut s, a, b) = doc();
log(&mut s, "app.activeDocument.pathItems[0].guides = true;");
assert!(is_guide(&s, a));
s.set_guides_locked(true);
let steps = undo_steps(&s);
let e = failure(&mut s, "app.activeDocument.pathItems[0].guides = false;");
assert!(e.contains("guides are locked"), "{e}");
let e = failure(&mut s, "app.activeDocument.pathItems[1].guides = true;");
assert!(e.contains("guides are locked"), "{e}");
assert_eq!((is_guide(&s, a), is_guide(&s, b), undo_steps(&s)), (true, false, steps));
log(&mut s, "var ps = app.activeDocument.pathItems; ps[0].guides = true; ps[1].guides = false;");
assert_eq!((is_guide(&s, a), is_guide(&s, b), undo_steps(&s)), (true, false, steps), "a value the path has runs no command");
}
@@ -124,8 +124,8 @@ const INSIDE: &[(&str, &str)] = &[
(
"PathItem.prototype.",
"area clipping closed closed= constructor evenodd evenodd= fillColor fillColor= fillOverprint fillOverprint= filled \
filled= guides length pathPoints polarity polarity= resize resolution resolution= rotate selectedPathPoints \
selectedPathPoints= setEntirePath strokeCap strokeCap= strokeColor strokeColor= strokeDashOffset strokeDashOffset= \
filled= guides guides= length pathPoints polarity polarity= resize resolution resolution= rotate selectedPathPoints \
setEntirePath strokeCap strokeCap= strokeColor strokeColor= strokeDashOffset strokeDashOffset= \
strokeDashes strokeDashes= strokeJoin strokeJoin= strokeMiterLimit strokeMiterLimit= strokeOverprint strokeOverprint= \
strokeWidth strokeWidth= stroked stroked= translate",
),
+3 -1
View File
@@ -946,7 +946,9 @@ mod tests {
let mut app = app();
open(&mut app);
set(&app, "artboards", json!(5)).unwrap();
set(&app, "artboardLayout", json!({"layout": "gridByColumn", "rows": 3.6, "spacing": 10})).unwrap();
// Rows that are not a whole number are refused, as `file.new` refuses them.
assert!(set(&app, "artboardLayout", json!({"layout": "gridByColumn", "rows": 3.6, "spacing": 10})).is_err());
set(&app, "artboardLayout", json!({"layout": "gridByColumn", "rows": 4, "spacing": 10})).unwrap();
assert_eq!(fields(&app)["artboardLayout"]["rows"], json!(4));
create(&mut app);
let st = app.session.active().unwrap();
+1 -1
View File
@@ -812,7 +812,7 @@ macOS cursor delivery (#2292) is narrowed to a native host adapter using the exi
## G6 Automation and scripting
- **Missing:** the rest of the document object model for scripts (layers, artboards, stories and threads of type,
the selected path points, gradient stops and the other classes) and the `#engine` script directive (#1183 is
gradient stops and the other classes) and the `#engine` script directive (#1183 is
open). Scripts have `app`, the open documents, new documents, each document's selection and its page items, its
text frames with their text ranges and character and paragraph attributes, and the installed fonts, and
`Document.pathItems` makes paths and reads and changes their points, colors, stroke options and transforms. File › Scripts › Other Script… and `script.run` run JavaScript files over the command registry, `#targetengine`
+37 -19
View File
@@ -2901,8 +2901,10 @@ app through the global object `vc`, and writes to the Script Console and runs ot
and `TextRange.changeCaseTo`, throw an error that says they are not available yet, and `start`, `end`,
`characterOffset` and `orientation` cannot be set yet.
- `Document.pathItems` (https://ai-scripting.docsforadobe.dev/jsobjref/PathItems/) lists the document's paths in the
order of `pageItems`, paths inside groups and compound paths included, with `length`, `[i]`, `index(key)`,
`getByName(name)`, `removeAll()`, `add()` (a path with no points, from `path.create`, painted as new art; when new
order of `pageItems`, paths inside groups and compound paths included, with `length`, `[i]`, `[name]` (read as
`pageItems["name"]` is read), `index(key)`,
`getByName(name)`, `removeAll()` (when any path is on a locked artboard, it throws
`cannot delete objects on a locked artboard` and deletes nothing), `add()` (a path with no points, from `path.create`, painted as new art; when new
art has no fill and no stroke, the path has neither), and the shape creators
`rectangle(top, left, width, height, reversed?)`, `roundedRectangle(top, left, width, height, horizontalRadius = 15,
verticalRadius = 20, reversed?)`, `ellipse(top = 100, left = 100, width = 50, height = 100, reversed?, inscribed?)`,
@@ -2912,22 +2914,29 @@ app through the global object `vc`, and writes to the Script Console and runs ot
art is painted. `add()` and the shape creators put the new path on top of the active layer whatever the drawing
mode, which stays as it was. A `PathItem` (https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/) adds to the page item
members `pathPoints`, `closed`, `evenodd`, `area` (negative for a path that runs counterclockwise), `length`,
`guides`, `clipping`, `setEntirePath(points)`, `filled`, `fillColor`, `fillOverprint`, `stroked`, `strokeColor`,
`strokeOverprint`, `strokeWidth`, `strokeCap`, `strokeJoin`, `strokeMiterLimit` (1 to 500), `strokeDashes`,
`strokeDashOffset`, `translate(deltaX?, deltaY?, ...)`, `rotate(angle, ..., rotateAbout?)` (counterclockwise for a
positive angle) and `resize(scaleX, scaleY, ..., changeLineWidths?, scaleAbout?)`. The geometry changes through
`path.setAnchors`, the fill and stroke through `paint.setFill` and `paint.setStroke`, the stroke options through
`stroke.set`, the fill rule through `path.setFillRule`, overprint through `object.setOverprint` and the transforms
through `object.move`, `object.rotate` and `object.scale`. Changes to the points of a path (`closed`,
`setEntirePath`, `pathPoints` and each `PathPoint`) are written together with one `path.setAnchors` before the
script uses any other member or command, or the points of another path, and when the script ends; a path aligned
to the pixel grid, or in an object that is, is written at each change, so its points read as the grid snaps them.
`guides`, `clipping`, `selectedPathPoints`, `setEntirePath(points)`, `filled`, `fillColor`, `fillOverprint`,
`stroked`, `strokeColor`, `strokeOverprint`, `strokeWidth`, `strokeCap`, `strokeJoin`, `strokeMiterLimit` (1 to
500), `strokeDashes`, `strokeDashOffset`, `translate(deltaX?, deltaY?, ...)`, `rotate(angle, ..., rotateAbout?)`
(counterclockwise for a positive angle) and `resize(scaleX, scaleY, ..., changeLineWidths?, scaleAbout?)`. The
geometry changes through `path.setAnchors`, the fill and stroke through `paint.setFill` and `paint.setStroke`, the
stroke options through `stroke.set`, the fill rule through `path.setFillRule`, overprint through
`object.setOverprint` and the transforms through `object.move`, `object.rotate` and `object.scale`. Changes to the
points of a path (`closed`, `setEntirePath`, `pathPoints` and each `PathPoint`) are written together with one
`path.setAnchors` before the script uses any other member or command, or the points of another path, and when the
script ends; a path aligned to the pixel grid, or in an object that is, is written at each change, so its points
read as the grid snaps them.
`pathPoints`
(https://ai-scripting.docsforadobe.dev/jsobjref/PathPoints/) has `length`, `[i]`, `index(i)`, `add()` and
`removeAll()`, and each `PathPoint` (https://ai-scripting.docsforadobe.dev/jsobjref/PathPoint/) has `anchor`,
`leftDirection` (the handle into the point), `rightDirection` (the handle out of it), `pointType`, `parent` and
`remove()`. `new RGBColor()` (0 to 255), `new CMYKColor()` (0 to 100), `new GrayColor()` (0 to 100, 0 black and 100
white, as https://ai-scripting.docsforadobe.dev/jsobjref/GrayColor/ gives it), `new LabColor()` and `new NoColor()`
`leftDirection` (the handle into the point), `rightDirection` (the handle out of it), `pointType`, `selected`,
`parent` and `remove()`. Assigning `guides` makes the path a guide with `view.guides.make` (`true`) or a path again
with `view.guides.release` (`false`), with the selection kept; a value that is not a boolean throws a `TypeError`.
`PathPoint.selected` reads `PathPointSelection.ANCHORPOINT` for a selected anchor point and
`PathPointSelection.NOSELECTION` otherwise; assigning `ANCHORPOINT` adds the point to the direct-selected anchors and
`NOSELECTION` removes it, through `select.anchorsMany`, with the other selected objects and anchors kept.
`selectedPathPoints` lists the points that read `ANCHORPOINT`, in the order of `pathPoints`. `new RGBColor()` (0 to
255), `new CMYKColor()` (0 to 100), `new GrayColor()` (0 to 100, 0 black and 100 white, as
https://ai-scripting.docsforadobe.dev/jsobjref/GrayColor/ gives it), `new LabColor()` and `new NoColor()`
(https://ai-scripting.docsforadobe.dev/jsobjref/NoColor/) make plain color objects; assigning a `NoColor` removes
the fill or stroke. The enumerations `PointType`, `PathPointSelection`, `StrokeCap`, `StrokeJoin`, `PolarityValues`
and `Transformation` hold strings such as `"StrokeCap.ROUNDENDCAP"`.
@@ -2939,8 +2948,17 @@ app through the global object `vc`, and writes to the Script Console and runs ot
a point of its path (`remove()`, `removeAll()`) or replaced its points (`setEntirePath`), or before anything other
than the object model changed the path's points (a command run with `vc.run`, such as `path.setAnchors`,
`object.move` or `edit.undo`); points stay valid through the object model's other changes to the path or to an
object that holds it, such as `translate()`. Color components left out
count as 0, `new
object that holds it, such as `translate()`. Every point of a path selected as a whole is a selected anchor point,
and the endpoints of selected segments are not; a path in a selected group or compound path is selected as a whole.
Direction handles are not selected on their own, so assigning `LEFTDIRECTION`, `RIGHTDIRECTION` or `LEFTRIGHTPOINT`
to `selected` throws an error that says it is not available yet, and so does assigning `NOSELECTION` to a point of a
path in a selected group or compound path. Selecting a point of a path with selected segments replaces that path's
segment selection. Changing `selected` adds no undo step. Selecting a point of a path that cannot be selected
throws `Cannot select`, and selecting a point of a guide while guides are locked throws an error. A clipping path
cannot be made a guide, and `guides = true` on one throws an error. Assigning `guides` the value a path already
has runs no command. Assigning the other value throws an error that says it is not available yet on a path inside
a compound path, throws `Cannot edit` on a path that is hidden, locked or cannot be selected, and throws an error
while guides are locked. Color components left out count as 0, `new
cmykColor()` makes a `CMYKColor`, `LabColor.l` is 0 to 100 and `a` and `b` are -128 to 128, and a component out of
range throws a `RangeError` when the color is assigned, with nothing changed. A component reads with the fewest
decimals, at least 4, that give the stored value back, so assigning a color read from a path leaves the path as it
@@ -2960,8 +2978,8 @@ app through the global object `vc`, and writes to the Script Console and runs ot
that is hidden or locked, or that is in a hidden or locked layer or group, throws `Cannot edit` with nothing
changed. A path in a compound path or compound shape reads the fill, stroke and overprint of that compound path or
shape, which the paint commands paint in its place. A change to a path's paint or stroke leaves the paint for new
art, the active Fill or Stroke proxy and Recent Colors as they were. `selectedPathPoints`, `PathPoint.selected`,
`transform`, `polarity`, the gradient stops and the document's default paint are not available yet.
art, the active Fill or Stroke proxy and Recent Colors as they were. `transform`, `polarity`, the gradient stops and
the document's default paint are not available yet.
- `$.write(...values)` writes the values to the Script Console with no separator, each as `String(value)` gives it, and
`$.writeln(...values)` does the same and ends the line. Each call counts as a host call.
- `$.evalFile(path, timeout?)` runs the file `path` names, relative to the file being run, in the same global
+1 -1
View File
@@ -198,7 +198,7 @@ Gujarati interface follow-up (2026-11-14): the catalog and zero/one plural rule
| M10 | Brushes, symbols, patterns, Repeat | 🟡 pattern swatches (5 tile types, Pattern Options, editing mode, SVG `<pattern>`/PDF export) and live Repeat (radial/grid/mirror) done; interactive selected mirror axis implemented (focused and native checks passed; full CI blocked by an unrelated text test); symbol libraries done (Window › Symbol Libraries, six generated libraries (Basic Shapes, UI Frames, Map Markers, Inventory Icons, Skill Icons, Weather Icons), User Defined, Other Library…, Save Symbols); brush libraries done (Window › Brush Libraries, fifteen generated libraries including Tech Circuit, Decorative, Engraving, Arrows, Stipple, Pressure Sensitive, Ink and Wash, Bristle Brushes and Dry Media, User Defined, Other Library…, Save Brushes); symbol editing shows draggable 9-slice guides (#5280), with guides outside the artwork still unsupported; brushes/symbols in progress | 23–37 |
| M11 | Artboards & views (selected-set deletion shared by Artboards menu, trash and Properties, retaining artboard 1 when all are selected; Artboard deletion keys keep the first of an all-selected set and protect artwork; history prunes invalid indices while preserving valid multiselection (history tests and full workspace CI pass); click-to-fit objects with the Artboard tool (#1227), artboard escape routing and document setup modal handoff done; artboard panel/tool with Move Artwork for X/Y fields and Artboard Options, Trim View (hiding the guides and the grid while it is on, #8363), middle-button pan, print tiling and the status bar's artboard navigator with synchronized Artboard tool selection done; Window › Arrange › Tile and Consolidate All Windows done; multiple windows, presentation polish) (cached canvas reprojection preserves scale during resize, rotation and DPI changes; regression-tested and contributor-confirmed 2026-10-19; estimates unchanged) (cached canvas dimensions match the renderer limit before cache-key creation, view construction and worker submission; regression-tested; estimates unchanged); status-bar pointer coordinates follow the active ruler origin and General units | 🟡; Artboard Options shares existing presets and orientation controls and can fit artwork without moving it; artwork fitting includes all drawn document art across artboards and off-board; artwork bounds are cached by active document and revision, and selection uses the shared bounds cache across artboards | 15–25 |
| M12 | Advanced color & art (CMYK/ICC, separations, Gradient Mesh, Live Paint, Image Trace, Graphs) | 🟡 Gradient Mesh, Live Paint, Image Trace (junction-returning pieces retain their positioned boundaries; a simpler contour walk with identical output; an edge's sub-pixel shift is the same from either side; notches read only their own piece; collapsed loops keep few segments; large images trace with a warning; Auto Color keeps rare distinct colours; quick presets trace at once and the Image Trace button opens the adjustment controls; Properties reopens them; tiny fitted contours retain islands and holes; Create Strokes: exact crop EDT, Guo–Hall thinning and maximal-disc graph simplification; 15 presets, the 14 documented ones each with an enhanced version; Ignore Color (manual picker and canvas eyedropper from original pixels, no canvas View change, missed pixels keep the pick armed, Preview/Undo retained; #8068), Shapes, Auto Grouping and Gradients options; measured in `image-trace-quality.md`; closed outlines retain their interior after straightening; the Flat Logo mode places edges to a fraction of a pixel, restores sharp corners, snaps lines and circles, and refuses gradients; live trace result bounds and selection highlights exclude the retained bitmap except in source-image views), Recolor Artwork, colour management (ICC, soft proofing, separations preview), Graphs (all 9 tools, Graph Data/Type, group-selected series colours persist through regenerate/save/open) done; Graph Design and Marker designs, Transpose and Switch x/y, `\|` label line breaks, the pie options, drop shadows, the legend across the top, overlapping widths, First Row/Column in Front, filled lines, kept label formatting and the Graph Data worksheet done; graph Column designs pending; Vector Halftone Preview keeps the selection box without drawing dot selection marks (#6369); Live Paint Bucket fills faces crossed in one drag (#6373) | 6–10 |
| M13 | Automation (Actions ✅ record/playback, persisted; variables, scripting, batch) | 🟡 MCP `add_text` exposes existing vertical point, area and path type; `script.run` and File › Scripts › Other Script… run JavaScript files, and Window › Script Console shows their output; scripts have `app`, the open documents, new documents, each document's selection and its page items, and `Document.pathItems` makes paths and reads and changes their points, colors, stroke options and transforms; the rest of the script document model (layers, artboards, type, the selected path points, gradient stops and the other classes) and batch work remain | 18–27 |
| M13 | Automation (Actions ✅ record/playback, persisted; variables, scripting, batch) | 🟡 MCP `add_text` exposes existing vertical point, area and path type; `script.run` and File › Scripts › Other Script… run JavaScript files, and Window › Script Console shows their output; scripts have `app`, the open documents, new documents, each document's selection and its page items, and `Document.pathItems` makes paths and reads and changes their points, colors, stroke options and transforms; the rest of the script document model (layers, artboards, type, gradient stops and the other classes) and batch work remain | 18–27 |
| M14 | 1.0 polish (Asset Export tile context menus implemented for G12; preferences, shortcut editor, workspaces, accessibility, packaging for all OSes) (status messages and readouts use stable responsive allocations sized for localized labels and ordinary coordinates; sample widths cached by language/unit/DPI; regression-tested and contributor-confirmed 2026-10-19; estimates unchanged) | 🟡 Icon-strip flyouts resize on their free edges and retain sizes (#5713); interim macOS cursor delivery (#2292) uses existing artwork and host-owned AppKit cursors; headless coverage only, native menu/focus/handback and display validation pending. Dock groups collapse to their tabs by a double-click on a tab (UI.8); Preferences › General › Constrain Angle acts for the arrow keys, Shift drags and new objects (#394, 2026-10-21); numeric-field pointer selection and focus regression-tested (#1326; a release more than 1 pt from the press keeps the caret, a tap within 1 pt selects all, #6659); RPM runtime capabilities and glibc floor checked (#1275; real-distro install/start-up pending), Eyedropper cursor with precise-setting checks (#1269), Preferences, shortcut editor (chords with Shift and a punctuation key fire as typed; other apps' text shortcut sets imported), workspaces (each keeps its layout changes until Reset <name>, UI.7), Window › Help Bar shown or hidden apart from the status bar and kept in saved workspaces, panels docked by dragging into any dock group (as tabs or a top/bottom split) or into the icon column, and closed from a dock tab's context menu (UI.6), a custom title bar on Windows/Linux with a Home button, content-sized dialogs, menus that scroll when longer than the window and macOS native menu dismissal done (M14.8), and native macOS save sheets with a Format menu (#866); titled PDF exports set `DisplayDocTitle` for viewers and accessibility checkers (#3646) and give the document language as the catalog's `/Lang` (#3644); accessibility and broader Windows/Linux packaging/QA pending; floating tab groups collapse into the side icon rail and opened rail panels fold back into it (#5925, in part), with pointer and native-window regression coverage; estimates unchanged; numeric spinner arrows keep repeating while held with the mouse (#6307); Swatches item context menus tested in all five views and rendered layouts inspected; Linux full CI passed, Windows engine baseline limitations documented (G12); Graphic Styles item context menus in thumbnail and list views with Options, Duplicate, Delete, Redefine, Break Link (#8755); Appearance panel row context menus for strokes, fills, effects, and root object row (Duplicate, Delete, Hide/Show, Edit Effect…, Clear Appearance, Reduce to Basic Appearance) with secondary click row selection (#8809); Character Styles and Paragraph Styles item context menus (panels::text_styles::tests::right_click_context_menu_*); Window > Toolbars > Compact Tools offers optional denser main Tools spacing in one or two columns, with the existing layout still the default (#7234) | 18–28 |
| — | Interaction fidelity pass (every tool's modifiers, Properties panel per context, isolation, nuance; width-point creation and adjoining adjustment regression-tested; dialog layout reviewed) | ⬜ (new ruler-guide Alt orientation implemented; existing-guide Escape cancellation regression-tested; broader pass remains) | 60–90 |
| — | Hardening at scale (big-file corpus, fuzzing, cross-platform + browser QA) | 🟡 PngSuite integrity and bounded fetching verified (#1729); real-world corpus/manual QA remain | 50–80 |
+1 -1
View File
@@ -1042,7 +1042,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`). 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/). Layers and the other classes are not there yet. `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, fill and stroke colors, stroke weight) 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/, https://ai-scripting.docsforadobe.dev/jsobjref/CharacterAttributes/ and https://ai-scripting.docsforadobe.dev/jsobjref/TextFonts/ describe them (`docs/mcp.md`). Offsets count UTF-16 units, VectorCraft's own rule. Stories, threading, lines, styles and tab stops are not there yet. `crates/engine/src/tests/script_text.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, 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`). The transforms move gradients with the art: `changeFillGradients` false throws an error, as do `changeFillPatterns` and `changeStrokePattern` given as different values, and `transform` is not there yet (`docs/mcp.md` lists these limits). Gradient stops and the document's default paint are not there yet. `crates/engine/src/tests/script_dom_paths.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, 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, its area and length are read-only, and `RGBColor`, `CMYKColor`, `GrayColor`, `LabColor` and `NoColor` make colors (`docs/mcp.md`). The transforms move gradients with the art: `changeFillGradients` false throws an error, as do `changeFillPatterns` and `changeStrokePattern` given as different values, and `transform` is not there yet (`docs/mcp.md` lists these limits). Gradient stops and the document's default paint are not there yet. `crates/engine/src/tests/script_dom_paths.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`.