Merge main into feat/scripts-api-d3-layers-artboards

This commit is contained in:
dotCooCoo committed 2026-12-02 11:39:00 -08:00
commit cd3a0da644
375 files changed
+24589 -3335

No files matched your search

+41 -13
View File
@@ -69,9 +69,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, ON_LOCKED_ARTBOARD, 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};
@@ -248,8 +248,9 @@ fn read_points<T>(h: &super::Host, item: Item, f: impl FnOnce(&[SubPath]) -> T)
/// Changes the subpaths of the path of `item` with `f`. The change waits in [`super::State`] with
/// the path's other point changes until [`flush`] writes them. The first change of a path writes
/// the waiting changes of another path first, and throws `Cannot edit` when the path is hidden or
/// locked or is on a locked artboard ([`refuse_path_edit`]), unless it changes nothing. A path that is aligned to the pixel grid, or is in an object
/// that is, is written at once, so that its points read as the grid snaps them.
/// locked or is on a locked artboard ([`refuse_path_edit`]), unless it changes nothing. A path
/// that is aligned to the pixel grid, or is in an object that is, is written at once, so that its
/// points read as the grid snaps them.
fn edit_points<T>(h: &super::Host, item: Item, f: impl FnOnce(&mut Vec<SubPath>) -> T) -> std::result::Result<T, HostError> {
forget_waiting_starts(h);
if let Some((waiting, subs)) = &mut *h.dom.pending.borrow_mut()
@@ -427,13 +428,32 @@ 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. A key that is the text of a
/// number but not an array index, such as `-1` or `1.5`, reaches the indexer as a number and is
/// looked up as that name, giving `undefined` when no path has it.
fn items_at(h: &super::Host, a: &[Data]) -> Answer {
if super::layers::is_scoped(a, "PathItems") {
return super::layers::scoped_at(h, a);
}
let doc = items_doc(h, a)?;
let Data::Number(n) = arg(a, 1) else { return Ok(Data::Undefined) };
let Some(i) = whole(*n).and_then(|i| usize::try_from(i).ok()) else { return Ok(Data::Undefined) };
match arg(a, 1) {
Data::String(_) => match items_by_name(h, a) {
Err(HostError::Error(e)) if e == NOT_FOUND && super::probing(a) => Ok(Data::Undefined),
r => r,
},
Data::Number(n) => match super::position(*n) {
Some(i) => item_at(h, doc, i),
None => match items_named(h, doc, &vectorcraft_js::number_to_string(*n)) {
Err(HostError::Error(e)) if e == NOT_FOUND => Ok(Data::Undefined),
r => r,
},
},
_ => Ok(Data::Undefined),
}
}
/// The path at position `i` of `pathItems`, or `undefined` past the end.
fn item_at(h: &super::Host, doc: Doc, i: usize) -> Answer {
with_doc(h, doc, |_, st| Ok(path_items(h, st)?.get(i).map_or(Data::Undefined, |id| super::item_ref(h, st, *id))))
}
@@ -443,10 +463,15 @@ fn items_by_name(h: &super::Host, a: &[Data]) -> Answer {
}
let doc = items_doc(h, a)?;
let Data::String(name) = arg(a, 1) else { return Err(HostError::Type("give a name, as a string".into())) };
items_named(h, doc, name)
}
/// The first path of `pathItems` named `name`, or `Not found`.
fn items_named(h: &super::Host, doc: Doc, name: &str) -> Answer {
with_doc(h, doc, |_, st| {
let ids = path_items(h, st)?;
h.charge_call(ids.len() as u64)?;
let id = ids.iter().find(|i| st.doc.node(**i).and_then(|n| n.name.as_deref()) == Some(name.as_str()));
let id = ids.iter().find(|i| st.doc.node(**i).and_then(|n| n.name.as_deref()) == Some(name));
id.map(|id| super::item_ref(h, st, *id)).ok_or_else(|| HostError::Error(NOT_FOUND.into()))
})
}
@@ -454,10 +479,13 @@ fn items_by_name(h: &super::Host, a: &[Data]) -> Answer {
fn items_index(h: &super::Host, a: &[Data]) -> Answer {
match arg(a, 1) {
Data::String(_) => items_by_name(h, a),
Data::Number(_) => match items_at(h, a)? {
Data::Undefined => Err(HostError::Error(NOT_FOUND.into())),
d => Ok(d),
},
Data::Number(n) => {
let doc = items_doc(h, a)?;
match whole(*n).and_then(|i| usize::try_from(i).ok()).map(|i| item_at(h, doc, i)).transpose()? {
Some(Data::Undefined) | None => Err(HostError::Error(NOT_FOUND.into())),
Some(d) => Ok(d),
}
}
_ => Err(HostError::Type("give a name or an index".into())),
}
}
@@ -483,7 +511,7 @@ fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
}
if !on_locked.is_empty() {
let list = on_locked.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
return Err(HostError::Error(format!("{}: {list}", super::ON_LOCKED_ARTBOARD)));
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<_>>()})))?;
+7 -1
View File
@@ -545,6 +545,8 @@ struct Job {
paper_size: bool,
/// `colorProfileMode` is `SOURCEPROFILE`: the colors print as they are, whatever `name` says.
source: bool,
/// `colorProfileMode` is assigned `CUSTOMPROFILE`: `name` must name the profile.
custom: bool,
/// `printArea` is assigned: the artboards print even when the base settings ignore them.
print_area: bool,
/// The groups of `settings`: the top level and each nested object by its key.
@@ -693,6 +695,7 @@ fn map_color(h: &Host, slot: usize, job: &mut Job) {
let source = set.iter().any(|(k, v)| *k == "colorProfileMode" && member_of(v) == "SOURCEPROFILE");
job.profile = set.iter().find(|(k, _)| *k == "name").map(|(_, v)| string_of(v));
job.source = source;
job.custom = set.iter().any(|(k, v)| *k == "colorProfileMode" && member_of(v) == "CUSTOMPROFILE");
let g = job.group("color");
for (k, v) in &set {
if *k == "intent" {
@@ -992,7 +995,7 @@ fn prepare(h: &Host, doc: Doc, mut job: Job) -> Answer {
/// each assigned name against the list it must come from, and puts the checked names into the
/// job: a print or flattener preset by its name (any case), an RGB or CMYK color profile by its
/// name (any case) and a paper by its id or label. An empty name, or one with a path separator or
/// a control character, throws.
/// a control character, throws, and so does `CUSTOMPROFILE` with no profile `name`.
fn check_names(h: &Host, doc: Doc, job: &mut Job) -> std::result::Result<(), HostError> {
let (count, saved_ignore) = with_doc(h, doc, |_, st| {
let mode = st.doc.print_setup.as_ref().and_then(|v| v.get("artboards")).and_then(Value::as_str);
@@ -1022,6 +1025,9 @@ fn check_names(h: &Host, doc: Doc, job: &mut Job) -> std::result::Result<(), Hos
}
job.group("advanced").insert("flattenerPreset".into(), json!(n));
}
if job.custom && job.profile.is_none() {
return Err(HostError::Error("PrintColorManagementOptions.name must name a color profile for CUSTOMPROFILE".into()));
}
if let Some(name) = job.profile.take() {
let what = "PrintColorManagementOptions.name";
let n = plain_name(what, "color profile", &name)?;
+13 -7
View File
@@ -366,7 +366,12 @@ const AI_KEPT: &[(&str, Default)] = &[
];
fn ai_starts() -> Vec<(&'static str, Data)> {
vec![("compressed", Data::Bool(true)), ("pdfCompatible", Data::Bool(true)), ("embedICCProfile", Data::Bool(false))]
vec![
("compatibility", text("Compatibility.ILLUSTRATOR19")),
("compressed", Data::Bool(true)),
("pdfCompatible", Data::Bool(true)),
("embedICCProfile", Data::Bool(false)),
]
}
fn eps_map(name: &str, d: &Data, p: &mut Map<String, Value>) -> std::result::Result<bool, HostError> {
@@ -1010,12 +1015,13 @@ const SAVES_SOME_ARTBOARDS: &str =
"the save would keep only some of its artboards: save it with saveAs first, or close with SaveOptions.DONOTSAVECHANGES";
/// Whether the file that saving `st` with its remembered options writes would omit artboards. A
/// PDF with `useArtboards: false` holds one page of the art's bounds. A native file, or a `.ai`
/// file other than a legacy version 7 one, with `separateArtboards` holds every artboard, and its
/// `range` names only the separate files. An EPS file embeds the whole document in its main file,
/// so its `artboardRange` never omits an artboard from what reopens.
/// PDF with `useArtboards: false` holds one page of the art's bounds. A native file holds every
/// artboard, and its `range` names only the separate files of `separateArtboards`. A `.ai` file
/// other than a legacy version 7 one with `separateArtboards` holds every artboard too. An EPS
/// file embeds the whole document in its main file, so its `artboardRange` never omits an artboard
/// from what reopens.
fn picks_artboards(st: &crate::doc_state::DocState) -> bool {
if st.format == "eps" {
if matches!(st.format, "eps" | "vectorcraft" | "template") {
return false;
}
let options = Value::Object(crate::cmd::fileio::remembered_save_options(st));
@@ -1027,7 +1033,7 @@ fn picks_artboards(st: &crate::doc_state::DocState) -> bool {
return true;
}
let legacy = crate::cmd::fileio::saves_legacy_ai(st.format, &options);
if matches!(st.format, "vectorcraft" | "template" | "ai" | "ait") && options.get("separateArtboards") == Some(&Value::Bool(true)) && !legacy {
if matches!(st.format, "ai" | "ait") && options.get("separateArtboards") == Some(&Value::Bool(true)) && !legacy {
return false;
}
let count = st.doc.artboards.len();