From 0d5850f616e46c7258df6cd5c6ed9b702823313d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 18:41:43 -0800 Subject: [PATCH] Scripts: build on main's optional item bounds and painting-tool check main's item_rect now gives no bounds for an empty object, and the Live Paint Bucket check became tool_paints for the fill and the stroke. rotate and resize leave a path without bounds unchanged, and appearance.setNewArt uses the same inheritance test as paint.rs. --- crates/engine/src/cmd/newart.rs | 6 +++++- crates/engine/src/script/dom.rs | 4 +--- crates/engine/src/script/dom/defaults.rs | 12 ++---------- crates/engine/src/script/dom/paths.rs | 23 +++++++++++++++-------- crates/engine/src/tests/script_dom.rs | 8 +++++--- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/crates/engine/src/cmd/newart.rs b/crates/engine/src/cmd/newart.rs index 2637927046..f9563ee886 100644 --- a/crates/engine/src/cmd/newart.rs +++ b/crates/engine/src/cmd/newart.rs @@ -172,7 +172,11 @@ fn set_new_art(s: &mut Session, p: &Value) -> Result { return Err(bad(C, "dashOffset needs a dash pattern")); } let nothing = fill.is_none() && stroke.is_none() && change.is_empty() && fill_overprint.is_none() && stroke_overprint.is_none(); - if !nothing && !s.prefs.new_art_basic && !s.bucket_paints() && s.active().is_some_and(|st| !st.selection.subjects().is_empty()) { + if !nothing + && !s.prefs.new_art_basic + && !(s.tool_paints(false) && s.tool_paints(true)) + && s.active().is_some_and(|st| !st.selection.subjects().is_empty()) + { return Err(bad( C, "with New Art Has Basic Appearance off, new art takes the selected object's appearance: deselect it or turn the option on", diff --git a/crates/engine/src/script/dom.rs b/crates/engine/src/script/dom.rs index 39c22665fd..b02050c5c5 100644 --- a/crates/engine/src/script/dom.rs +++ b/crates/engine/src/script/dom.rs @@ -2868,9 +2868,7 @@ fn classes(link: &Link) -> Vec { ]); document.extend(defaults::document_members(l)); document.extend( - ["layers", "artboards", "groupItems", "swatches", "symbols", "activeLayer", "saveAs", "close"] - .into_iter() - .map(|m| later(l, "Document", m)), + ["layers", "artboards", "groupItems", "swatches", "symbols", "activeLayer", "saveAs", "close"].into_iter().map(|m| later(l, "Document", m)), ); document.extend(variables::document_members(l)); document.push(("tags".into(), get(l, tags::doc_tags), MemberInfo { collection: true, ..typed("Tags") })); diff --git a/crates/engine/src/script/dom/defaults.rs b/crates/engine/src/script/dom/defaults.rs index 4b8e24cbb3..9080d30dd7 100644 --- a/crates/engine/src/script/dom/defaults.rs +++ b/crates/engine/src/script/dom/defaults.rs @@ -192,18 +192,10 @@ pub(super) fn document_members(l: &Link) -> Vec { named(vec![ ("defaultFillColor", property(l, |h, a| default_color(h, a, true), |h, a| set_default_color(h, a, true)), typed("Color")), ("defaultFilled", property(l, |h, a| default_painted(h, a, true), |h, a| set_default_painted(h, a, true)), typed("boolean")), - ( - "defaultFillOverprint", - property(l, |h, a| default_overprint(h, a, true), |h, a| set_default_overprint(h, a, true)), - typed("boolean"), - ), + ("defaultFillOverprint", property(l, |h, a| default_overprint(h, a, true), |h, a| set_default_overprint(h, a, true)), typed("boolean")), ("defaultStrokeColor", property(l, |h, a| default_color(h, a, false), |h, a| set_default_color(h, a, false)), typed("Color")), ("defaultStroked", property(l, |h, a| default_painted(h, a, false), |h, a| set_default_painted(h, a, false)), typed("boolean")), - ( - "defaultStrokeOverprint", - property(l, |h, a| default_overprint(h, a, false), |h, a| set_default_overprint(h, a, false)), - typed("boolean"), - ), + ("defaultStrokeOverprint", property(l, |h, a| default_overprint(h, a, false), |h, a| set_default_overprint(h, a, false)), typed("boolean")), ( "defaultStrokeWidth", property(l, default_stroke_width, set_default_stroke_width), diff --git a/crates/engine/src/script/dom/paths.rs b/crates/engine/src/script/dom/paths.rs index 503e5c3ffe..356afe8b99 100644 --- a/crates/engine/src/script/dom/paths.rs +++ b/crates/engine/src/script/dom/paths.rs @@ -67,9 +67,9 @@ use vectorcraft_js::{Data, HostClass, HostError, HostItem, HostMember, MemberInf use vectorcraft_tools::params::gradient_params; use super::{ - Answer, Coords, Described, Doc, Item, Link, NOT_FOUND, STALE_ITEM, arg, boolean, class, colors, command, command_value, 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, returns, this_doc, typed, whole, with_doc, + Answer, Coords, Described, Doc, Item, Link, NOT_FOUND, STALE_ITEM, arg, boolean, class, colors, command, command_value, 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, returns, this_doc, typed, whole, with_doc, }; use crate::{DocState, NodeId, NodeKind}; @@ -1155,8 +1155,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)?; @@ -1185,8 +1186,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)?; @@ -1637,7 +1639,12 @@ fn pt_remove(h: &super::Host, a: &[Data]) -> Answer { pub(super) fn path_item_members(l: &Link) -> Vec { let transform = |first: &[(&'static str, &'static str)]| { let mut args: Vec<(&str, &str)> = first.to_vec(); - args.extend([("changePositions", "boolean"), ("changeFillPatterns", "boolean"), ("changeFillGradients", "boolean"), ("changeStrokePattern", "boolean")]); + args.extend([ + ("changePositions", "boolean"), + ("changeFillPatterns", "boolean"), + ("changeFillGradients", "boolean"), + ("changeStrokePattern", "boolean"), + ]); args }; let mut resize = transform(&[("scaleX", "number"), ("scaleY", "number")]); diff --git a/crates/engine/src/tests/script_dom.rs b/crates/engine/src/tests/script_dom.rs index 35d5c8e6a9..cf96155be9 100644 --- a/crates/engine/src/tests/script_dom.rs +++ b/crates/engine/src/tests/script_dom.rs @@ -1243,9 +1243,11 @@ fn a_startup_preset_alone_gives_its_first_size() { #[test] fn page_item_members_not_built_yet_throw_on_read_and_assignment() { let (mut s, _, _) = doc(); - for source in - ["app.activeDocument.pageItems[0].isIsolated;", "app.activeDocument.pageItems[0].uuid = 'x';", "app.activeDocument.pageItems[0].transform(5);"] - { + for source in [ + "app.activeDocument.pageItems[0].isIsolated;", + "app.activeDocument.pageItems[0].uuid = 'x';", + "app.activeDocument.pageItems[0].transform(5);", + ] { assert!(failure(&mut s, source).contains("is not available yet"), "{source}"); } assert!(failure(&mut s, "app.activeDocument.layers = 1;").contains("Document.layers is not available yet"));