Merge main into feat/scripts-api-layer-path-items

This commit is contained in:
dotCooCoo committed 2026-12-04 08:00:07 -08:00
commit 1ae7a5d5cb
66 files changed
+5239 -308

No files matched your search

+16 -1
View File
@@ -857,9 +857,24 @@ fn art_remove_all(h: &Host, a: &[Data], kind: Kind) -> Answer {
/// The ids (at most 20) among `ids` that are the clipping path of a group or layer that keeps other
/// objects once `ids` are deleted. Deleting one would leave the next object clipping the rest.
/// Deleting every path of a compound path would leave it empty, so a compound path that clips
/// counts as deleted too.
pub(super) fn kept_clipping_paths(d: &Document, ids: &[NodeId]) -> Vec<u64> {
let going: std::collections::HashSet<NodeId> = ids.iter().copied().collect();
let mut going: std::collections::HashSet<NodeId> = ids.iter().copied().collect();
let mut seen = std::collections::HashSet::new();
let mut emptied: Vec<NodeId> = Vec::new();
for p in ids.iter().filter_map(|i| d.parent_of(*i)) {
if going.contains(&p) || !seen.insert(p) {
continue;
}
let all_go = |n: &crate::doc::Node| n.children().is_some_and(|k| k.iter().all(|k| going.contains(&k.id)));
if d.node(p).is_some_and(|n| matches!(n.kind, NodeKind::Compound { .. }) && all_go(n)) {
emptied.push(p);
}
}
going.extend(emptied.iter().copied());
ids.iter()
.chain(&emptied)
.filter(|i| {
d.parent_of(**i).and_then(|p| d.node(p)).is_some_and(|p| {
let kids = p.children().map_or(&[][..], Vec::as_slice);
+15 -2
View File
@@ -425,6 +425,19 @@ fn paint_owner<'a>(d: &'a crate::Document, id: NodeId, n: &'a crate::doc::Node)
d.parent_of(id).and_then(|p| d.node(p)).filter(|p| matches!(p.kind, NodeKind::Compound { .. }) || p.is_compound_shape()).unwrap_or(n)
}
/// A script's new path goes on the active layer while it is shown and unlocked, or the topmost
/// shown, unlocked layer otherwise. While an opacity mask, pattern or symbol is being edited,
/// the path goes on the layer recorded by that edit mode. `create::on_layer` validates the layer.
fn new_path_layer(st: &crate::DocState) -> Option<NodeId> {
let d = &st.doc;
if let Some(layer) =
d.mask_edit.map(|e| e.layer).or_else(|| d.pattern_edit.as_ref().map(|e| e.layer)).or_else(|| d.symbol_edit.as_ref().map(|e| e.layer))
{
return Some(layer);
}
st.current_layer().filter(|l| d.is_editable(*l)).or_else(|| d.default_layer())
}
/// Runs a path creation command with its layer placement recorded.
fn drawing_normally(h: &super::Host, parent: Option<NodeId>, id: &str, params: &Value) -> std::result::Result<(Data, Value), HostError> {
let mut params = params.clone();
@@ -801,7 +814,7 @@ fn make_in(
fn make(h: &super::Host, doc: Doc, container: Option<NodeId>, id: &str, params: &Value, reversed: bool) -> Answer {
keeping_paint(h, || {
make_in(h, doc, container, |h| {
let parent = with_doc(h, doc, |_, st| st.current_layer().or_else(|| st.doc.default_layer()));
let parent = with_doc(h, doc, |_, st| new_path_layer(st));
let id = made_id(&drawing_normally(h, parent, id, params)?)?;
if reversed {
command(h, "path.reverse", &json!({"ids": [id.0]}))?;
@@ -965,7 +978,7 @@ fn items_add(h: &super::Host, a: &[Data]) -> Answer {
let ap = h.session.borrow().new_art();
ap.fill_paint().is_none() && ap.stroke_paint().is_none()
};
let parent = with_doc(h, doc, |_, st| st.current_layer().or_else(|| st.doc.default_layer()));
let parent = with_doc(h, doc, |_, st| new_path_layer(st));
let id = made_id(&drawing_normally(h, parent, "path.create", &json!({"d": ""}))?)?;
if unpainted {
command(h, "paint.setStroke", &json!({"none": true, "ids": [id.0], "objectOnly": true}))?;