mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Merge pull request #9283 from dotCooCoo/feat/scripts-page-item-blending-mode
Scripts: PageItem.blendingMode reads and sets an object's blending mode
This commit is contained in:
6 files changed
+226
-39
No files matched your search
@@ -576,23 +576,36 @@ struct ObjectOpacity {
|
||||
knockout_shape: bool,
|
||||
}
|
||||
|
||||
/// The series `id` belongs to when it is a graph series group or a path directly in one, as [`series_members`] finds
|
||||
/// it. Looked up through its parents, with no pass over the document.
|
||||
fn series_group_or_mark(doc: &Document, id: NodeId) -> Option<SeriesRef> {
|
||||
let node = doc.node(id)?;
|
||||
let chain = doc.ancestry(id)?;
|
||||
let parent = doc.node(*chain.iter().rev().nth(1)?)?;
|
||||
let in_graph = |group: &Node, graph: &Node| {
|
||||
let index = group.extras().series_index.and_then(|i| usize::try_from(i).ok())?;
|
||||
graph.extras().graph.as_deref().filter(|spec| index < series_count(spec)).map(|_| SeriesRef { graph: graph.id, group: group.id, index })
|
||||
};
|
||||
if let Some(r) = in_graph(node, parent) {
|
||||
return Some(r);
|
||||
}
|
||||
// Only the paths the graph draws again, not the copy of a graph design.
|
||||
if !matches!(node.kind, NodeKind::Path { .. }) {
|
||||
return None;
|
||||
}
|
||||
in_graph(parent, doc.node(*chain.iter().rev().nth(2)?)?)
|
||||
}
|
||||
|
||||
/// The graph, series, whether it is the series group itself (`true`) or a path directly in it, and the object
|
||||
/// transparency of each of `edited` that is one of those, in order.
|
||||
/// transparency of each of `edited` that is one of those, in order. Each object is looked up through its parents
|
||||
/// ([`series_group_or_mark`]), so an edit of a few objects does not read the rest of the document.
|
||||
fn object_opacity_captures(doc: &Document, edited: &[NodeId]) -> Vec<(NodeId, usize, bool, ObjectOpacity)> {
|
||||
if edited.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let members = series_members(doc);
|
||||
if members.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
edited
|
||||
.iter()
|
||||
.filter_map(|id| {
|
||||
let r = members.get(id)?;
|
||||
let r = series_group_or_mark(doc, *id)?;
|
||||
let group = r.group == *id;
|
||||
// Only the series group and the paths the graph draws again, not the copy of a graph design.
|
||||
let node = doc.node(*id).filter(|n| group || (doc.parent_of(*id) == Some(r.group) && matches!(n.kind, NodeKind::Path { .. })))?;
|
||||
let node = doc.node(*id)?;
|
||||
let mut look = ObjectOpacity {
|
||||
opacity: (node.opacity < 1.0).then_some(node.opacity),
|
||||
blend: (node.blend != BlendMode::Normal).then_some(node.blend),
|
||||
@@ -675,6 +688,25 @@ fn graph_labels(doc: &Document) -> HashMap<NodeId, (NodeId, Role)> {
|
||||
out
|
||||
}
|
||||
|
||||
/// The graph and kind of generated label `id`, as [`graph_labels`] finds it. Only the graphs among its parent and
|
||||
/// grandparent are read, with no pass over the document; `own` keeps each graph's labels read so far.
|
||||
fn graph_label_of(doc: &Document, id: NodeId, own: &mut HashMap<NodeId, HashMap<NodeId, Role>>) -> Option<(NodeId, Role)> {
|
||||
if !doc.node(id).is_some_and(|n| matches!(n.kind, NodeKind::Text(_))) {
|
||||
return None;
|
||||
}
|
||||
let chain = doc.ancestry(id)?;
|
||||
// The nearer graph first: [`graph_labels`] visits it later, so its entry is the one kept.
|
||||
for graph in chain.iter().rev().skip(1).take(2) {
|
||||
let Some(n) = doc.node(*graph) else { continue };
|
||||
let Some(spec) = n.extras().graph.as_deref() else { continue };
|
||||
let labels = own.entry(*graph).or_insert_with(|| own_labels(n, spec).into_iter().collect());
|
||||
if let Some(role) = labels.get(&id) {
|
||||
return Some((*graph, *role));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// The generated labels of graph `n` (with spec `g`) and what each shows, as [`graph_labels`] finds them.
|
||||
fn own_labels(n: &Node, g: &GraphSpec) -> Vec<(NodeId, Role)> {
|
||||
let mut out = vec![];
|
||||
@@ -1725,9 +1757,9 @@ fn label_rows_of(doc: &Document, ids: &[NodeId]) -> Vec<(NodeId, Role, Option<ve
|
||||
if !ids.iter().any(|id| doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Text(_)))) {
|
||||
return vec![];
|
||||
}
|
||||
let labels = graph_labels(doc);
|
||||
let mut own = HashMap::new();
|
||||
let mut picked: Vec<(NodeId, Role, Option<vectorcraft_doc::LabelRows>)> = vec![];
|
||||
for (&(g, role), n) in ids.iter().rev().filter_map(|id| Some((labels.get(id)?, doc.node(*id)?))) {
|
||||
for ((g, role), n) in ids.iter().rev().filter_map(|id| Some((graph_label_of(doc, *id, &mut own)?, doc.node(*id)?))) {
|
||||
if !picked.iter().any(|(pg, pr, _)| *pg == g && *pr == role) {
|
||||
picked.push((g, role, label_rows(n)));
|
||||
}
|
||||
|
||||
@@ -59,11 +59,12 @@
|
||||
//! A center outside the canvas after coordinate conversion throws a `RangeError`.
|
||||
//! - Members the help pages list that are not here yet throw an error that says so, and `reflect`
|
||||
//! leaves them out.
|
||||
//! - Assigning `hidden`, `locked`, `opacity`, `position`, `left`, `top`, `width` or `height` to an
|
||||
//! object in a hidden or locked layer, and `zOrder()` on one, throw `Cannot edit` and change
|
||||
//! nothing, even for the value the object has. The exception is `opacity` given the value the
|
||||
//! object has when that changes nothing; on a graph's mark or label whose series or kind keeps
|
||||
//! another opacity it would still change the graph, so it is refused too. Its `name` and `note`
|
||||
//! - Assigning `hidden`, `locked`, `opacity`, `blendingMode`, `position`, `left`, `top`, `width` or
|
||||
//! `height` to an object in a hidden or locked layer, and `zOrder()` on one, throw `Cannot edit`
|
||||
//! and change nothing, even for the value the object has. The exception is `opacity` or
|
||||
//! `blendingMode` given the value the object has when that changes nothing; on a graph's mark or
|
||||
//! label whose series or kind keeps another opacity or blend mode it would still change the graph,
|
||||
//! so it is refused too. Its `name` and `note`
|
||||
//! still change. An object that is hidden or locked itself, or is in a hidden or locked group,
|
||||
//! takes them.
|
||||
//! - `name` and `note` take a number or a Boolean as the text `String(value)` gives.
|
||||
@@ -81,6 +82,7 @@ use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::BlendMode;
|
||||
use vectorcraft_geom::{Point, Rect};
|
||||
use vectorcraft_js::{
|
||||
ArgInfo, Data, HostClass, HostError, HostFunction, HostItem, HostMember, MemberInfo, Realm, RunError, host_ref, host_ref_parts,
|
||||
@@ -2031,6 +2033,56 @@ fn item_set_opacity(h: &Host, a: &[Data]) -> Answer {
|
||||
set_props(h, a, |_| false, json!({"opacity": now.unwrap_or(v)}))
|
||||
}
|
||||
|
||||
/// The members of `BlendModes` with the blend mode each one names.
|
||||
const BLEND_MODES: [(&str, BlendMode); 16] = [
|
||||
("COLORBLEND", BlendMode::Color),
|
||||
("COLORBURN", BlendMode::ColorBurn),
|
||||
("COLORDODGE", BlendMode::ColorDodge),
|
||||
("DARKEN", BlendMode::Darken),
|
||||
("DIFFERENCE", BlendMode::Difference),
|
||||
("EXCLUSION", BlendMode::Exclusion),
|
||||
("HARDLIGHT", BlendMode::HardLight),
|
||||
("HUE", BlendMode::Hue),
|
||||
("LIGHTEN", BlendMode::Lighten),
|
||||
("LUMINOSITY", BlendMode::Luminosity),
|
||||
("MULTIPLY", BlendMode::Multiply),
|
||||
("NORMAL", BlendMode::Normal),
|
||||
("OVERLAY", BlendMode::Overlay),
|
||||
("SATURATIONBLEND", BlendMode::Saturation),
|
||||
("SCREEN", BlendMode::Screen),
|
||||
("SOFTLIGHT", BlendMode::SoftLight),
|
||||
];
|
||||
|
||||
fn item_blending_mode(h: &Host, a: &[Data]) -> Answer {
|
||||
read_item(h, a, |_, n| {
|
||||
let name = BLEND_MODES.iter().find(|(_, m)| *m == n.blend).map_or("NORMAL", |(name, _)| name);
|
||||
Ok(text(format!("BlendModes.{name}")))
|
||||
})
|
||||
}
|
||||
|
||||
/// `blendingMode = BlendModes.<MODE>`: the object's own blend mode, as `object.setProps` sets it.
|
||||
/// The mode the object already has may be assigned while its layer is hidden or locked, unless it
|
||||
/// would still replace the blend mode a graph keeps for the item's series or kind.
|
||||
fn item_set_blending_mode(h: &Host, a: &[Data]) -> Answer {
|
||||
let mode = match arg(a, 1) {
|
||||
Data::String(s) => s.strip_prefix("BlendModes.").and_then(|m| BLEND_MODES.iter().find(|(name, _)| *name == m)).map(|(_, mode)| *mode),
|
||||
_ => None,
|
||||
};
|
||||
let mode = mode.ok_or_else(|| HostError::Type("blendingMode needs a BlendModes value".into()))?;
|
||||
let item = this_item(h, a)?;
|
||||
let (same, keeps_other) = with_doc(h, item.doc, |_, st| {
|
||||
let d = &st.doc;
|
||||
let same = d.node(item.id).is_some_and(|n| n.blend == mode);
|
||||
let keeps_other =
|
||||
crate::cmd::graph::series_object_opacity_differs(d, &[item.id]) || crate::cmd::graph::label_object_opacity_differs(d, &[item.id]);
|
||||
(same, keeps_other)
|
||||
});
|
||||
if !same || keeps_other {
|
||||
refuse_protected_edit(h, item)?;
|
||||
}
|
||||
set_props(h, a, |_| false, json!({"blend": mode.label()}))
|
||||
}
|
||||
|
||||
fn item_selected(h: &Host, a: &[Data]) -> Answer {
|
||||
let item = this_item(h, a)?;
|
||||
Ok(Data::Bool(with_doc(h, item.doc, |_, st| st.selection.objects.contains(&item.id))))
|
||||
@@ -2550,6 +2602,8 @@ pub(super) fn install(realm: &mut Realm, link: &Link) -> std::result::Result<(),
|
||||
let items = members.iter().map(|m| (m.to_string(), HostItem::Value(text(format!("{name}.{m}"))))).collect();
|
||||
realm.define_host_object(name, items)?;
|
||||
}
|
||||
let blend_modes = BLEND_MODES.iter().map(|(m, _)| (m.to_string(), HostItem::Value(text(format!("BlendModes.{m}"))))).collect();
|
||||
realm.define_host_object("BlendModes", blend_modes)?;
|
||||
variables::define_enums(realm)?;
|
||||
realm.define_host_classes(classes(link), vec![("app".into(), host_ref("Application", &[]))])?;
|
||||
let l = link;
|
||||
@@ -2706,6 +2760,7 @@ fn classes(link: &Link) -> Vec<HostClass> {
|
||||
("locked", property(l, item_locked, item_set_locked), typed("boolean")),
|
||||
("selected", property(l, item_selected, item_set_selected), typed("boolean")),
|
||||
("opacity", property(l, item_opacity, item_set_opacity), MemberInfo { min: Some(0.0), max: Some(100.0), ..typed("number") }),
|
||||
("blendingMode", property(l, item_blending_mode, item_set_blending_mode), typed("BlendModes")),
|
||||
("position", property(l, item_position, item_set_position), typed("Array")),
|
||||
("left", property(l, item_left, item_set_left), typed("number")),
|
||||
("top", property(l, item_top, item_set_top), typed("number")),
|
||||
@@ -2731,7 +2786,6 @@ fn classes(link: &Link) -> Vec<HostClass> {
|
||||
page_item.extend(
|
||||
[
|
||||
"artworkKnockout",
|
||||
"blendingMode",
|
||||
"isIsolated",
|
||||
"layer",
|
||||
"pixelAligned",
|
||||
|
||||
@@ -394,6 +394,52 @@ fn an_opacity_a_graph_mark_already_has_replaces_the_one_its_series_keeps() {
|
||||
assert_eq!(kept(&s), None);
|
||||
}
|
||||
|
||||
/// A blend mode a graph mark or axis label already has still replaces the blend mode another object
|
||||
/// of its series or kind left on the graph, and is refused in a hidden or locked layer.
|
||||
#[test]
|
||||
fn a_blend_mode_a_graph_mark_or_label_already_has_replaces_the_one_the_graph_keeps() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();
|
||||
let csv = ",2024,2025\nQ1,3,2\nQ2,5,4";
|
||||
let r = s.execute("graph.create", &json!({"type": "column", "x": 100, "y": 100, "width": 300, "height": 200, "csv": csv})).unwrap();
|
||||
let id = NodeId(r["id"].as_u64().unwrap());
|
||||
let spec = |s: &Session| s.active().unwrap().doc.node(id).unwrap().extras().graph.as_deref().unwrap().clone();
|
||||
let kept_mark = |s: &Session| spec(s).series_paints.first().and_then(|p| p.blend);
|
||||
let kept_label = |s: &Session| spec(s).label_styles.values_rows.as_ref().and_then(|r| r.paint.blend);
|
||||
let graph = s.active().unwrap().doc.node(id).unwrap().clone();
|
||||
let group = graph.children().unwrap().iter().find(|c| c.extras().series_index == Some(0)).unwrap().clone();
|
||||
let marks: Vec<NodeId> = group.children().unwrap().iter().map(|m| m.id).collect();
|
||||
let axes = graph.children().unwrap().iter().find(|c| c.name.as_deref() == Some("Axes")).unwrap().clone();
|
||||
// The value axis numbers come first among the Axes group's labels.
|
||||
let labels: Vec<NodeId> = axes.children().unwrap().iter().filter(|c| matches!(c.kind, NodeKind::Text(_))).map(|c| c.id).collect();
|
||||
s.execute("object.setProps", &json!({"id": marks[0].0, "blend": "Multiply"})).unwrap();
|
||||
s.execute("object.setProps", &json!({"id": labels[0].0, "blend": "Screen"})).unwrap();
|
||||
let both = (Some(vectorcraft_color::BlendMode::Multiply), Some(vectorcraft_color::BlendMode::Screen));
|
||||
assert_eq!((kept_mark(&s), kept_label(&s)), both);
|
||||
s.execute("object.setProps", &json!({"id": marks[1].0, "name": "mark"})).unwrap();
|
||||
s.execute("object.setProps", &json!({"id": labels[1].0, "name": "label"})).unwrap();
|
||||
let layer = s.active().unwrap().doc.layers[0].id;
|
||||
for (on, off) in [
|
||||
(json!({"ids": [layer.0], "visible": false}), json!({"ids": [layer.0], "visible": true})),
|
||||
(json!({"ids": [layer.0], "locked": true}), json!({"ids": [layer.0], "locked": false})),
|
||||
] {
|
||||
s.execute("object.setProps", &on).unwrap();
|
||||
for name in ["mark", "label"] {
|
||||
let steps = undo_steps(&s);
|
||||
let e = failure(&mut s, &format!("var m = app.activeDocument.pageItems.getByName('{name}'); m.blendingMode = m.blendingMode;"));
|
||||
assert!(e.contains("Cannot edit"), "{on} {name}: {e}");
|
||||
assert_eq!((kept_mark(&s), kept_label(&s)), both, "{on} {name}");
|
||||
assert_eq!(undo_steps(&s), steps, "{on} {name}");
|
||||
}
|
||||
s.execute("object.setProps", &off).unwrap();
|
||||
}
|
||||
log(
|
||||
&mut s,
|
||||
"var p = app.activeDocument.pageItems; p.getByName('mark').blendingMode = BlendModes.NORMAL; p.getByName('label').blendingMode = BlendModes.NORMAL;",
|
||||
);
|
||||
assert_eq!((kept_mark(&s), kept_label(&s)), (None, None));
|
||||
}
|
||||
|
||||
/// `app.redraw()` returns `undefined` and leaves the art and the undo history as they were.
|
||||
#[test]
|
||||
fn redraw_returns_and_changes_nothing() {
|
||||
@@ -431,6 +477,51 @@ fn assigning_the_reported_opacity_changes_nothing() {
|
||||
assert_eq!(undo_steps(&s), steps + 1);
|
||||
}
|
||||
|
||||
/// `blendingMode` reads and sets the object's own blend mode as a `BlendModes` value; the mode it
|
||||
/// already has adds no undo step, and any other value throws and changes nothing.
|
||||
#[test]
|
||||
fn blending_mode_reads_and_sets_the_objects_blend_mode() {
|
||||
let (mut s, a, b) = doc();
|
||||
let blend = |s: &Session, id: NodeId| s.active().unwrap().doc.node(id).unwrap().blend;
|
||||
let steps = undo_steps(&s);
|
||||
let out = log(
|
||||
&mut s,
|
||||
"var i = app.activeDocument.pageItems[1]; vc.log(i.blendingMode);\
|
||||
i.blendingMode = BlendModes.MULTIPLY; vc.log(i.blendingMode);\
|
||||
vc.log([i.hasOwnProperty('blendingMode'), BlendModes.SATURATIONBLEND, BlendModes.COLORBLEND]);",
|
||||
);
|
||||
assert_eq!(out[..2], [json!("BlendModes.NORMAL"), json!("BlendModes.MULTIPLY")]);
|
||||
assert_eq!(out[2], json!([true, "BlendModes.SATURATIONBLEND", "BlendModes.COLORBLEND"]));
|
||||
assert_ne!(blend(&s, a), blend(&s, b), "only the assigned object changed");
|
||||
assert_eq!(undo_steps(&s), steps + 1, "one undo step for the run");
|
||||
let (before, steps) = (blend(&s, a), undo_steps(&s));
|
||||
log(&mut s, "var i = app.activeDocument.pageItems[1]; i.blendingMode = BlendModes.MULTIPLY; i.blendingMode = i.blendingMode;");
|
||||
assert_eq!((blend(&s, a), undo_steps(&s)), (before, steps), "the mode the object has adds no step");
|
||||
// Two modes the help page names with a suffix set the modes the Transparency panel calls Color
|
||||
// and Saturation.
|
||||
log(&mut s, "var p = app.activeDocument.pageItems; p[1].blendingMode = BlendModes.COLORBLEND; p[0].blendingMode = BlendModes.SATURATIONBLEND;");
|
||||
assert_eq!((blend(&s, a).label(), blend(&s, b).label()), ("Color", "Saturation"));
|
||||
let (before, steps) = (blend(&s, a), undo_steps(&s));
|
||||
for value in
|
||||
["'BlendModes.SCREEN '", "'MULTIPLY'", "'Multiply'", "'BlendModes.multiply'", "'BlendModes.NOPE'", "5", "null", "ZOrderMethod.BRINGTOFRONT"]
|
||||
{
|
||||
// The error is caught in the script, so the run does not roll back and the mode read right
|
||||
// after it is the one the setter left.
|
||||
let out = log(
|
||||
&mut s,
|
||||
&format!(
|
||||
"var i = app.activeDocument.pageItems[1], e = '';\
|
||||
try {{ i.blendingMode = {value}; }} catch (x) {{ e = String(x); }}\
|
||||
vc.log(e); vc.log(i.blendingMode);"
|
||||
),
|
||||
);
|
||||
let e = out[0].as_str().unwrap_or_default();
|
||||
assert!(e.contains("blendingMode needs a BlendModes value"), "{value}: {e}");
|
||||
assert_eq!(out[1], json!("BlendModes.COLORBLEND"), "{value}");
|
||||
assert_eq!((blend(&s, a), undo_steps(&s)), (before, steps), "{value}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selection_assignment_is_atomic_across_invalid_items() {
|
||||
let (mut s, a, b) = doc();
|
||||
@@ -1138,13 +1229,13 @@ fn a_startup_preset_alone_gives_its_first_size() {
|
||||
fn page_item_members_not_built_yet_throw_on_read_and_assignment() {
|
||||
let (mut s, _, _) = doc();
|
||||
for source in
|
||||
["app.activeDocument.pageItems[0].blendingMode;", "app.activeDocument.pageItems[0].uuid = 'x';", "app.activeDocument.pageItems[0].rotate(5);"]
|
||||
["app.activeDocument.pageItems[0].isIsolated;", "app.activeDocument.pageItems[0].uuid = 'x';", "app.activeDocument.pageItems[0].rotate(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"));
|
||||
// A deleted item or an earlier run's document is stale first.
|
||||
let e = failure(&mut s, "var i = app.activeDocument.pageItems[0]; i.remove(); i.blendingMode;");
|
||||
let e = failure(&mut s, "var i = app.activeDocument.pageItems[0]; i.remove(); i.isIsolated;");
|
||||
assert!(e.contains("Stale page item"), "{e}");
|
||||
run(&mut s, "#targetengine keep\nvar d = app.activeDocument;").unwrap();
|
||||
let e = failure(&mut s, "#targetengine keep\nd.layers;");
|
||||
@@ -1923,7 +2014,7 @@ fn unsupported_members_say_so() {
|
||||
|
||||
/// A script that names each visible selected object after its place in `app.selection`, testing
|
||||
/// the members it uses with `hasOwnProperty` and `propertyIsEnumerable` first. A member that is not
|
||||
/// available yet, such as `blendingMode`, is read only when `hasOwnProperty` reports it, so it is
|
||||
/// available yet, such as `isIsolated`, is read only when `hasOwnProperty` reports it, so it is
|
||||
/// never read.
|
||||
const NAME_PICKED: &str = "\
|
||||
var picked = app.selection, k = picked.length, named = 0;\
|
||||
@@ -1931,7 +2022,7 @@ const NAME_PICKED: &str = "\
|
||||
while (k--) {\
|
||||
var obj = picked[k];\
|
||||
var usable = obj.propertyIsEnumerable('name') && obj.hasOwnProperty('hidden') && !obj.hidden;\
|
||||
if (obj.hasOwnProperty('blendingMode') && obj.blendingMode) usable = false;\
|
||||
if (obj.hasOwnProperty('isIsolated') && obj.isIsolated) usable = false;\
|
||||
if (usable) { obj.name = 'picked ' + k; named += 1; }\
|
||||
}\
|
||||
if (picked.length && named < picked.length) alert('Some objects were skipped.');";
|
||||
@@ -2010,9 +2101,9 @@ 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('isIsolated'), p.hasOwnProperty('rotate'), 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')]);",
|
||||
vc.log([keys.indexOf('opacity') >= 0, keys.indexOf('typename') >= 0, keys.indexOf('duplicate'), keys.indexOf('isIsolated')]);",
|
||||
);
|
||||
assert_eq!(out[0], json!([true, true, true, true, true, true, true]));
|
||||
// Members that are not available yet, unknown names and inherited ones are not the object's own.
|
||||
@@ -2141,7 +2232,7 @@ fn a_collection_read_with_a_name_gives_the_named_object() {
|
||||
assert_eq!(out, vec![json!([true, "n", true, false, true]), json!([true, true, false]), json!(["Not found", "Not found"])]);
|
||||
}
|
||||
|
||||
/// `opacity`, `hidden`, `locked` and the position and size setters on an object in a hidden or
|
||||
/// `opacity`, `blendingMode`, `hidden`, `locked` and the position and size setters on an object in a hidden or
|
||||
/// locked layer throw and the run changes nothing, while its name and note still change; an object
|
||||
/// that is hidden or locked itself takes them.
|
||||
#[test]
|
||||
@@ -2161,6 +2252,7 @@ fn setters_refuse_art_in_a_hidden_or_locked_layer() {
|
||||
// `hidden` and `locked` are refused even when the value is the one the object has.
|
||||
for set in [
|
||||
"opacity = 50",
|
||||
"blendingMode = BlendModes.MULTIPLY",
|
||||
"hidden = true",
|
||||
"hidden = false",
|
||||
"locked = true",
|
||||
@@ -2182,9 +2274,9 @@ fn setters_refuse_art_in_a_hidden_or_locked_layer() {
|
||||
let out = log(
|
||||
&mut s,
|
||||
"var c = app.activeDocument.pageItems.getByName('closed'); c.note = 'n'; c.name = 'renamed'; c.opacity = c.opacity;\
|
||||
vc.log([c.name, c.note, c.opacity]); c.name = 'closed'; c.note = '';",
|
||||
c.blendingMode = c.blendingMode; vc.log([c.name, c.note, c.opacity, c.blendingMode]); c.name = 'closed'; c.note = '';",
|
||||
);
|
||||
assert_eq!(out, vec![json!(["renamed", "n", 100])], "{on}");
|
||||
assert_eq!(out, vec![json!(["renamed", "n", 100, "BlendModes.NORMAL"])], "{on}");
|
||||
s.execute("object.setProps", &off).unwrap();
|
||||
}
|
||||
s.execute("object.setProps", &json!({"ids": [a.0], "locked": true})).unwrap();
|
||||
@@ -2192,9 +2284,11 @@ fn setters_refuse_art_in_a_hidden_or_locked_layer() {
|
||||
let out = log(
|
||||
&mut s,
|
||||
"var p = app.activeDocument.pageItems; p.getByName('locked').opacity = 50; p.getByName('free').opacity = 40;\
|
||||
vc.log([p.getByName('locked').opacity, p.getByName('free').opacity]);",
|
||||
p.getByName('locked').blendingMode = BlendModes.SCREEN; p.getByName('free').blendingMode = BlendModes.DARKEN;\
|
||||
vc.log([p.getByName('locked').opacity, p.getByName('free').opacity, p.getByName('locked').blendingMode,\
|
||||
p.getByName('free').blendingMode]);",
|
||||
);
|
||||
assert_eq!(out, vec![json!([50, 40])]);
|
||||
assert_eq!(out, vec![json!([50, 40, "BlendModes.SCREEN", "BlendModes.DARKEN"])]);
|
||||
}
|
||||
|
||||
/// `name` takes a number or a Boolean as the text `String` gives it, and nothing else.
|
||||
|
||||
@@ -81,7 +81,7 @@ const INSIDE: &[(&str, &str)] = &[
|
||||
),
|
||||
(
|
||||
"",
|
||||
"activeDocument activeDocument= app Application CoordinateSystem Document DocumentArtboardLayout DocumentColorSpace \
|
||||
"activeDocument activeDocument= app Application BlendModes CoordinateSystem Document DocumentArtboardLayout DocumentColorSpace \
|
||||
DocumentPreset DocumentPresetType DocumentPreviewMode DocumentRasterResolution DocumentTransparencyGrid documents \
|
||||
Documents ElementPlacement Layer PageItem PageItems RulerUnits ScreenMode selection selection= Tag Tags View Views \
|
||||
ZOrderMethod",
|
||||
@@ -132,6 +132,11 @@ const INSIDE: &[(&str, &str)] = &[
|
||||
("Tags.prototype.", "add constructor getByName index length parent removeAll typename"),
|
||||
("Tag.", "prototype"),
|
||||
("Tag.prototype.", "constructor name name= parent remove typename value value="),
|
||||
(
|
||||
"BlendModes.",
|
||||
"COLORBLEND COLORBURN COLORDODGE DARKEN DIFFERENCE EXCLUSION HARDLIGHT HUE LIGHTEN LUMINOSITY MULTIPLY NORMAL \
|
||||
OVERLAY SATURATIONBLEND SCREEN SOFTLIGHT",
|
||||
),
|
||||
("CoordinateSystem.", "ARTBOARDCOORDINATESYSTEM DOCUMENTCOORDINATESYSTEM"),
|
||||
("DocumentArtboardLayout.", "Column GridByCol GridByRow RLGridByCol RLGridByRow RLRow Row"),
|
||||
("DocumentColorSpace.", "CMYK RGB"),
|
||||
|
||||
+9
-7
@@ -2882,7 +2882,9 @@ other files through `$`:
|
||||
Attributes panel's note, trimmed as `attributes.set` trims it), `hidden`, `locked`, `selected` (assigning it adds
|
||||
or removes only that object, as `select.add` and `select.toggle` do, and the other objects stay selected as they
|
||||
were), `opacity` (0 to
|
||||
100), `position`, `left`, `top`, `width`, `height`, `geometricBounds`, `visibleBounds`, `controlBounds` (the
|
||||
100), `blendingMode` (the object's own blend mode as a `BlendModes` value such as `"BlendModes.MULTIPLY"`
|
||||
(https://ai-scripting.docsforadobe.dev/jsobjref/scripting-constants/), set with `object.setProps`; `COLORBLEND` and `SATURATIONBLEND` are the Color and Saturation modes, and any other value
|
||||
throws `blendingMode needs a BlendModes value`), `position`, `left`, `top`, `width`, `height`, `geometricBounds`, `visibleBounds`, `controlBounds` (the
|
||||
visible bounds, widened to take in the direction points of every path in the object), `editable` (false for an
|
||||
object that is hidden or locked, in a hidden or locked layer or group, or on a locked artboard), `zOrderPosition`,
|
||||
`duplicate(relativeObject?, insertionLocation?)`,
|
||||
@@ -2896,12 +2898,12 @@ other files through `$`:
|
||||
the undo history as they were before the call. `move` on an object that is hidden or locked, inside a hidden or
|
||||
locked layer or group, or on a locked artboard throws `Cannot move` and moves nothing. `duplicate` on such an
|
||||
object, with or without a relative object, throws `Cannot duplicate` and makes no copy. Assigning `hidden`,
|
||||
`locked`, `opacity`, `position`, `left`, `top`, `width` or `height` to an object in a hidden or locked layer or on a locked artboard
|
||||
`locked`, `opacity`, `blendingMode`, `position`, `left`, `top`, `width` or `height` to an object in a hidden or locked layer or on a locked artboard
|
||||
throws `Cannot edit` and changes nothing, even when the value is the one the object has, and `zOrder()` on such
|
||||
an object throws `Cannot edit` too. The one exception is `opacity` given the value the object already has, which
|
||||
changes nothing and does not throw; on a graph's mark or label whose series or kind keeps another opacity, that
|
||||
an object throws `Cannot edit` too. The one exception is `opacity` or `blendingMode` given the value the object already has, which
|
||||
changes nothing and does not throw; on a graph's mark or label whose series or kind keeps another opacity or blend mode, that
|
||||
value would still change the graph, so it throws `Cannot edit` as well. Its `name` and `note` still change, and an
|
||||
object that is hidden or locked itself takes `hidden`, `locked` and `opacity` (VectorCraft's own rule). Position,
|
||||
object that is hidden or locked itself takes `hidden`, `locked`, `opacity` and `blendingMode` (VectorCraft's own rule). Position,
|
||||
size and stacking-order changes also require a selectable object. Other targets excluded by selection filtering,
|
||||
including guide paths while Lock Guides is on, throw `Cannot select`. `move` with the object itself
|
||||
as the relative object and `PLACEBEFORE` or `PLACEAFTER` leaves it where it is and adds no undo step. When `move`
|
||||
@@ -2912,7 +2914,7 @@ other files through `$`:
|
||||
`Duplicating a path inside a compound path is not available yet`, and `zOrder` on one throws
|
||||
`Reordering a path inside a compound path is not available yet` and leaves the document unchanged. A script that
|
||||
holds a placed image keeps the same object when the image is embedded: the next read gives that object, now a
|
||||
`RasterItem`. The enumerations `ElementPlacement`, `ZOrderMethod`, `RulerUnits`, `DocumentColorSpace`, `CoordinateSystem`,
|
||||
`RasterItem`. The enumerations `ElementPlacement`, `ZOrderMethod`, `BlendModes`, `RulerUnits`, `DocumentColorSpace`, `CoordinateSystem`,
|
||||
`DocumentArtboardLayout`, `DocumentPresetType`, `DocumentPreviewMode`, `DocumentRasterResolution` and
|
||||
`DocumentTransparencyGrid` hold strings such as `"ZOrderMethod.BRINGTOFRONT"`.
|
||||
`pageItems` lists the art topmost first, as the example on
|
||||
@@ -2957,7 +2959,7 @@ other files through `$`:
|
||||
`..`, a network path, a NUL character or more than 4,096 bytes throws an error. `app.redraw()` returns `undefined`
|
||||
and does not change the documents or add an undo step. In the app, the documents are drawn as they were before the
|
||||
run until the run ends, with or without the call. Some members the Application,
|
||||
Document and PageItem pages list, such as `Document.layers`, `PageItem.blendingMode`, `PageItem.rotate` and
|
||||
Document and PageItem pages list, such as `Document.layers`, `PageItem.isIsolated`, `PageItem.rotate` and
|
||||
`app.beep`, throw an error that says they are not available yet when they are read or assigned.
|
||||
`hasOwnProperty` and `propertyIsEnumerable` are false for those members and true for every other member of an
|
||||
object's class, so `item.hasOwnProperty("opacity")` is true on a page item, and `for (k in item)` lists the
|
||||
|
||||
@@ -1110,7 +1110,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- The control server writes each reply through a 64 KiB buffer. On Windows 11 it sends the 17 MB `document.inspect` reply of a document with 50,000 objects on one layer to a client over loopback in 0.09 s instead of 34 s.
|
||||
- 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: `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: 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/). `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`.
|
||||
- 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/). `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`. `Document.layers`, `Document.activeLayer`, paths, 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`.
|
||||
|
||||
Reference in new issue
Block a user