Merge remote-tracking branch 'upstream/main' into refactor/shared-classic-hpgl

This commit is contained in:
Terra854
2026-11-25 02:29:47 +08:00
24 changed files with 445 additions and 35 deletions
+15 -2
View File
@@ -12,6 +12,9 @@ pub type AnchorRef = (usize, usize);
/// (subpath index, segment index) inside a path.
pub type SegmentRef = (usize, usize);
/// The most objects [`Selection::add_all`] adds by looking for each one in the selected objects.
const FEW_TO_ADD: usize = 8;
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Selection {
/// Selected objects in selection order.
@@ -197,14 +200,24 @@ impl Selection {
/// carry its current activation, so a removal drops every slot of the id at once.
fn each(&mut self, ids: impl IntoIterator<Item = NodeId>, toggle: bool) {
use std::collections::hash_map::{Entry, HashMap};
let mut ids = ids.into_iter().peekable();
if ids.peek().is_none() {
let ids: Vec<NodeId> = ids.into_iter().collect();
if ids.is_empty() {
return;
}
self.target = None;
self.slices.clear();
self.symbol_part = None;
self.on_path_member = None;
// Up to [`FEW_TO_ADD`] objects to add are each looked for in the selected objects; more go
// through a table of the selected objects.
if !toggle && ids.len() <= FEW_TO_ADD {
for id in ids {
if !self.objects.contains(&id) {
self.objects.push(id);
}
}
return;
}
let mut live: HashMap<NodeId, usize> = self.objects.iter().map(|id| (*id, 0)).collect();
let mut added: Vec<(NodeId, usize)> = Vec::new();
let mut removed = false;
+4
View File
@@ -859,6 +859,10 @@ pub use plugin_call::{Location, ParamsPlace, key_location, location_in, location
pub use select::SIMILAR;
pub(crate) use vectorcraft_doc::range::parse_range;
/// What the fill and stroke proxies read from the selected objects, kept with the selection
/// ([`crate::doc_state::SelectionRecord`]).
pub(crate) use paint::SelectionPaints;
/// A date param in Unix seconds that defaults to the clock: `None` when absent (now, see
/// [`clock_date`]), `Some(None)` for null (no date), else `Some(Some(seconds))`.
pub(crate) fn date_param(p: &Value, key: &str, cmd: &str) -> Result<Option<Option<i64>>> {
+30 -2
View File
@@ -13,6 +13,7 @@
//! resets new art when it opens such a document.
use std::borrow::Cow;
use std::sync::Arc;
use serde_json::{Value, json};
use vectorcraft_color::{BlendMode, Paint};
@@ -32,7 +33,9 @@ pub(crate) struct NewArtSource {
}
use super::gradient::unplaced;
use super::paint::SelectionPaints;
use super::{CommandSpec, Result, Session, always, cmd, switch_or};
use crate::doc_state::{SelectionRecord, objects_only};
pub fn specs() -> Vec<CommandSpec> {
vec![
@@ -267,9 +270,10 @@ impl Session {
if !has_paint {
return;
}
let (fill_mixed, stroke_mixed) = self.proxy_mixed();
let read = self.read_selection_paints();
let (fill_mixed, stroke_mixed) = read.as_ref().map_or_else(|| self.proxy_mixed(), |p| (p.fill_mixed, p.stroke_mixed));
let (fill, stroke) = self.proxy_paints();
let weight_mixed = self.active().is_some_and(|st| st.stroke_mixed().weight);
let weight_mixed = read.as_ref().map_or_else(|| self.active().is_some_and(|st| st.stroke_mixed().weight), |p| p.weight_mixed);
let weight = self.shown_stroke().filter(|st| st.paint != Paint::None && !weight_mixed).map(|st| st.width);
if !fill_mixed {
self.paint.fill = unplaced(&fill);
@@ -281,6 +285,30 @@ impl Session {
self.paint.stroke_width = width;
}
}
/// The [`SelectionPaints`] of the active document's selection, read now and kept in its
/// [`SelectionRecord`] when the record holds none. `None` when anything besides whole objects
/// is selected ([`objects_only`]), with an active Appearance item, when a selected object is in
/// a Live Paint group, and with gradient mesh points picked: the proxies then read the
/// selection with [`Session::proxy_mixed`] and [`crate::DocState::stroke_mixed`]. While the
/// Live Paint Bucket paints, [`Session::load_selection_paints`] returns before reading them.
fn read_selection_paints(&mut self) -> Option<SelectionPaints> {
if self.appearance_item().is_some() {
return None;
}
let st = self.active_mut()?;
if !objects_only(&st.selection) {
return None;
}
if st.selection_paints().is_none() {
let paints = SelectionPaints::of(&st.doc, &st.selection.objects);
let settled = st.selection_record().and_then(|r| r.settled);
st.selection_record =
Some(SelectionRecord { doc: Arc::downgrade(&st.doc), objects: st.selection.objects.clone(), settled, paints: Some(paints) });
}
let paints = st.selection_paints()?.clone();
(!paints.in_live_paint && self.fill_mesh_points().is_empty()).then_some(paints)
}
}
fn set_basic(s: &mut Session, p: &Value) -> Result<Value> {
+89 -5
View File
@@ -224,7 +224,7 @@ impl Session {
// A Live Paint group without faces (or edges) shows the next selected object's paint; any other
// object without a painted object shows the defaults for new art. A face or edge selected with
// its Live Paint group counts with the group, wherever it is in the selection.
let covered = live_paint_covered(&st.doc, st.selection.subjects());
let covered = st.selection_live_paint_covered(st.selection.subjects());
for id in st.selection.subjects().iter().filter(|id| !covered.contains(*id)) {
let Some(n) = st.doc.node(*id) else { continue };
let mut nodes = vec![];
@@ -303,6 +303,74 @@ pub(crate) fn painted<'a>(n: &'a Node, top: bool, stroke: bool, out: &mut Vec<&'
}
}
/// What the proxies read from selected objects: the first fill, stroke and stroke weight met, and
/// whether another one differs ([`DocState::proxy_mixed`] without an active Appearance item or
/// picked mesh points, and [`super::stroke::StrokeMixed::weight`]), and whether an object lies in a
/// Live Paint group or may hold a gradient mesh. The objects added to a selection are read with
/// [`SelectionPaints::add`].
#[derive(Clone, Debug, Default)]
pub(crate) struct SelectionPaints {
fill: Option<Paint>,
pub(crate) fill_mixed: bool,
stroke: Option<Paint>,
pub(crate) stroke_mixed: bool,
weight: Option<f64>,
pub(crate) weight_mixed: bool,
/// An object is a face or edge of a Live Paint group, or lies inside one
/// ([`live_paint_covered`]).
pub(crate) in_live_paint: bool,
/// An object is a gradient mesh or a container ([`Session::fill_mesh_points`]).
pub(crate) may_hold_mesh: bool,
}
impl SelectionPaints {
/// Read objects `ids` of `doc`.
pub(crate) fn of(doc: &Document, ids: &[NodeId]) -> Self {
let mut p = Self::default();
p.add(doc, ids);
p
}
/// Read objects `ids` of `doc` too.
pub(crate) fn add(&mut self, doc: &Document, ids: &[NodeId]) {
fn meet<T>(first: &mut Option<T>, mixed: &mut bool, value: T, same: impl Fn(&T, &T) -> bool) {
match first {
Some(f) => *mixed |= !same(f, &value),
None => *first = Some(value),
}
}
// As in `proxy_mixed_with`: every node with an added id, in tree order.
let (mut fills, mut strokes) = (vec![], vec![]);
for n in doc.nodes_in_order(ids.iter().copied()) {
painted(n, true, false, &mut fills);
painted(n, true, true, &mut strokes);
}
for n in fills {
meet(&mut self.fill, &mut self.fill_mixed, proxy_paint(n, false, None), same_in_proxy);
}
for n in strokes {
meet(&mut self.stroke, &mut self.stroke_mixed, proxy_paint(n, true, None), same_in_proxy);
}
// As in `stroke_mixed`: the node each added id names.
for id in ids {
let Some(n) = doc.node(*id) else { continue };
self.in_live_paint |= in_live_paint(doc, *id);
self.may_hold_mesh |= matches!(n.kind, NodeKind::Mesh(_)) || n.is_container();
let mut nodes = vec![];
painted(n, true, true, &mut nodes);
for n in nodes {
let widths: Vec<f64> = match &n.kind {
NodeKind::Text(t) => t.runs.iter().map(|r| r.style.stroke_layer().width).collect(),
_ => n.appearance.stroke().map(|s| s.width).into_iter().collect(),
};
for w in widths {
meet(&mut self.weight, &mut self.weight_mixed, w, |a, b| a == b);
}
}
}
}
}
impl DocState {
/// Whether the selected objects' fills and strokes differ as the proxies show them (a "?"
/// proxy; a group whose contents differ counts). `item` (the Appearance panel's active item)
@@ -329,7 +397,7 @@ impl DocState {
let (mut selected, mut fills, mut strokes) = (vec![], vec![], vec![]);
// The faces and edges of the selected Live Paint groups (or of those inside selected groups): selected as well,
// they count with their group's.
let covered = live_paint_covered(&self.doc, &self.selection.objects);
let covered = self.selection_live_paint_covered(&self.selection.objects);
// Every node with a selected id, in tree order: a repeated id (a damaged file) counts at each
// place it appears.
for n in self.doc.nodes_in_order(self.selection.objects.iter().copied()) {
@@ -927,8 +995,7 @@ pub(crate) fn live_paint_split(d: &Document, roots: &[NodeId]) -> LivePaintParts
/// object: they count with their group, wherever they are in `selected`. The groups are looked for only when an
/// object in `selected` is inside a Live Paint group.
pub(crate) fn live_paint_covered(d: &Document, selected: &[NodeId]) -> std::collections::HashSet<NodeId> {
let inside = |id: &NodeId| d.ancestry(*id).is_some_and(|up| up.iter().rev().skip(1).filter_map(|a| d.node(*a)).any(is_live_paint));
if !selected.iter().any(inside) {
if !selected.iter().any(|id| in_live_paint(d, *id)) {
return std::collections::HashSet::new();
}
let (mut parts, edges, _) = live_paint_split(d, selected);
@@ -936,6 +1003,22 @@ pub(crate) fn live_paint_covered(d: &Document, selected: &[NodeId]) -> std::coll
parts
}
/// Is `id` inside a Live Paint group (one of the groups around it is one)?
fn in_live_paint(d: &Document, id: NodeId) -> bool {
d.ancestry(id).is_some_and(|up| up.iter().rev().skip(1).filter_map(|a| d.node(*a)).any(is_live_paint))
}
impl DocState {
/// [`live_paint_covered`] for `ids`, the selected objects or the selection's subjects: none
/// when the [`SelectionPaints`] of the selection say no selected object is in a Live Paint group.
pub(crate) fn selection_live_paint_covered(&self, ids: &[NodeId]) -> std::collections::HashSet<NodeId> {
if self.selection_paints().is_some_and(|p| !p.in_live_paint) {
return std::collections::HashSet::new();
}
live_paint_covered(&self.doc, ids)
}
}
/// The instance whose object is selected with Direct Selection, and that object's path
/// ([`super::brushsym::selected_part`]), when `p` names no `ids`, `id` or `item`: the paint commands
/// then change that object. A bad `target` or `aligned` is refused as it is for any other selection.
@@ -1181,7 +1264,8 @@ impl Session {
// Only gradient meshes have points to pick: a selection with no mesh and no container that
// could hold one skips reading the tool's options.
let may_hold_mesh = |id: &NodeId| st.doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Mesh(_)) || n.is_container());
if st.selection.symbol_part.is_some() || !st.selection.subjects().iter().any(may_hold_mesh) {
let none_may = || st.selection_paints().map_or_else(|| !st.selection.subjects().iter().any(may_hold_mesh), |p| !p.may_hold_mesh);
if st.selection.symbol_part.is_some() || none_may() {
return vec![];
}
let Ok(item) = item_target(self, &Value::Null, "paint.setFill").map(|t| t.of_kind(self, true)) else { return vec![] };
+3 -3
View File
@@ -11,7 +11,7 @@ use vectorcraft_geom::PathData;
use vectorcraft_tools::builder::is_live_paint;
use super::appearance::{ItemTarget, edit_items, item_target};
use super::paint::{live_paint_covered, live_paint_parts_skipped, painted};
use super::paint::{live_paint_parts_skipped, painted};
use super::{CommandSpec, Result, Session, always, bad, bool_or, cmd, has_doc, ok, str_param};
use crate::DocState;
use crate::inspect::{ALIGNS, CAPS, JOINS, StrokeMixed, node_stroke, scale_layer};
@@ -465,7 +465,7 @@ impl Session {
// A Live Paint group without edges shows the next selected object's stroke; any other object
// without a painted object shows none. A face or edge selected with its Live Paint group counts
// with the group, wherever it is in the selection.
let covered = live_paint_covered(&st.doc, &st.selection.objects);
let covered = st.selection_live_paint_covered(&st.selection.objects);
for id in st.selection.objects.iter().filter(|id| !covered.contains(*id)) {
let Some(n) = st.doc.node(*id) else { continue };
let mut nodes = vec![];
@@ -540,7 +540,7 @@ impl DocState {
} else {
let selected: Vec<&Node> = self.selection.objects.iter().filter_map(|id| self.doc.node(*id)).collect();
// The faces and edges of the selected Live Paint groups: selected as well, they count with their group's.
let covered = live_paint_covered(&self.doc, &self.selection.objects);
let covered = self.selection_live_paint_covered(&self.selection.objects);
for n in selected.into_iter().filter(|n| !covered.contains(&n.id)) {
painted(n, true, true, &mut nodes);
}
+71
View File
@@ -150,6 +150,39 @@ pub struct DocState {
/// measured: the next refresh checks only the layer trees that differ from it
/// ([`cmd::inline::refresh`]). Not saved.
pub(crate) inline_resolved: Option<cmd::inline::Resolved>,
/// The selected objects as [`crate::Session::select`] last checked them or the proxies last
/// read them, with the document they were checked in ([`SelectionRecord`]). Not saved.
pub(crate) selection_record: Option<SelectionRecord>,
}
/// A selection of objects alone ([`objects_only`]) with the document it was checked or read in:
/// while the document and the selected objects stay the same, a command that adds objects checks
/// and reads only the added ones.
#[derive(Clone, Debug)]
pub(crate) struct SelectionRecord {
/// The document, held as [`EmptyArtboards::doc`] holds it.
pub(crate) doc: std::sync::Weak<Document>,
pub(crate) objects: Vec<NodeId>,
/// Lock Guides as it was when [`crate::Session::select`] left these objects selected; `None`
/// when it did not.
pub(crate) settled: Option<bool>,
/// What the proxies read from these objects; `None` when they were not read.
pub(crate) paints: Option<cmd::SelectionPaints>,
}
/// Whether `sel` holds selected objects and nothing else: no anchors, segments, key, target,
/// slices, ruler guides, object of a symbol instance's art or object on a path.
pub(crate) fn objects_only(sel: &Selection) -> bool {
sel.anchors.is_empty()
&& sel.segments.is_empty()
&& sel.key.is_none()
&& sel.target.is_none()
&& sel.slices.is_empty()
&& sel.guides.is_empty()
&& sel.key_guide.is_none()
&& sel.key_anchor.is_none()
&& sel.symbol_part.is_none()
&& sel.on_path_member.is_none()
}
/// What the commands scripts ran did to an open document since the person last opened or saved it
@@ -407,8 +440,46 @@ impl DocState {
art_to_fit: Default::default(),
measured_in_own: None,
inline_resolved: None,
selection_record: None,
}
}
/// The [`SelectionRecord`] of the selection now: `None` when the document or the selected
/// objects changed since it was made, or when anything besides whole objects is selected
/// ([`objects_only`]). Only a new [`Document`] makes the record stale: the document's new art
/// is the one state that changes in place and matters to it, and [`crate::Session::select`]
/// checks the whole selection while there is new art.
pub(crate) fn selection_record(&self) -> Option<&SelectionRecord> {
self.selection_record
.as_ref()
.filter(|r| std::ptr::eq(r.doc.as_ptr(), Arc::as_ptr(&self.doc)) && objects_only(&self.selection) && r.objects == self.selection.objects)
}
/// What the proxies read from the selected objects, when the [`SelectionRecord`] of the
/// selection now holds it.
pub(crate) fn selection_paints(&self) -> Option<&cmd::SelectionPaints> {
self.selection_record().and_then(|r| r.paints.as_ref())
}
/// Keep the [`SelectionRecord`] of the selection that [`crate::Session::select`] left, with
/// Lock Guides `guides_locked`. `record` is the record of the selection before: when the
/// selected objects start with its objects, the added objects are read into its paints.
pub(crate) fn record_selection(&mut self, record: Option<SelectionRecord>, guides_locked: bool) {
if !objects_only(&self.selection) {
self.selection_record = None;
return;
}
let objects = &self.selection.objects;
self.selection_record = Some(match record {
Some(mut r) if objects.starts_with(&r.objects) => {
let added = &objects[r.objects.len()..];
if let Some(p) = &mut r.paints {
p.add(&self.doc, added);
}
r.objects.extend_from_slice(added);
r.settled = Some(guides_locked);
r
}
_ => SelectionRecord { doc: Arc::downgrade(&self.doc), objects: objects.clone(), settled: Some(guides_locked), paints: None },
});
}
/// The document, its file and the file it was read from as the person last left them, for the
/// commands scripts run ([`DocState::by_script`]): `None` for a document a script's command
+28 -9
View File
@@ -1,7 +1,8 @@
use super::{
Arc, Document, EngineError, Interaction, LastTransform, NamedStep, Result, Selection, Session, TOO_DEEP, Value, cmd, deselect_hidden, doc_sane,
objects_in_range,
Arc, Document, EngineError, Interaction, LastTransform, NamedStep, NodeKind, Result, Selection, Session, TOO_DEEP, Value, cmd, deselect_hidden,
doc_sane, objects_in_range,
};
use crate::doc_state::objects_only;
impl Session {
/// Run `f` on a mutable copy of the active document. Outside an interaction this records one
@@ -210,14 +211,32 @@ impl Session {
let st = self.doc_mut()?;
let before = st.selection.objects.clone();
let new_art = st.selection.new_art.clone();
let record = if st.selection_record().is_some() { st.selection_record.take() } else { None };
f(&st.doc, &mut st.selection);
st.selection.prune(&st.doc);
// Lock Guides locks the paths made into guides too (#1534), and Lock Slices and Hide
// Slices keep the slices out, whatever selects them.
deselect_hidden(&menu, &st.doc, &mut st.selection);
// The art on a locked artboard can't be selected, whatever selects it, except new art
// that was selected and still is.
st.protect_locked_artboards(&before, &new_art, None);
let added = objects_only(&st.selection) && st.selection.objects.starts_with(&before);
// Objects added to objects this checked in the same document, with Lock Guides as it was
// then and no art on a locked artboard to protect, are checked alone, by the rules `prune`
// and `deselect_hidden` apply to an object.
let settled = record.as_ref().is_some_and(|r| r.settled == Some(menu.guides_locked))
&& st.selection.new_art.is_empty()
&& st.doc.new_art.get().is_empty()
&& !st.doc.artboards.iter().any(|a| a.locked);
if added && settled {
let doc = &st.doc;
let tail = st.selection.objects.split_off(before.len());
st.selection.objects.extend(tail.into_iter().filter(|id| {
doc.node(*id).is_some_and(|n| !n.is_ruler_guide() && !(menu.guides_locked && matches!(n.kind, NodeKind::Path { guide: true, .. })))
}));
} else {
st.selection.prune(&st.doc);
// Lock Guides locks the paths made into guides too (#1534), and Lock Slices and Hide
// Slices keep the slices out, whatever selects them.
deselect_hidden(&menu, &st.doc, &mut st.selection);
// The art on a locked artboard can't be selected, whatever selects it, except new art
// that was selected and still is.
st.protect_locked_artboards(&before, &new_art, None);
}
st.record_selection(record, menu.guides_locked);
// Selecting art makes its layer (or sublayer) the current one, as in the Layers panel of
// the reference app: new art then goes beside it.
if st.selection.objects != before
+26 -1
View File
@@ -1,6 +1,7 @@
//! Commands that remove, insert or copy many objects, and an Alt-drag that copies them, each walk
//! the document's tree a few times on one layer of 25,000 to 100,000 objects, and objects in two
//! layers and inside a group keep their order and ids.
//! layers and inside a group keep their order and ids. Selecting objects one at a time looks up
//! only the added ones.
use std::sync::Arc;
use std::time::Duration;
@@ -696,3 +697,27 @@ fn copies_of_ids_listed_twice_or_inside_another_listed_id_keep_their_order_and_i
assert_eq!(layers(&s), [json!([a, n + 1, n, b, c, [group, d, e, f]]), json!([g, h])]);
undo_gives_back(&mut s, &before);
}
/// `select.add` run once for each of `n` objects, from nothing selected → the walks of the tree and
/// the lookups by id it took.
fn add_one_at_a_time(n: usize) -> (u64, u64) {
let mut s = session(n, square);
s.execute("select.none", &json!({})).unwrap();
let ids = layer(&s, 0);
let (walks, lookups) = (vectorcraft_doc::tree_walks(), vectorcraft_doc::path_lookups());
for id in &ids {
s.execute("select.add", &json!({"ids": [id.0]})).unwrap();
}
assert!(selected(&s, &ids));
(vectorcraft_doc::tree_walks() - walks, vectorcraft_doc::path_lookups() - lookups)
}
/// Selecting objects one at a time checks and reads only the object each `select.add` adds: twice
/// as many objects take about twice as many lookups, and the tree is not walked for each one.
#[test]
fn selecting_objects_one_at_a_time_looks_up_only_the_added_objects() {
let (walks, lookups) = add_one_at_a_time(1_000);
let (more_walks, more_lookups) = add_one_at_a_time(2_000);
assert!(walks.max(more_walks) <= MOST_TREE_WALKS, "walked the tree {walks} and {more_walks} times");
assert!(more_lookups <= lookups * 5 / 2, "{lookups} lookups for 1,000 objects, {more_lookups} for 2,000");
}
+32
View File
@@ -4621,6 +4621,38 @@ fn locked_guides_lock_guide_paths() {
assert_eq!(selected(&s), vec![b]);
}
/// A guide path added to the selection after another object stays unselected while Lock Guides is
/// on, and is selected once it is off.
#[test]
fn a_guide_path_added_after_another_object_stays_unselected_while_guides_are_locked() {
let mut s = session();
let b = rect(&mut s, 20.0, 20.0, 10.0, 10.0);
let g = guide_path(&mut s, 0.0);
s.execute("view.guides.lock", &json!({"locked": true})).unwrap();
for id in [b, g] {
s.execute("select.add", &json!({"ids": [id.0]})).unwrap();
}
assert_eq!(selected(&s), vec![b]);
s.execute("view.guides.lock", &json!({"locked": false})).unwrap();
s.execute("select.add", &json!({"ids": [g.0]})).unwrap();
assert_eq!(selected(&s), vec![b, g]);
}
/// An id that names no object and a ruler guide's id, added to a selection after another object,
/// leave the selection as a whole new selection of the same ids would.
#[test]
fn a_missing_object_and_a_ruler_guide_added_after_another_object_stay_unselected() {
let mut s = session();
let (b, c) = (rect(&mut s, 20.0, 20.0, 10.0, 10.0), rect(&mut s, 40.0, 20.0, 10.0, 10.0));
s.execute("guide.add", &json!({"vertical": true, "pos": 100})).unwrap();
let guide = s.doc().unwrap().doc.ruler_guides()[0].id.unwrap();
s.execute("select.none", &json!({})).unwrap();
s.execute("select.add", &json!({"ids": [b.0]})).unwrap();
let missing = NodeId(u64::MAX);
s.select(|_, sel| sel.objects.extend([missing, guide, c])).unwrap();
assert_eq!(selected(&s), vec![b, c]);
}
/// A rectangle at (`x`, 0), 10 pt wide, made into a guide; nothing is selected after.
fn guide_path(s: &mut Session, x: f64) -> NodeId {
let g = rect(s, x, 0.0, 10.0, 10.0);
+41
View File
@@ -192,6 +192,47 @@ fn a_paint_the_selected_objects_do_not_share_stays_as_it_was() {
assert_eq!((s.paint.stroke.clone(), s.paint.stroke_width), (node(&s, a).appearance.stroke_paint(), 5.0), "the strokes are shared");
}
fn add(s: &mut Session, id: NodeId) {
run(s, "select.add", json!({"ids": [id.0]}));
}
/// Objects added one at a time are compared with the objects already selected: a fill and weight
/// they all share loads, one they don't stays as it was.
#[test]
fn objects_added_one_at_a_time_load_only_the_paints_all_selected_objects_share() {
let mut s = session();
let a = painted(&mut s, 20.0, "#ff0000", "#00ff00", 5.0);
let b = painted(&mut s, 120.0, "#ff0000", "#00ff00", 5.0);
let c = painted(&mut s, 220.0, "#0000ff", "#00ff00", 1.0);
let red = node(&s, a).appearance.fill_paint();
run(&mut s, "select.none", json!({}));
add(&mut s, a);
(s.paint.fill, s.paint.stroke_width) = (Paint::None, 0.5);
add(&mut s, b);
assert_eq!((s.paint.fill.clone(), s.paint.stroke_width), (red, 5.0), "a and b share them");
(s.paint.fill, s.paint.stroke_width) = (Paint::None, 0.5);
add(&mut s, c);
assert_eq!((s.paint.fill.clone(), s.paint.stroke_width), (Paint::None, 0.5), "c's differ");
}
/// An edit of the selected objects between two additions is read: the objects selected before it
/// are compared as the edit left them.
#[test]
fn an_object_added_after_an_edit_is_compared_with_the_edited_objects() {
let mut s = session();
let a = painted(&mut s, 20.0, "#ff0000", "#00ff00", 5.0);
let b = painted(&mut s, 120.0, "#ff0000", "#00ff00", 5.0);
let c = painted(&mut s, 220.0, "#0000ff", "#00ff00", 5.0);
let blue = node(&s, c).appearance.fill_paint();
run(&mut s, "select.none", json!({}));
add(&mut s, a);
add(&mut s, b);
run(&mut s, "paint.setFill", json!({"color": "#0000ff", "ids": [a.0, b.0]}));
s.paint.fill = Paint::None;
add(&mut s, c);
assert_eq!(s.paint.fill, blue, "a, b and c are all blue now");
}
#[test]
fn art_without_paint_leaves_the_proxies_as_they_were() {
let mut s = session();
+15
View File
@@ -967,6 +967,21 @@ fn a_locked_artboard_protects_the_art_on_it() {
assert!(!tile.is_empty() && !tile.contains(&a), "{tile:?}");
}
/// Art on a locked artboard stays unselected when `select.add` adds it after another object.
#[test]
fn art_on_a_locked_artboard_added_after_another_object_stays_unselected() {
let mut s = session();
let a = rect(&mut s);
s.execute("artboard.new", &json!({"x": 1000, "y": 0, "width": 200, "height": 200})).unwrap();
let b = NodeId(s.execute("shape.rectangle", &json!({"x": 1010, "y": 10, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap());
s.execute("artboard.setProps", &json!({"index": 1, "locked": true})).unwrap();
s.execute("select.none", &json!({})).unwrap();
for id in [a, b] {
s.execute("select.add", &json!({"ids": [id.0]})).unwrap();
}
assert_eq!(s.doc().unwrap().selection.objects, [a]);
}
/// New art on a locked artboard stays selected and editable until the selection leaves it: a
/// second Pen click goes on the path the first one started, and pasted art moves. Once another
/// object is clicked, a click, a marquee, `select.set` and Select All pass over that art. Undo, in
+16
View File
@@ -125,6 +125,22 @@ fn file_names_are_uri_encoded_and_current_relative() {
let _ = std::fs::remove_dir_all(base);
}
/// `localizedName` of a file and a folder is the name they show, decoded, as `displayName` is,
/// not the encoded `name`.
#[test]
fn file_and_folder_give_their_localized_name() {
let base = folder("localized");
let log = logged(
&base,
"var f = new File('caf%C3%A9 x.txt'), d = new Folder('n%C3%A9w');\n\
f.localizedName = 'other';\n\
vc.log([f.localizedName === f.displayName, f.localizedName === f.name, d.localizedName === d.displayName,\n\
d.localizedName === d.name, f.localizedName, 'localizedName' in Folder.prototype]);",
);
assert_eq!(log, json!([[true, false, true, false, "caf\u{e9} x.txt", true]]));
let _ = std::fs::remove_dir_all(base);
}
#[test]
fn script_file_without_scope_cannot_probe_home() {
let base = folder("home");
@@ -59,7 +59,7 @@ const INSIDE: &[(&str, &str)] = &[
(
"File.prototype.",
"absoluteURI alias changePath close constructor created creator displayName encoding encoding= eof error error= \
exists fsName fullName getRelativeURI hidden length lineFeed lineFeed= modified name openDlg parent path read \
exists fsName fullName getRelativeURI hidden length lineFeed lineFeed= localizedName modified name openDlg parent path read \
readch readln readonly relativeURI resolve saveDlg seek tell toString type",
),
(
@@ -70,7 +70,7 @@ const INSIDE: &[(&str, &str)] = &[
(
"Folder.prototype.",
"absoluteURI alias changePath constructor created displayName error error= exists fsName fullName getFiles \
getRelativeURI modified name parent path relativeURI resolve selectDlg toString",
getRelativeURI localizedName modified name parent path relativeURI resolve selectDlg toString",
),
];
+7
View File
@@ -314,6 +314,12 @@ fn display_name(i: &mut Interp, this: Value, _: &[Value], _: bool) -> JsResult<V
parsed(i, &this, "displayName", "display")
}
/// `localizedName`: the same decoded name as `displayName`; VectorCraft does not look up a name the
/// system shows in another language.
fn localized_name(i: &mut Interp, this: Value, _: &[Value], _: bool) -> JsResult<Value> {
parsed(i, &this, "localizedName", "display")
}
fn path(i: &mut Interp, this: Value, _: &[Value], _: bool) -> JsResult<Value> {
parsed(i, &this, "path", "path")
}
@@ -1029,6 +1035,7 @@ fn common(i: &mut Interp, ctor: ObjId, proto: ObjId) -> JsResult<()> {
accessor(i, proto, "relativeURI", relative_uri, None)?;
accessor(i, proto, "name", name, None)?;
accessor(i, proto, "displayName", display_name, None)?;
accessor(i, proto, "localizedName", localized_name, None)?;
accessor(i, proto, "path", path, None)?;
accessor(i, proto, "parent", parent, None)?;
accessor(i, proto, "exists", exists, None)?;
+8
View File
@@ -95,6 +95,14 @@ fn variables_functions_and_closures() {
assert_eq!(num("(function(a, b, c) {}).length"), 3.0);
}
#[test]
fn a_trailing_comma_adds_no_argument_or_parameter() {
assert_eq!(num("function f(a, b,) { return arguments.length * 10 + f.length; } f(1,)"), 12.0);
assert_eq!(num("function P(x,) { this.n = arguments.length; } new P(5,).n"), 1.0);
assert_eq!(num("var f = new Function('a,', 'return arguments.length'); f(1, 2) * 10 + f.length"), 21.0);
assert_eq!(num("Function('a', '', 'return a')(4)"), 4.0);
}
#[test]
fn call_and_apply_set_this_and_arguments() {
assert_eq!(num("function f(a, b) { return this.k + a + b; } f.call({k: 1}, 2, 3)"), 6.0);
+10 -1
View File
@@ -1008,9 +1008,17 @@ impl<'s> Parser<'s> {
let default = if self.es2015 && self.eat(Punct::Eq)? { Some(self.parse_assignment(false)?) } else { None };
params.push(param);
defaults.push(default);
// A comma may follow the last parameter (ECMAScript 2017, section 14.1), except in
// a setter, which takes one parameter and no comma (section 14.3).
if !self.eat(Punct::Comma)? {
break;
}
if self.at(Punct::RParen) {
if kind == FunctionKind::Setter {
return Err(self.error_at_token(&self.tok, "a setter must have exactly one parameter"));
}
break;
}
}
}
let close = self.expect(Punct::RParen)?;
@@ -1473,7 +1481,8 @@ impl<'s> Parser<'s> {
if !self.at(Punct::RParen) {
loop {
args.push(self.parse_element()?);
if !self.eat(Punct::Comma)? {
// A comma may follow the last argument (ECMAScript 2017, section 12.3).
if !self.eat(Punct::Comma)? || self.at(Punct::RParen) {
break;
}
}
+18
View File
@@ -134,6 +134,24 @@ fn accessors_take_the_right_number_of_parameters() {
assert!(err("({set a(x, y) {}});").message.contains("setter"));
}
#[test]
fn a_comma_may_end_arguments_and_parameters() {
let p = ok("f(1,);");
assert!(matches!(expr(&p, first_expr(&p)), Expr::Call { args, .. } if args.len() == 1));
let p = ok("new F(1, 2,);");
assert!(matches!(expr(&p, first_expr(&p)), Expr::New { args, .. } if args.len() == 2));
let p = ok("function g(a, b,) {}");
let Stmt::FunctionDecl(g) = stmt(&p, p.body[0]) else { panic!() };
assert_eq!(p.ast.function(*g).unwrap().params.len(), 2);
for src in ["(function (a,) {});", "({get a() {}, m: function (x,) {}});", "f(g(1,),);", "'use strict'; function h(a,) {}"] {
ok(src);
}
for src in ["f(,);", "f(1,,);", "f(, 1);", "function g(,) {}", "function g(a,,) {}", "new F(,);"] {
err(src);
}
assert!(err("({set a(v,) {}});").message.contains("setter"));
}
#[test]
fn property_names_may_repeat() {
for src in ["({a: 1, a: 2});", "({a: 1, 'a': 2});", "({get a() {}, set a(v) {}});", "({a: 1, get a() {}});", "({get a() {}, get a() {}});"] {
+3 -1
View File
@@ -249,9 +249,11 @@ enum Pending<'s> {
/// `Window`: `(` and a string literal with the window's type may follow.
Window(Option<usize>),
WindowType(Option<usize>),
/// `.executeMenuCommand(`: a string literal and `)` may follow.
/// `.executeMenuCommand(`: a string literal and `)` may follow, with a trailing comma
/// between them.
Menu(Option<usize>),
MenuString(Option<usize>, &'s str),
MenuStringComma(Option<usize>, &'s str),
/// `.open(`: a string literal with the open mode may follow.
Open(Option<usize>),
/// A File object's `length`, `hidden` or `readonly` (`f.length`, `f['length']`): an assignment
+3 -2
View File
@@ -66,7 +66,8 @@ impl<'s, 'a, 'l> Analyzer<'s, 'a, 'l> {
self.menu(None, l);
}
}
Pending::MenuString(l, s) => self.menu(t.is(")").then_some(s), l),
Pending::MenuString(l, s) if t.is(",") => self.pending = Pending::MenuStringComma(l, s),
Pending::MenuString(l, s) | Pending::MenuStringComma(l, s) => self.menu(t.is(")").then_some(s), l),
Pending::Open(l) => {
if t.kind == T::Str {
self.open_mode(&unquote(t.text, 2), l);
@@ -123,7 +124,7 @@ impl<'s, 'a, 'l> Analyzer<'s, 'a, 'l> {
}
match pending {
Pending::Window(l) | Pending::WindowType(l) => self.acc.feature(FeatureId::ScriptuiWindow, l),
Pending::Menu(l) | Pending::MenuString(l, _) => self.menu(None, l),
Pending::Menu(l) | Pending::MenuString(l, _) | Pending::MenuStringComma(l, _) => self.menu(None, l),
Pending::Setter(l, true) => self.file_setter(l),
Pending::Open(_) | Pending::Setter(_, false) | Pending::Name(..) | Pending::None => {}
}
+12
View File
@@ -1556,6 +1556,18 @@ fn menu_commands_are_counted_with_their_lines() {
assert_eq!(feature(&r, "menuCommand").map(|f| f.count), Some(6));
}
#[test]
fn a_menu_command_string_with_a_trailing_comma_is_listed() {
let r = report(concat!(
"app.executeMenuCommand('acmecopyall',);\n",
"app.executeMenuCommand('acmecopyall', n);\n",
"app.executeMenuCommand('acmecopyall',\n",
));
let strings: Vec<(&str, usize, &[usize])> = r.menu_strings.iter().map(|s| (s.value.as_str(), s.count, s.lines.as_slice())).collect();
assert_eq!(strings, [("acmecopyall", 1, &[1][..])]);
assert_eq!(r.menu_dynamic, 2);
}
#[test]
fn effects_outside_the_document_are_listed_in_order() {
let r = report(concat!(
+3 -1
View File
@@ -320,7 +320,9 @@ fn dimmed_rows_follow_the_settings_they_depend_on() {
if let Some((enabled, help)) = row_state(&mut a, "appTitleBar") {
let label = format!("variable {from_env}, system {system}");
assert_eq!(enabled, !from_env && !system, "app title bar: {label}");
assert_eq!(help.is_some_and(|h| h.contains("VECTORCRAFT_TITLEBAR")), from_env, "app title bar note: {label}");
// The note, not the setting's sentence, which names the variable too.
let note = help.is_some_and(|h| h.contains("VECTORCRAFT_TITLEBAR environment variable"));
assert_eq!(note, from_env, "app title bar note: {label}");
}
if let Some((enabled, _)) = row_state(&mut a, "systemTitleBar") {
assert_eq!(enabled, !from_env, "system title bar: variable {from_env}");
+2
View File
@@ -10,6 +10,8 @@ fn the_cut_tools_have_their_own_icons_and_toolbar_slot() {
for (tool, icon) in [("mirrorCut", "dc-mirror-cut"), ("lineCut", "dc-line-cut"), ("rectCut", "dc-rect-cut")] {
let info = vectorcraft_tools::tool_info(tool).unwrap();
assert_eq!(icons::tool_icon(info.icon), icon);
// The app registers its icons at start; a test run alone in its process must too.
craft::ui::primitives::register_app_icons(&icons::APP_ICONS);
assert!(craft::ui::primitives::has_icon(&IconId::new(icon)), "{icon}");
assert!(crate::toolbar::BASIC.iter().flat_map(|(_, slots)| slots.iter()).any(|s| s.contains(&tool) && s.contains(&"knife")));
}
+5 -4
View File
@@ -2948,10 +2948,11 @@ script reads files with them:
`%xx` escapes are read as UTF-8, and on Windows `/` and `\` both separate names and `/c/` names drive C. `File(path)`
without `new` gives a `Folder` for an existing folder, and `Folder(path)` gives a `File` for an existing file. Two
objects for the same path are different objects.
- `name`, `displayName`, `fsName`, `absoluteURI`, `fullName`, `relativeURI`, `path`, `parent` and `toString()` come
from the path. `exists`, `length`, `created`, `modified`, `hidden`, `readonly` and `alias` read the file system.
`exists` is true for a `File` only when the path names something other than a folder, and for a `Folder` only
when it names a folder.
- `name`, `displayName`, `localizedName`, `fsName`, `absoluteURI`, `fullName`, `relativeURI`, `path`, `parent` and
`toString()` come from the path. `localizedName` gives the same decoded name as `displayName`: VectorCraft does not
look up a name the system shows in another language. `exists`, `length`, `created`, `modified`, `hidden`,
`readonly` and `alias` read the file system. `exists` is true for a `File` only when the path names something
other than a folder, and for a `Folder` only when it names a folder.
`File.encode`, `File.decode` and `File.isEncodingAvailable` (and the same on `Folder`), `File.fs`, and the folders
`Folder.temp`, `Folder.desktop`, `Folder.myDocuments`, `Folder.userData` and the others are there too.
- `open('r')` opens a file to read, and `read([chars])`, `readln()`, `readch()`, `seek(pos[, mode])`, `tell()`, `eof`
+2 -2
View File
@@ -1046,7 +1046,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Scripts: `$.fileName` is a read-only name of the script file in use ([the help page](https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/)). VectorCraft's own rules: it names the file of the code that reads it, so a function a file included with `#include` or run with `$.evalFile` defined, or one an earlier run of a named engine kept, gives its own file and not the calling file; code from a script given as `source`, and kept code whose place the engine dropped, gives an empty name, and code that `eval` or `Function` compiled gives the file being run. `crates/engine/src/tests/script_include.rs`, `crates/engine/src/tests/script_engines.rs`.
- Scripts: a runtime error is shown at the line that was running ([the help page](https://extendscript.docsforadobe.dev/extendscript-toolkit/debugging-in-the-toolkit/)). VectorCraft's own rules: an error in code an earlier run of a named engine compiled, such as a function it defined, is reported at that code's file, line and column (the earlier run's script, a file it included or a file its `$.evalFile` ran), while the report and its console line keep the calling run's name; a script given as text is named by its run's name, and each engine keeps these places for 8 MiB of source maps, the oldest going first. An error in code whose place is gone, or in code that `eval` or `Function` compiled, is reported without a line and column, and the code still runs. `crates/engine/src/tests/script_engines.rs`.
- Scripts: `$.line` is the line of the running script, counting from 1, and `$.stack` is the current stack trace ([the help page](https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/)). VectorCraft's own rules: both count lines in the file the code is in (the script, a file it included, a file `$.evalFile` ran, or the file of an earlier run of the named engine), and `$.stack` starts with a line holding the run's name in square brackets, such as `[main.jsx]`, then writes each frame as `name@file:line`, outermost first; code that `eval` or `Function` compiled keeps its own line in `[eval]`, and code whose place the engine no longer keeps is at line 0 of `[unknown]`. `crates/engine/src/tests/script_include.rs`, `crates/engine/src/tests/script_engines.rs`, `crates/engine/src/tests/script_dollar.rs`, `crates/js/src/extension_tests.rs`.
- Scripts: `File` and `Folder` ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/), [Folder object](https://extendscript.docsforadobe.dev/file-system-access/folder-object/)) name files and folders by platform or URI path, with `name`, `fsName`, `absoluteURI`, `relativeURI`, `parent`, `Folder.current` and `encode`/`decode`, and read them: `exists`, `length`, the dates, `getFiles` with a mask or a function, and `open('r')` with `read`, `readln`, `readch`, `seek`, `tell` and `close`, decoding by byte order mark, `encoding`, UTF-8 or CP1252. VectorCraft's own rules: a script reads only in its own folder and below (and inside the automation read roots when they are set); any other path and a network or device path are refused before anything is looked up, and a link that leads out is refused as well (`false` or `null`, with `error` set); a file is read whole up to 8 MiB and a run reads up to 32 MiB; `execute` is not available. `crates/engine/src/tests/script_io.rs`.
- Scripts: `File` and `Folder` ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/), [Folder object](https://extendscript.docsforadobe.dev/file-system-access/folder-object/)) name files and folders by platform or URI path, with `name`, `fsName`, `absoluteURI`, `relativeURI`, `parent`, `localizedName`, `Folder.current` and `encode`/`decode`, and read them: `exists`, `length`, the dates, `getFiles` with a mask or a function, and `open('r')` with `read`, `readln`, `readch`, `seek`, `tell` and `close`, decoding by byte order mark, `encoding`, UTF-8 or CP1252. VectorCraft's own rules: `localizedName` gives the same decoded name as `displayName`, without looking up a name the system shows in another language; a script reads only in its own folder and below (and inside the automation read roots when they are set); any other path and a network or device path are refused before anything is looked up, and a link that leads out is refused as well (`false` or `null`, with `error` set); a file is read whole up to 8 MiB and a run reads up to 32 MiB; `execute` is not available. `crates/engine/src/tests/script_io.rs`.
- Scripts: `File` and `Folder` write ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/), [Folder object](https://extendscript.docsforadobe.dev/file-system-access/folder-object/)): `open('w')`, `open('e')` and `open('a')` with `write` and `writeln` by `lineFeed`, `copy`, `remove` (a folder only when empty), `rename`, `folder.create()`, the `length` and `readonly` setters, and `File.openDialog`, `File.saveDialog`, `Folder.selectDialog`, `openDlg`, `saveDlg` and `selectDlg`, with a `filter` of file types or a filter function and `multiSelect`. VectorCraft's own rules: a script writes only in `Folder.temp` (one for the run, deleted when it ends), its own `Folder.userData` next to the settings, and what a person allowed it in a file dialog, once or always; Always keeps the grant for that script file with that text by its SHA-256 and for the sources the run evaluated (`$.evalFile`, `eval`, `Function`), so a run that evaluates other code, or whose named engine holds other code, loses it first; `script.grants` lists the grants and `script.grants.revoke` removes them; the settings folder is kept out of every grant; the commands a script runs with `vc.run` read and write only in the same places and the open documents' own files, and read the files linked as the next line says; a run with nobody to ask gets `null` from the dialogs; a file is written at close or when the run ends, 8 MiB a file and 32 MiB a run, and named in `written`, also after a run that failed. `crates/engine/src/tests/script_io.rs`.
- Scripts: an export, save, print or package that a script runs with `vc.run` includes the linked images and placed files of the documents open when the run began, also when those files are outside the script's own places. VectorCraft's own rules: the commands read those files as the links led at the run's first `vc.run` and as the person last opened or saved each document; a link does not let them write the file it names, and they write a linked file only where the previous line lets them write (the script's own write places and the open documents' own files); a path that leads to another file since, a link or data set value a script's command adds or changes, in that run or an earlier one, and a document a script's command opens give it no further file to read, and a document a script's command opened gives the commands no access to its own file until the person saves it; a linked file in the folder that holds the settings is not read unless it lies in one of the script's own places inside that folder, and the automation read roots still apply. `crates/engine/src/tests/script_run.rs`, `file_access::tests` in `vectorcraft-engine`.
- Scripts: the `hidden` setter and `createAlias(target)` ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/)), with setting `hidden`, `rename` and `remove` acting on an alias itself ([Using File and Folder objects](https://extendscript.docsforadobe.dev/file-system-access/using-file-and-folder-objects/)). VectorCraft's own rules: on Unix a name that starts with a dot is hidden, so setting `hidden` renames the file with one dot added or its leading dots taken off, and both names must be places the script may write; `createAlias` makes a symbolic link to the real path of a file the script may read, in a place it may write where nothing is, a link that leads nowhere included; a link is checked again each time it is used; on Windows both set `error` and change nothing. `crates/engine/src/tests/script_io.rs`.
@@ -1082,7 +1082,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- File › Scripts › Check Script… reads a script written for Illustrator (`.jsx`, `.jsxinc` or a compiled `.jsxbin`) without running any of it and reports what it needs (the document model, files, dialogs, menu commands, features only Illustrator has), what it would do outside the document, the menu commands and document-model members it uses, its directives and included files, and the problems that would stop it loading (`script.check`, which also reads `.js` files); File › Open and drag-and-drop show the report for `.jsx`, `.jsxinc` and `.jsxbin` files.
- Check Script reads names by the same identifier rule as `vectorcraft-js`: Unicode 17.0 `ID_Start` characters, `$` and `_` start a name, and `ID_Continue` characters and `$` continue it (https://www.unicode.org/reports/tr31/, https://tc39.es/ecma262/#sec-names-and-keywords). U+2118, U+203F, U+00B7 and the zero width non-joiner and joiner are name characters, and U+00B2 and U+2E2F are not. Of the characters Unicode 17.0 assigned, U+088F starts a name and U+1ACF may follow its first character. A `\uXXXX` escape is read as its character only where a name may hold it, so `\u0030abc` does not become a name that starts with a digit; a `\u{…}` escape takes any number of hexadecimal digits up to U+10FFFF, and one that is empty, unclosed, out of range or a surrogate is not part of a name. Each `\u{…}` escape read in a name is reported as syntax newer than ES3, which has only the four-digit form (https://ecma-international.org/wp-content/uploads/ECMA-262_3rd_edition_december_1999.pdf, section 7.6). A private name may start with an escape (`this.#\u{61}pp` is the private name `#app`), and a private name at the start of a line inside braces is not read as a directive unless its name is a directive's. Tests: `crates/scriptcheck/src/tests.rs` (`names_are_made_of_the_unicode_identifier_characters`, `an_escape_stands_for_a_character_only_where_a_name_may_hold_it`, `braced_escapes_in_names_are_read_by_their_value`, `braced_name_escape_reports_later_syntax_and_member`, `private_names_with_escaped_starts_are_single_tokens`, `private_name_at_line_start_is_not_a_directive`), `crates/engine/tests/it/js_lexer_vs_scriptcheck.rs` (`both_lexers_take_the_same_characters_into_names`).
- Check Script reports `file.write` and `filesWritten` when a script sets a File object's `length`, `hidden` or `readonly` (https://extendscript.docsforadobe.dev/file-system-access/file-object/), by plain or compound assignment, `++` or `--`, or the name as a string literal in brackets. It leaves out only objects that are always Folder objects, `new Folder(…)` and the `Folder` places such as `Folder.temp` other than `Folder.current`, which a script can assign; `Folder(…)` gives a File object when the path names a file and `Folder.selectDialog()` gives a File or Folder object (https://extendscript.docsforadobe.dev/file-system-access/folder-object/), so setting those counts, as it does on a variable that any assignment, in any branch or included file, gives such an object. Nothing counts as a Folder object in a check whose files use `with`, name `eval`, `Function`, `evalFile` or `constructor` as a word or as a string literal in brackets (`this['eval'](s)`, `(function () {}).constructor(s)`), read, call or assign a property in brackets on any object (a `[` after a value, not an array literal) when the brackets hold anything but one number or string literal (`g[k] = …`, `$['global'][k] = …`, `this[k](s)`, `this['ev' + 'al'](s)`, `this[('eval')](s)`, `this[0, 'eval'](s)`, `$[k](f)`, `(function () {})[k](s)`, or a preprocessor line inside the brackets) or the `[` opens while 4,096 other `[` are open, assign a property in brackets whose name is a string literal of more than 256 characters, assign properties of more than 1,000 different names on members, or assign or declare `Folder`, and a variable whose name a member assignment writes (`$.global.d = …`, `this.d = …`, `this['d'] = …`, with the string's escapes undone) counts as one that may hold a File object (`setting_a_folders_length_or_flags_does_not_write`, `a_variable_that_may_hold_a_file_counts_as_one`, `a_file_in_a_local_variable_leaves_an_outer_folder_alone`, `a_folder_that_other_code_may_rebind_counts_as_a_file`, `a_folder_that_unnamed_code_may_rebind_counts_as_a_file`, `a_bracketed_name_is_read_whole_or_counts_as_any_name`, `a_bracketed_variable_read_counts_as_any_name`, `a_bracketed_joined_name_counts_as_any_name`, `a_bracketed_name_in_parentheses_counts_as_any_name`, `a_bracketed_comma_expression_counts_as_any_name`, `a_bracketed_variable_call_on_dollar_counts_as_any_name`, `a_bracketed_variable_constructor_counts_as_any_name`, `a_literal_name_in_brackets_leaves_the_folder_alone`, `a_directive_in_a_bracketed_name_counts_as_any_name`). A test lists every global and member the script host adds to the JavaScript engine, except VectorCraft's own `vc` and its members, and fails when one has no row; for each one that reaches outside the document it checks that `script.check` reports the expected `outside` id, and it checks that the checker lists every directive the host reads. Tests: `crates/scriptcheck/src/tests.rs` (`setting_a_files_length_or_flags_writes_it`), `crates/engine/tests/it/script_host_vs_scriptcheck.rs` (`every_name_the_host_adds_has_a_row`, `every_name_that_reaches_outside_has_its_checker_id`, `the_checker_lists_every_directive_the_host_reads`).
- `vectorcraft-js` parses JavaScript as ECMAScript 5.1 defines it, with the legacy octal forms, block functions and lenient regular expressions of Annex B, into a syntax tree with source spans; it reads the `#target`, `#include` and other preprocessor lines as directives without running them, and a script that breaks the grammar or an early-error rule gives a `SyntaxError` with its line and column. Nesting past the parser's depth limit (`Options::max_depth`, 200 by default) gives a `SyntaxError` instead of exhausting the stack. `cargo xtask test262` fetches the conformance suite at a pinned commit and parses its ES5 tests: 5,411 of 5,418 runs pass (the 7 others use `let` and `const`). This entry covers parsing; the next entry covers running scripts. Tests: `crates/js/src/tests.rs`, `crates/engine/tests/it/js_lexer_vs_scriptcheck.rs`.
- `vectorcraft-js` parses JavaScript as ECMAScript 5.1 defines it, with the legacy octal forms, block functions and lenient regular expressions of Annex B, into a syntax tree with source spans. A comma may follow the last argument of a call or `new` expression and the last parameter of a function other than a setter, as ECMAScript 2017 allows (https://tc39.es/ecma262/2017/#sec-left-hand-side-expressions, https://tc39.es/ecma262/2017/#sec-function-definitions); `f(,)` and `f(1,,)` give a `SyntaxError`. It reads the `#target`, `#include` and other preprocessor lines as directives without running them, and a script that breaks the grammar or an early-error rule gives a `SyntaxError` with its line and column. Nesting past the parser's depth limit (`Options::max_depth`, 200 by default) gives a `SyntaxError` instead of exhausting the stack. `cargo xtask test262` fetches the conformance suite at a pinned commit and parses its ES5 tests: 5,411 of 5,418 runs pass (the 7 others use `let` and `const`). This entry covers parsing; the next entry covers running scripts. Tests: `crates/js/src/tests.rs`, `crates/engine/tests/it/js_lexer_vs_scriptcheck.rs`.
- `vectorcraft-js` identifiers, written out or as `\uXXXX` and `\u{...}` escapes, take the characters Unicode's `ID_Start` and `ID_Continue` properties allow (https://www.unicode.org/reports/tr31/), plus `$` and, at the start, `_`, as later ECMAScript editions define them (https://tc39.es/ecma262/#sec-names-and-keywords). `Other_ID_Start` characters such as U+2118 and `Other_ID_Continue` characters such as U+00B7 and the zero width non-joiner and joiner are accepted, and no `Pattern_Syntax` or `Pattern_White_Space` character is. Letter categories come from Unicode 17.0, so U+088F starts an identifier and U+1ACF may follow its first character; characters assigned after Unicode 17.0 are not yet identifier characters. Tests: `crates/js/src/tests.rs` (`identifier_characters_are_unicode_17_id_start_and_id_continue`, which checks every code point, `identifiers_take_the_characters_unicode_17_assigned`, `identifiers_take_the_other_id_start_and_continue_characters`, `identifiers_refuse_pattern_syntax_surrogates_and_bad_escapes`, `no_pattern_syntax_or_white_space_character_is_an_identifier_character`).
- `vectorcraft-js`'s `Realm` runs ECMAScript 5.1 scripts: the parsed script compiles to verified bytecode that a non-recursive interpreter runs, with closures, `this`, `arguments`, `with`, direct and indirect `eval`, `new Function`, `try`/`catch`/`finally`, labeled `break` and `continue`, and `for`-`in` in insertion order, over a mark-and-sweep heap, with the built-ins the next two entries list. Every run is bounded by fuel, heap bytes, frames, nested host calls and an interrupt flag (smaller defaults in the wasm build), and a run that reaches a limit stops with a limit error that `try` cannot catch. `cargo xtask test262` also runs the suite's ES5 language tests that need only the built-ins present: 4,280 of 4,286 runs pass (4 of the others expect the completion values of later editions, and 2 expect a configurable function `length`). The app does not call it yet. Tests: `crates/js/src/interp_tests.rs`, `crates/js/tests/test262.rs`.
- With `Options::es2015`, `vectorcraft-js` also reads and runs these ECMAScript 2015 forms (https://262.ecma-international.org/6.0/): `let` and `const` with block scope and their temporal dead zone (a read or write before the declaration runs throws a `ReferenceError`, and a write to a `const` throws a `TypeError` in any code), a new `let` binding for each iteration of a `for` or `for`-`in` loop, function declarations scoped to their block, arrow functions with the `this` and `arguments` of the code around them and no `prototype`, template literals and tagged templates with one frozen strings object for each site, default and rest parameters with an `arguments` object that does not follow the parameters, and spread in array literals, calls and `new`. Spread reads arrays by index, reading the length again before each element, strings and `String` objects by code point, and objects with a `length` property by index, and throws a `TypeError` for any other value; that rule is VectorCraft's own until iterators are added. Spread and template objects take fuel for each element and count against the heap limit, and nested arrows and templates count against `Options::max_depth`. `script.run` sets the option for a `.js` file, and `eval`, `Function`, `#include` files and `$.evalFile` read code the way the script does; a `.jsx` file and a `source` string stay ES5.1. Destructuring, `for`-`of`, classes, generators and modules are still syntax errors. `cargo xtask test262` reads the suite's tests of these forms without and with the option: 390 of 390 negative parse runs and 533 of 708 other runs pass with it (373 and 27 without it). Of the 175 failing runs, 151 do not parse because the tests also use forms this list leaves out (classes, method definitions, destructuring, `for`-`of`, trailing commas in parameter lists, and a later edition's rule for escapes in tagged templates), and 24 expect function `name` properties, a configurable function `length` and the `caller` and `arguments` restrictions, ECMAScript 2015 rules that `vectorcraft-js` does not implement. Tests: `crates/js/src/es2015_tests.rs`, `crates/js/tests/test262.rs`, `crates/engine/src/tests/script_run.rs`.