mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 21:12:57 -05:00
Scripts: placed and raster members use main's described member lists; a placedItems.add() result goes stale after File > Revert
The images, tracing and save/open members now carry the type and argument descriptions that main's Described lists expect, and PlacedItem.contentVariable comes from the variables members. A placedItems.add() handle now records the document's revert count, so reading or assigning its file after File > Revert throws Stale page item and places nothing, as other page items do.
This commit is contained in:
1 parent
19f1cf0aa0
commit
e59994ead4
7 files changed
+140
-112
No files matched your search
@@ -575,12 +575,9 @@ fn item_of(h: &Host, d: &Data) -> std::result::Result<Item, HostError> {
|
||||
};
|
||||
let (doc, id) = match handle.as_slice() {
|
||||
[_, _, _, _, _] => node_of(h, &handle).ok_or_else(|| HostError::Error(STALE_ITEM.into()))?,
|
||||
&[run, uid, _, _, reverts, slot] => {
|
||||
let doc = find_doc(h, run, uid).ok_or_else(|| HostError::Error(STALE_ITEM.into()))?;
|
||||
if h.session.borrow().documents().get(doc.index).map(|st| st.reverts) != whole(reverts) {
|
||||
return Err(HostError::Error(STALE_ITEM.into()));
|
||||
}
|
||||
(doc, images::pending_id(h, run, uid, slot)?)
|
||||
&[run, uid, _, _, _, slot] => {
|
||||
let id = images::pending_id(h, run, uid, slot)?;
|
||||
(find_doc(h, run, uid).ok_or_else(|| HostError::Error(STALE_ITEM.into()))?, id)
|
||||
}
|
||||
_ => return Err(HostError::Type("this is not a page item".into())),
|
||||
};
|
||||
@@ -2972,9 +2969,8 @@ fn classes(link: &Link) -> Vec<HostClass> {
|
||||
]);
|
||||
document.extend(defaults::document_members(l));
|
||||
document.extend(text::styles::doc_members(l));
|
||||
document.extend(
|
||||
["layers", "artboards", "groupItems", "swatches", "symbols", "activeLayer", "close"].into_iter().map(|m| later(l, "Document", m)),
|
||||
);
|
||||
document
|
||||
.extend(["layers", "artboards", "groupItems", "swatches", "symbols", "activeLayer", "close"].into_iter().map(|m| later(l, "Document", m)));
|
||||
document.extend(save_open::document_members(l));
|
||||
document.extend(images::document_members(l));
|
||||
document.extend(variables::document_members(l));
|
||||
|
||||
@@ -37,12 +37,12 @@ use std::sync::Arc;
|
||||
|
||||
use serde_json::json;
|
||||
use vectorcraft_geom::{Affine, Point};
|
||||
use vectorcraft_js::{Data, HostClass, HostError, HostMember, file_ref, file_ref_path, host_ref, host_ref_parts};
|
||||
use vectorcraft_js::{Data, HostClass, HostError, MemberInfo, file_ref, file_ref_path, host_ref, host_ref_parts};
|
||||
|
||||
use super::{
|
||||
Answer, Coords, Doc, Host, Item, Link, NOT_FOUND, ON_LOCKED_ARTBOARD, STALE_ITEM, all_editable, arg, class, command, command_value, doc_of,
|
||||
doc_ref, edit_item, editable, find_doc, float, frame, get, item_of, item_ref, later, method, named, num, on_doc, page_items, property, text,
|
||||
typename_of, whole, with_doc,
|
||||
Answer, Coords, Described, Doc, Host, Item, Link, NOT_FOUND, ON_LOCKED_ARTBOARD, STALE_ITEM, all_editable, arg, class, command, command_value,
|
||||
doc_of, doc_ref, edit_item, editable, find_doc, float, frame, get, item_of, item_ref, later, method, named, num, on_doc, page_items, property,
|
||||
returns, text, typed, typename_of, variables, whole, with_doc,
|
||||
};
|
||||
use crate::{DocState, Document, NodeId, NodeKind};
|
||||
|
||||
@@ -86,22 +86,23 @@ pub(super) struct State {
|
||||
lists: RefCell<Option<Lists>>,
|
||||
}
|
||||
|
||||
/// A `PlacedItems.add()` result: its document, and its image once `file` placed one.
|
||||
/// A `PlacedItems.add()` result: its document, how many times that document had been reverted then,
|
||||
/// and its image once `file` placed one.
|
||||
struct Pending {
|
||||
uid: u64,
|
||||
reverts: u64,
|
||||
bound: Option<NodeId>,
|
||||
}
|
||||
|
||||
/// The slot of a `PlacedItems.add()` result in this run, from its handle.
|
||||
/// The slot of a `PlacedItems.add()` result in this run, from its handle. A result whose document
|
||||
/// was closed or reverted since is stale.
|
||||
fn slot_of(h: &Host, run: f64, uid: f64, slot: f64) -> Result<usize, HostError> {
|
||||
let stale = || HostError::Error(STALE_ITEM.into());
|
||||
if whole(run) != Some(h.run) {
|
||||
return Err(stale());
|
||||
}
|
||||
let doc = find_doc(h, run, uid).ok_or_else(stale)?;
|
||||
let reverts = h.session.borrow().documents().get(doc.index).map(|st| st.reverts);
|
||||
let k = whole(slot).and_then(|k| usize::try_from(k).ok()).ok_or_else(stale)?;
|
||||
let uid = whole(uid).ok_or_else(stale)?;
|
||||
match h.dom.images.pending.borrow().get(k) {
|
||||
Some(p) if p.uid == uid => Ok(k),
|
||||
Some(p) if p.uid == doc.uid && Some(p.reverts) == reverts => Ok(k),
|
||||
_ => Err(stale()),
|
||||
}
|
||||
}
|
||||
@@ -115,12 +116,12 @@ pub(super) fn pending_id(h: &Host, run: f64, uid: f64, slot: f64) -> Result<Node
|
||||
}
|
||||
}
|
||||
|
||||
/// The handle's run, uid and slot when `d` is a `PlacedItems.add()` result. Its handle has five
|
||||
/// numbers, where a page item's has four.
|
||||
/// The handle's run, uid and slot when `d` is a `PlacedItems.add()` result. Its handle has six
|
||||
/// numbers, where a page item's has five.
|
||||
fn pending_handle(d: &Data) -> Option<[f64; 3]> {
|
||||
match host_ref_parts(d) {
|
||||
Some(("PlacedItem", handle)) => match handle.as_slice() {
|
||||
[run, uid, _, _, slot] => Some([*run, *uid, *slot]),
|
||||
[run, uid, _, _, _, slot] => Some([*run, *uid, *slot]),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
@@ -241,12 +242,13 @@ fn list_remove_all(h: &Host, a: &[Data], placed: bool) -> Answer {
|
||||
/// `PlacedItems.add()`: a placed item with no file yet, which assigning `file` places.
|
||||
fn placed_add(h: &Host, a: &[Data]) -> Answer {
|
||||
let doc = list_doc(h, a, true)?;
|
||||
let reverts = h.session.borrow().documents().get(doc.index).map_or(0, |st| st.reverts);
|
||||
let mut pending = h.dom.images.pending.borrow_mut();
|
||||
if pending.len() >= MAX_PENDING {
|
||||
return Err(HostError::Range(format!("a run makes at most {MAX_PENDING} placed items with PlacedItems.add")));
|
||||
}
|
||||
pending.push(Pending { uid: doc.uid, bound: None });
|
||||
Ok(host_ref("PlacedItem", &[float(h.run), float(doc.uid), 0.0, 0.0, float(pending.len() as u64 - 1)]))
|
||||
pending.push(Pending { uid: doc.uid, reverts, bound: None });
|
||||
Ok(host_ref("PlacedItem", &[float(h.run), float(doc.uid), 0.0, 0.0, float(reverts), float(pending.len() as u64 - 1)]))
|
||||
}
|
||||
|
||||
macro_rules! both {
|
||||
@@ -623,50 +625,54 @@ fn raster_status(h: &Host, a: &[Data]) -> Answer {
|
||||
}
|
||||
|
||||
/// `Document.placedItems` and `Document.rasterItems`.
|
||||
pub(super) fn document_members(l: &Link) -> Vec<(String, HostMember)> {
|
||||
named(vec![("placedItems", get(l, doc_placed)), ("rasterItems", get(l, doc_raster))])
|
||||
pub(super) fn document_members(l: &Link) -> Vec<Described> {
|
||||
named(vec![
|
||||
("placedItems", get(l, doc_placed), MemberInfo { collection: true, ..typed("PlacedItems") }),
|
||||
("rasterItems", get(l, doc_raster), MemberInfo { collection: true, ..typed("RasterItems") }),
|
||||
])
|
||||
}
|
||||
|
||||
/// The collections, `PlacedItem` and `RasterItem`, after `PageItem`.
|
||||
pub(super) fn classes(l: &Link) -> Vec<HostClass> {
|
||||
let placed_list = named(vec![
|
||||
("typename", typename_of("PlacedItems")),
|
||||
("length", get(l, placed_length)),
|
||||
("parent", get(l, placed_parent)),
|
||||
("index", method(l, placed_index)),
|
||||
("getByName", method(l, placed_by_name)),
|
||||
("removeAll", method(l, placed_remove_all)),
|
||||
("add", method(l, placed_add)),
|
||||
("typename", typename_of("PlacedItems"), typed("string")),
|
||||
("length", get(l, placed_length), typed("number")),
|
||||
("parent", get(l, placed_parent), typed("Document")),
|
||||
("index", method(l, placed_index), returns("PlacedItem", &[("itemKey", "*")])),
|
||||
("getByName", method(l, placed_by_name), returns("PlacedItem", &[("name", "string")])),
|
||||
("removeAll", method(l, placed_remove_all), returns("undefined", &[])),
|
||||
("add", method(l, placed_add), returns("PlacedItem", &[])),
|
||||
]);
|
||||
let raster_list = named(vec![
|
||||
("typename", typename_of("RasterItems")),
|
||||
("length", get(l, raster_length)),
|
||||
("parent", get(l, raster_parent)),
|
||||
("index", method(l, raster_index)),
|
||||
("getByName", method(l, raster_by_name)),
|
||||
("removeAll", method(l, raster_remove_all)),
|
||||
("typename", typename_of("RasterItems"), typed("string")),
|
||||
("length", get(l, raster_length), typed("number")),
|
||||
("parent", get(l, raster_parent), typed("Document")),
|
||||
("index", method(l, raster_index), returns("RasterItem", &[("itemKey", "*")])),
|
||||
("getByName", method(l, raster_by_name), returns("RasterItem", &[("name", "string")])),
|
||||
("removeAll", method(l, raster_remove_all), returns("undefined", &[])),
|
||||
]);
|
||||
let mut placed = named(vec![
|
||||
("file", property(l, placed_file, placed_set_file)),
|
||||
("relink", method(l, placed_relink)),
|
||||
("embed", method(l, placed_embed)),
|
||||
("matrix", property(l, placed_matrix, placed_set_matrix)),
|
||||
("boundingBox", get(l, placed_box)),
|
||||
("file", property(l, placed_file, placed_set_file), typed("File")),
|
||||
("relink", method(l, placed_relink), returns("undefined", &[("relinkFile", "File")])),
|
||||
("embed", method(l, placed_embed), returns("undefined", &[])),
|
||||
("matrix", property(l, placed_matrix, placed_set_matrix), typed("Matrix")),
|
||||
("boundingBox", get(l, placed_box), typed("Array")),
|
||||
]);
|
||||
placed.push(later(l, "PlacedItem", "contentVariable"));
|
||||
placed.extend(variables::item_members(l, "PlacedItem"));
|
||||
let mut raster = named(vec![
|
||||
("bitsPerChannel", get(l, raster_bits)),
|
||||
("channels", get(l, raster_channels)),
|
||||
("colorizedGrayscale", get(l, raster_colorized)),
|
||||
("embedded", property(l, raster_embedded, raster_set_embedded)),
|
||||
("file", get(l, raster_file)),
|
||||
("imageColorSpace", get(l, raster_color_space)),
|
||||
("matrix", property(l, raster_matrix, raster_set_matrix)),
|
||||
("status", get(l, raster_status)),
|
||||
("transparent", get(l, raster_transparent)),
|
||||
("boundingBox", get(l, raster_box)),
|
||||
("bitsPerChannel", get(l, raster_bits), typed("number")),
|
||||
("channels", get(l, raster_channels), typed("number")),
|
||||
("colorizedGrayscale", get(l, raster_colorized), typed("boolean")),
|
||||
("embedded", property(l, raster_embedded, raster_set_embedded), typed("boolean")),
|
||||
("file", get(l, raster_file), typed("File")),
|
||||
("imageColorSpace", get(l, raster_color_space), typed("ImageColorSpace")),
|
||||
("matrix", property(l, raster_matrix, raster_set_matrix), typed("Matrix")),
|
||||
("status", get(l, raster_status), typed("RasterLinkState")),
|
||||
("transparent", get(l, raster_transparent), typed("boolean")),
|
||||
("boundingBox", get(l, raster_box), typed("Array")),
|
||||
]);
|
||||
raster.extend(["colorants", "colorize", "contentVariable", "overprint"].into_iter().map(|m| later(l, "RasterItem", m)));
|
||||
raster.extend(variables::item_members(l, "RasterItem"));
|
||||
raster.extend(["colorants", "colorize", "overprint"].into_iter().map(|m| later(l, "RasterItem", m)));
|
||||
vec![
|
||||
class("PlacedItems", None, placed_list, Some(super::function(l, placed_at))),
|
||||
class("RasterItems", None, raster_list, Some(super::function(l, raster_at))),
|
||||
|
||||
@@ -39,11 +39,11 @@ use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use serde_json::{Map, Value, json};
|
||||
use vectorcraft_js::{Data, HostClass, HostError, HostFunction, HostMember};
|
||||
use vectorcraft_js::{Data, HostClass, HostError, HostFunction};
|
||||
|
||||
use super::{
|
||||
Answer, Host, Link, MAX_TEXT_BYTES, NO_ACTIVE_DOCUMENT, arg, boolean, command, current, doc_ref, given, method, named, num, on_doc, property,
|
||||
text, this_doc, whole,
|
||||
Answer, Described, Host, Link, MAX_TEXT_BYTES, NO_ACTIVE_DOCUMENT, arg, boolean, command, current, doc_ref, given, method, named, num, on_doc,
|
||||
property, returns, text, this_doc, typed, whole,
|
||||
};
|
||||
|
||||
/// The most a scale factor of an export takes, in percent.
|
||||
@@ -787,13 +787,19 @@ fn app_set_interaction(h: &Host, a: &[Data]) -> Answer {
|
||||
}
|
||||
|
||||
/// The members these add to `Application`.
|
||||
pub(super) fn application_members(l: &Link) -> Vec<(String, HostMember)> {
|
||||
named(vec![("open", method(l, app_open)), ("userInteractionLevel", property(l, app_interaction, app_set_interaction))])
|
||||
pub(super) fn application_members(l: &Link) -> Vec<Described> {
|
||||
named(vec![
|
||||
("open", method(l, app_open), returns("Document", &[("file", "File"), ("documentColorSpace", "DocumentColorSpace"), ("options", "*")])),
|
||||
("userInteractionLevel", property(l, app_interaction, app_set_interaction), typed("UserInteractionLevel")),
|
||||
])
|
||||
}
|
||||
|
||||
/// The members these add to `Document`.
|
||||
pub(super) fn document_members(l: &Link) -> Vec<(String, HostMember)> {
|
||||
named(vec![("saveAs", method(l, doc_save_as)), ("exportFile", method(l, doc_export_file))])
|
||||
pub(super) fn document_members(l: &Link) -> Vec<Described> {
|
||||
named(vec![
|
||||
("saveAs", method(l, doc_save_as), returns("undefined", &[("saveIn", "File"), ("options", "*")])),
|
||||
("exportFile", method(l, doc_export_file), returns("undefined", &[("exportFile", "File"), ("exportFormat", "ExportType"), ("options", "*")])),
|
||||
])
|
||||
}
|
||||
|
||||
/// The option classes: each `new Name()` gives a record with its `typename` and the defaults its
|
||||
@@ -806,7 +812,7 @@ pub(super) fn classes(link: &Link) -> Vec<HostClass> {
|
||||
current(&l)?.charge_call(64)?;
|
||||
Ok(fresh(c))
|
||||
});
|
||||
HostClass { name: c.name.into(), parent: None, members: Vec::new(), index: None, construct: Some(f) }
|
||||
HostClass { name: c.name.into(), parent: None, members: Vec::new(), info: Vec::new(), index: None, construct: Some(f) }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -39,11 +39,11 @@ use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::{Map, Value, json};
|
||||
use vectorcraft_js::{Data, HostClass, HostError, HostMember, host_ref, host_ref_parts};
|
||||
use vectorcraft_js::{Data, HostClass, HostError, HostMember, MemberInfo, host_ref, host_ref_parts};
|
||||
|
||||
use super::{
|
||||
Answer, Host, Item, Link, STALE_ITEM, arg, boolean, class, command, command_value, edit_item, find_doc, float, get, id_of, item_of, item_ref,
|
||||
method, named, num, number, on_doc, property, text, typename_of, whole, with_doc,
|
||||
Answer, Described, Host, Item, Link, STALE_ITEM, arg, boolean, class, command, command_value, edit_item, float, get, item_of, item_ref, method,
|
||||
named, node_of, num, number, on_doc, property, returns, text, typed, typename_of, whole, with_doc,
|
||||
};
|
||||
use crate::doc::{Node, TraceView};
|
||||
use crate::{NodeId, NodeKind};
|
||||
@@ -179,27 +179,27 @@ fn result_id(v: &Value, key: &str) -> Option<NodeId> {
|
||||
|
||||
/// The Image Trace object, its document and the id its handle holds, of the `cls` (`TracingObject`
|
||||
/// or `TracingOptions`) `d` names. It must still be an Image Trace object of its document.
|
||||
fn tracing_of(h: &Host, d: &Data, cls: &str) -> Result<(Item, [f64; 4]), HostError> {
|
||||
fn tracing_of(h: &Host, d: &Data, cls: &str) -> Result<(Item, [f64; 5]), HostError> {
|
||||
let Some((c, handle)) = host_ref_parts(d).filter(|(c, _)| *c == cls) else {
|
||||
return Err(HostError::Type(format!("this is not a {cls}")));
|
||||
};
|
||||
let &[run, uid, high, low] = handle.as_slice() else { return Err(HostError::Type(format!("this is not a {c}"))) };
|
||||
let doc = find_doc(h, run, uid).ok_or_else(stale)?;
|
||||
let id = follow(h, doc.uid, id_of(high, low).ok_or_else(stale)?);
|
||||
let &[run, uid, high, low, reverts] = handle.as_slice() else { return Err(HostError::Type(format!("this is not a {c}"))) };
|
||||
let (doc, id) = node_of(h, &handle).ok_or_else(stale)?;
|
||||
let id = follow(h, doc.uid, id);
|
||||
let live = with_doc(h, doc, |_, st| st.doc.node(id).is_some_and(crate::cmd::is_trace_group));
|
||||
if !live {
|
||||
return Err(stale());
|
||||
}
|
||||
Ok((Item { doc, id }, [run, uid, high, low]))
|
||||
Ok((Item { doc, id }, [run, uid, high, low, reverts]))
|
||||
}
|
||||
|
||||
/// The `PluginItem` `this` names, with the handle numbers its `tracing` keeps.
|
||||
fn plugin_of(h: &Host, a: &[Data]) -> Result<(Item, [f64; 4]), HostError> {
|
||||
fn plugin_of(h: &Host, a: &[Data]) -> Result<(Item, [f64; 5]), HostError> {
|
||||
match host_ref_parts(arg(a, 0)) {
|
||||
Some(("PluginItem", handle)) => {
|
||||
let item = item_of(h, arg(a, 0))?;
|
||||
match handle.as_slice() {
|
||||
&[run, uid, high, low] => Ok((item, [run, uid, high, low])),
|
||||
&[run, uid, high, low, reverts] => Ok((item, [run, uid, high, low, reverts])),
|
||||
_ => Err(HostError::Type("this is not a PluginItem".into())),
|
||||
}
|
||||
}
|
||||
@@ -681,7 +681,7 @@ fn options_store(h: &Host, a: &[Data]) -> Answer {
|
||||
|
||||
/// A member of `TracingOptions` with no VectorCraft setting: reading and assigning it both throw,
|
||||
/// after the check that the tracing `this` names is still there.
|
||||
fn missing(link: &Link, name: &'static str) -> (String, HostMember) {
|
||||
fn missing(link: &Link, name: &'static str) -> Described {
|
||||
let message = not_implemented("TracingOptions", name);
|
||||
let l = link.clone();
|
||||
let f: vectorcraft_js::HostFunction = std::rc::Rc::new(move |a: Vec<Data>| {
|
||||
@@ -690,52 +690,54 @@ fn missing(link: &Link, name: &'static str) -> (String, HostMember) {
|
||||
tracing_of(&h, arg(&a, 0), "TracingOptions")?;
|
||||
Err(HostError::Error(message.clone()))
|
||||
});
|
||||
(name.to_string(), HostMember::Property { get: f.clone(), set: f })
|
||||
(name.to_string(), HostMember::Property { get: f.clone(), set: f }, MemberInfo { unavailable: true, ..MemberInfo::default() })
|
||||
}
|
||||
|
||||
/// Adds `trace()` to the `PlacedItem` and `RasterItem` classes in `classes`.
|
||||
pub(super) fn add_trace(classes: &mut [HostClass], l: &Link) {
|
||||
for c in classes.iter_mut() {
|
||||
match c.name.as_str() {
|
||||
"PlacedItem" => c.members.push(("trace".into(), method(l, placed_trace))),
|
||||
"RasterItem" => c.members.push(("trace".into(), method(l, raster_trace))),
|
||||
_ => {}
|
||||
}
|
||||
let f: super::Member = match c.name.as_str() {
|
||||
"PlacedItem" => placed_trace,
|
||||
"RasterItem" => raster_trace,
|
||||
_ => continue,
|
||||
};
|
||||
c.members.push(("trace".into(), method(l, f)));
|
||||
c.info.push(("trace".into(), returns("PluginItem", &[])));
|
||||
}
|
||||
}
|
||||
|
||||
/// `PluginItem`, after `PageItem`, `TracingObject` and `TracingOptions`.
|
||||
pub(super) fn classes(l: &Link) -> Vec<HostClass> {
|
||||
let plugin = named(vec![("isTracing", get(l, plugin_is_tracing)), ("tracing", get(l, plugin_tracing))]);
|
||||
let plugin = named(vec![("isTracing", get(l, plugin_is_tracing), typed("boolean")), ("tracing", get(l, plugin_tracing), typed("TracingObject"))]);
|
||||
let tracing = named(vec![
|
||||
("typename", typename_of("TracingObject")),
|
||||
("anchorCount", get(l, tracing_anchors)),
|
||||
("areaCount", get(l, tracing_areas)),
|
||||
("imageResolution", get(l, tracing_resolution)),
|
||||
("parent", get(l, tracing_parent)),
|
||||
("pathCount", get(l, tracing_paths)),
|
||||
("sourceArt", get(l, tracing_source)),
|
||||
("tracingOptions", get(l, tracing_options)),
|
||||
("usedColorCount", get(l, tracing_colors)),
|
||||
("expandTracing", method(l, tracing_expand)),
|
||||
("releaseTracing", method(l, tracing_release)),
|
||||
("typename", typename_of("TracingObject"), typed("string")),
|
||||
("anchorCount", get(l, tracing_anchors), typed("number")),
|
||||
("areaCount", get(l, tracing_areas), typed("number")),
|
||||
("imageResolution", get(l, tracing_resolution), typed("number")),
|
||||
("parent", get(l, tracing_parent), typed("PluginItem")),
|
||||
("pathCount", get(l, tracing_paths), typed("number")),
|
||||
("sourceArt", get(l, tracing_source), typed("PageItem")),
|
||||
("tracingOptions", get(l, tracing_options), typed("TracingOptions")),
|
||||
("usedColorCount", get(l, tracing_colors), typed("number")),
|
||||
("expandTracing", method(l, tracing_expand), returns("GroupItem", &[("viewed", "boolean")])),
|
||||
("releaseTracing", method(l, tracing_release), returns("PageItem", &[])),
|
||||
]);
|
||||
let mut options = named(vec![
|
||||
("typename", typename_of("TracingOptions")),
|
||||
("parent", get(l, options_parent)),
|
||||
("preset", get(l, options_preset)),
|
||||
("tracingMode", property(l, options_mode, options_set_mode)),
|
||||
("threshold", property(l, options_threshold, options_set_threshold)),
|
||||
("fills", property(l, options_fills, options_set_fills)),
|
||||
("strokes", property(l, options_strokes, options_set_strokes)),
|
||||
("maxColors", property(l, options_max_colors, options_set_max_colors)),
|
||||
("palette", property(l, options_palette, options_set_palette)),
|
||||
("ignoreWhite", property(l, options_ignore_white, options_set_ignore_white)),
|
||||
("minArea", property(l, options_min_area, options_set_min_area)),
|
||||
("viewRaster", property(l, options_view_raster, options_set_view_raster)),
|
||||
("viewVector", property(l, options_view_vector, options_set_view_vector)),
|
||||
("loadFromPreset", method(l, options_load)),
|
||||
("storeToPreset", method(l, options_store)),
|
||||
("typename", typename_of("TracingOptions"), typed("string")),
|
||||
("parent", get(l, options_parent), typed("TracingObject")),
|
||||
("preset", get(l, options_preset), typed("string")),
|
||||
("tracingMode", property(l, options_mode, options_set_mode), typed("TracingModeType")),
|
||||
("threshold", property(l, options_threshold, options_set_threshold), MemberInfo { min: Some(0.0), max: Some(255.0), ..typed("number") }),
|
||||
("fills", property(l, options_fills, options_set_fills), typed("boolean")),
|
||||
("strokes", property(l, options_strokes, options_set_strokes), typed("boolean")),
|
||||
("maxColors", property(l, options_max_colors, options_set_max_colors), MemberInfo { min: Some(2.0), max: Some(256.0), ..typed("number") }),
|
||||
("palette", property(l, options_palette, options_set_palette), typed("string")),
|
||||
("ignoreWhite", property(l, options_ignore_white, options_set_ignore_white), typed("boolean")),
|
||||
("minArea", property(l, options_min_area, options_set_min_area), typed("number")),
|
||||
("viewRaster", property(l, options_view_raster, options_set_view_raster), typed("ViewRasterType")),
|
||||
("viewVector", property(l, options_view_vector, options_set_view_vector), typed("ViewVectorType")),
|
||||
("loadFromPreset", method(l, options_load), returns("boolean", &[("presetName", "string")])),
|
||||
("storeToPreset", method(l, options_store), returns("boolean", &[("presetName", "string")])),
|
||||
]);
|
||||
options.extend(NOT_IMPLEMENTED.iter().map(|m| missing(l, m)));
|
||||
vec![
|
||||
|
||||
@@ -101,6 +101,24 @@ fn placed_add_file_links_one_image() {
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
/// A `placedItems.add()` result made before File › Revert is stale, as the document's other objects
|
||||
/// are, and places nothing.
|
||||
#[test]
|
||||
fn a_placed_items_add_result_is_stale_after_a_revert() {
|
||||
let base = folder("add-revert");
|
||||
let png = base.join("main/a.png");
|
||||
std::fs::write(&png, gray_png(4, 2)).unwrap();
|
||||
let mut s = session();
|
||||
s.execute("document.save", &json!({"path": base.join("main/saved.vectorcraft").to_string_lossy()})).unwrap();
|
||||
let assign = format!("p.file = new File('{}')", js_path(&png));
|
||||
for read in ["p.file", assign.as_str()] {
|
||||
let e = failure(&mut s, &base, &format!("var p = app.activeDocument.placedItems.add(); vc.run('file.revert'); {read};"));
|
||||
assert!(e.contains("Stale page item"), "{read}: {e}");
|
||||
}
|
||||
assert!(images(&s).is_empty());
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn placed_file_refuses_bad_values_without_changing_the_document() {
|
||||
let base = folder("bad");
|
||||
|
||||
@@ -117,7 +117,7 @@ const INSIDE: &[(&str, &str)] = &[
|
||||
defaultStrokeMiterLimit defaultStrokeMiterLimit= defaultStrokeOverprint defaultStrokeOverprint= \
|
||||
defaultStrokeWidth defaultStrokeWidth= defaultStroked defaultStroked= documentColorSpace groupItems \
|
||||
groupItems= height layers layers= name pageItems paragraphStyles parent pathItems placedItems rasterItems \
|
||||
rulerOrigin rulerOrigin= rulerUnits saveAs saveAs= scaleFactor selection selection= stories swatches swatches= \
|
||||
rulerOrigin rulerOrigin= rulerUnits saveAs scaleFactor selection selection= stories swatches swatches= \
|
||||
symbols symbols= tags textFrames toString typename views width",
|
||||
),
|
||||
("Views.", "prototype"),
|
||||
|
||||
+2
-2
@@ -3165,8 +3165,8 @@ through `$`:
|
||||
item before the value, so a stale item throws `Stale page item` whatever the value. Assigning `matrix` to an `add()`
|
||||
result without a file throws `PlacedItem.file is required` whatever the value, and assigning `file` to one checks
|
||||
the file and places the image. A run keeps at most 1,024 `placedItems.add()` results, and one that was not given a
|
||||
file is dropped at the end of the run. `contentVariable`, `colorants`, `colorize` and `overprint` are not available
|
||||
yet.
|
||||
file is dropped at the end of the run. `contentVariable` works as the variables paragraph below describes, and
|
||||
`colorants`, `colorize` and `overprint` are not available yet.
|
||||
- `PlacedItem.trace()` and `RasterItem.trace()` trace the image with `imageTrace.make` and the Default preset and
|
||||
return the Image Trace object as a `PluginItem` (https://ai-scripting.docsforadobe.dev/jsobjref/PluginItem/), whose
|
||||
`isTracing` is `true` and whose `tracing` is its `TracingObject`
|
||||
|
||||
Reference in new issue
Block a user