mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 13:32:45 -05:00
Merge main into feat/scripts-api-layer-path-items
This commit is contained in:
commit
d5a54ccffa
109 files changed
+5772
-262
No files matched your search
@@ -627,40 +627,93 @@ fn items_index(h: &super::Host, a: &[Data]) -> Answer {
|
||||
/// locked 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()` does. A compound path's
|
||||
/// `pathItems.removeAll()` leaves the compound path, empty, as `remove()` of its last path does.
|
||||
/// Like `PageItems.removeAll()`, it throws and deletes nothing when it would delete the clipping
|
||||
/// path of a group or layer that keeps other objects.
|
||||
/// It also throws and deletes nothing when it would delete the clipping path of a group or layer
|
||||
/// that keeps other objects, or leave a compound path or group that clips one with no visible path
|
||||
/// or visible type that lays out glyphs to clip by.
|
||||
fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
|
||||
let (doc, c) = items_scope(h, a)?;
|
||||
let (ids, refused, on_locked, masks, tracing) = with_doc(h, doc, |_, st| {
|
||||
let ids = path_items(h, st, c)?;
|
||||
let d = &st.doc;
|
||||
if h.session.borrow().menu.guides_locked
|
||||
&& let Some(id) = ids.iter().find(|id| st.doc.node(**id).is_some_and(|n| matches!(n.kind, NodeKind::Path { guide: true, .. })))
|
||||
&& let Some(id) = ids.iter().find(|id| d.node(**id).is_some_and(|n| matches!(n.kind, NodeKind::Path { guide: true, .. })))
|
||||
{
|
||||
return Err(HostError::Error(format!("Cannot edit PathItem {}: guides are locked", id.0)));
|
||||
}
|
||||
let refused: Vec<u64> = ids.iter().filter(|i| !editable(&st.doc, **i)).map(|i| i.0).take(20).collect();
|
||||
let locks = st.doc.locked_artboards();
|
||||
let refused: Vec<u64> = ids.iter().filter(|i| !editable(d, **i)).map(|i| i.0).take(20).collect();
|
||||
let locks = d.locked_artboards();
|
||||
let on_locked: Vec<u64> = ids.iter().filter(|i| locks.holds_id(**i)).map(|i| i.0).take(20).collect();
|
||||
// Without `keepEmpty`, `edit.clear` also deletes a compound path it empties.
|
||||
let mut going: Vec<NodeId> = ids.to_vec();
|
||||
if c.is_none() {
|
||||
let listed: std::collections::HashSet<NodeId> = ids.iter().copied().collect();
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for p in ids.iter().filter_map(|i| st.doc.parent_of(*i)) {
|
||||
if !seen.insert(p) {
|
||||
continue;
|
||||
}
|
||||
let emptied = st.doc.node(p).is_some_and(|n| {
|
||||
matches!(n.kind, NodeKind::Compound { .. }) && n.children().is_some_and(|k| k.iter().all(|k| listed.contains(&k.id)))
|
||||
});
|
||||
if emptied {
|
||||
going.push(p);
|
||||
let mut next: Vec<_> = d.layers.iter().collect();
|
||||
let mut nodes = Vec::new();
|
||||
while let Some(n) = next.pop() {
|
||||
nodes.push(n);
|
||||
next.extend(n.children().into_iter().flatten());
|
||||
}
|
||||
let mut going: std::collections::HashSet<NodeId> = ids.iter().copied().collect();
|
||||
let mut affected: std::collections::HashSet<NodeId> = ids.iter().copied().collect();
|
||||
for n in nodes.iter().rev() {
|
||||
if n.children().into_iter().flatten().any(|k| affected.contains(&k.id)) {
|
||||
affected.insert(n.id);
|
||||
}
|
||||
}
|
||||
// Type is laid out only inside a mask that loses a path; no other outline decides a refusal.
|
||||
let mut in_mask = std::collections::HashSet::new();
|
||||
for n in &nodes {
|
||||
if n.clips()
|
||||
&& let Some(mask) = n.children().and_then(|k| k.first())
|
||||
&& affected.contains(&mask.id)
|
||||
{
|
||||
let mut stack = vec![mask];
|
||||
while let Some(m) = stack.pop() {
|
||||
if in_mask.insert(m.id) {
|
||||
stack.extend(m.children().into_iter().flatten());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let masks = super::layers::kept_clipping_paths(&st.doc, &going);
|
||||
let mut geometry = std::collections::HashSet::new();
|
||||
let mut masks = Vec::new();
|
||||
for n in nodes.into_iter().rev() {
|
||||
let kids = n.children().map_or(&[][..], Vec::as_slice);
|
||||
// Without `keepEmpty`, clear removes compound paths emptied of direct members, but keeps
|
||||
// empty groups. A compound path's own `pathItems.removeAll()` keeps it, empty.
|
||||
if c.is_none()
|
||||
&& matches!(n.kind, NodeKind::Compound { .. })
|
||||
&& !kids.is_empty()
|
||||
&& kids.iter().all(|k| matches!(k.kind, NodeKind::Path { .. }) && going.contains(&k.id))
|
||||
{
|
||||
going.insert(n.id);
|
||||
}
|
||||
// A clip outline takes in visible paths and the glyphs of visible type, as
|
||||
// `push_clip_shapes` does; type that lays out no glyphs (blank, or overset) gives no
|
||||
// outline. A list marker is a glyph too, so whitespace-only type is laid out as well.
|
||||
let shape = n.visible
|
||||
&& match &n.kind {
|
||||
NodeKind::Path { .. } => true,
|
||||
NodeKind::Text(t) => {
|
||||
in_mask.contains(&n.id) && !vectorcraft_text::layout(vectorcraft_text::FontDb::global(), t).to_bezpath().elements().is_empty()
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
// A clipping group's outline is its first member's alone.
|
||||
let inner =
|
||||
if n.clips() { kids.first().is_some_and(|k| geometry.contains(&k.id)) } else { kids.iter().any(|k| geometry.contains(&k.id)) };
|
||||
if n.visible && ((shape && !going.contains(&n.id)) || inner) {
|
||||
geometry.insert(n.id);
|
||||
}
|
||||
if n.clips()
|
||||
&& let Some(mask) = kids.first()
|
||||
&& affected.contains(&mask.id)
|
||||
&& !geometry.contains(&mask.id)
|
||||
&& kids.iter().skip(1).any(|k| !going.contains(&k.id) && !matches!(k.kind, NodeKind::RulerGuide { .. }))
|
||||
&& masks.len() < 20
|
||||
{
|
||||
masks.push(mask.id.0);
|
||||
}
|
||||
}
|
||||
let going: Vec<NodeId> = going.into_iter().collect();
|
||||
// Deleting the objects above an image in an ordinary group named as a tracing would make it one.
|
||||
let tracing = super::removal_makes_tracing(&st.doc, &going);
|
||||
let tracing = super::removal_makes_tracing(d, &going);
|
||||
Ok::<_, HostError>((ids, refused, on_locked, masks, tracing))
|
||||
})?;
|
||||
if !refused.is_empty() {
|
||||
|
||||
Reference in new issue
Block a user