Merge main into feat/plugin-api-live-effect-appearance

This commit is contained in:
dotCooCoo committed 2026-11-25 18:37:06 -08:00
commit 1fb8202f67
334 files changed
+18941 -1532

No files matched your search

+70 -3
View File
@@ -38,6 +38,8 @@ pub const MITER_LIMIT: std::ops::RangeInclusive<f64> = 1.0..=500.0;
pub const MAX_EFFECT_ID: usize = 128;
/// Largest data a plug-in may keep with a document (`documentData`), in bytes of JSON.
pub const MAX_DOCUMENT_DATA: usize = 1 << 20;
/// Most characters of a filter's `notice` as the host shows it, its escapes counted.
pub const MAX_NOTICE_CHARS: usize = 200;
/// Most text a filter is given of one type object, in bytes of UTF-8 over all its runs: longer
/// type comes with `truncated` and no runs or paragraphs.
pub const MAX_INPUT_TEXT: usize = 256 * 1024;
@@ -794,10 +796,12 @@ pub struct Output {
/// (what the plug-in keeps stays as it is), `Some(None)` for `null` (it forgets it), else what
/// it keeps from now on, at most [`MAX_DOCUMENT_DATA`] bytes of JSON.
pub document_data: Option<Option<Value>>,
/// `notice`, the run's report for the status bar, as [`decode_notice`] reads it.
pub notice: Option<String>,
}
/// Parses a filter's output: `{"objects": [...], "documentData"?: …}`, or `{"error": "message"}`
/// when the plug-in declined (the message reaches the user).
/// Parses a filter's output: `{"objects": [...], "documentData"?: …, "notice"?: "…"}`, or
/// `{"error": "message"}` when the plug-in declined (the message reaches the user).
pub fn decode_output(bytes: &[u8]) -> Result<Output> {
decode_output_with(bytes, &[], &HashMap::new())
}
@@ -822,7 +826,70 @@ pub fn decode_output_with(bytes: &[u8], input: &[u8], read_only: &ReadOnlySpans)
Some(Some(data))
}
};
Ok(Output { objects, document_data })
let notice = decode_notice(&v)?;
Ok(Output { objects, document_data, notice })
}
/// The `notice` of output `v`: `None` when it has none (or `null`), else its text without the
/// white space around it, as [`crate::permissions::display_text`] shows plug-in text (control,
/// bidirectional formatting and separator characters escaped) and at most [`MAX_NOTICE_CHARS`]
/// characters. A `notice` that is not a string, or whose shown part has no character besides white
/// space, control characters and the default-ignorable characters the host does not escape, is an
/// error.
pub fn decode_notice(v: &Value) -> Result<Option<String>> {
match v.get("notice") {
None | Some(Value::Null) => Ok(None),
Some(Value::String(s)) if shown_part_is_visible(s.trim()) => Ok(Some(crate::permissions::display_text(s.trim(), MAX_NOTICE_CHARS))),
Some(_) => Err(Error::Output("`notice` must be a string with visible text".into())),
}
}
/// Does the part of notice `s` that [`crate::permissions::display_text`] keeps within
/// [`MAX_NOTICE_CHARS`], escapes counted and room left for the `…` when it cuts, hold a character
/// that draws something?
fn shown_part_is_visible(s: &str) -> bool {
let shows = |c: char| !c.is_whitespace() && !c.is_control() && !draws_nothing(c);
let width = |c: char| crate::permissions::display_text(c.encode_utf8(&mut [0; 4]), usize::MAX).chars().count();
// Characters written through the end of `c`, and through the first visible character.
let mut used = 0;
let mut visible_by = None;
for c in s.chars() {
used += width(c);
if visible_by.is_none() && shows(c) {
visible_by = Some(used);
}
if used > MAX_NOTICE_CHARS {
break;
}
}
visible_by.is_some_and(|end| used <= MAX_NOTICE_CHARS || end < MAX_NOTICE_CHARS)
}
/// Is `c` one of Unicode's default-ignorable characters (soft hyphen, zero-width and invisible
/// characters, fillers, variation selectors, tags) that [`crate::permissions::display_text`] keeps
/// as it is, so it draws nothing? The bidirectional ones it escapes are not among them.
fn draws_nothing(c: char) -> bool {
matches!(
c,
'\u{00AD}'
| '\u{034F}'
| '\u{115F}'
| '\u{1160}'
| '\u{17B4}'
| '\u{17B5}'
| '\u{180B}'..='\u{180F}'
| '\u{200B}'..='\u{200D}'
| '\u{2060}'..='\u{2065}'
| '\u{206A}'..='\u{206F}'
| '\u{3164}'
| '\u{FE00}'..='\u{FE0F}'
| '\u{FEFF}'
| '\u{FFA0}'
| '\u{FFF0}'..='\u{FFF8}'
| '\u{1BCA0}'..='\u{1BCA3}'
| '\u{1D173}'..='\u{1D17A}'
| '\u{E0000}'..='\u{E0FFF}'
)
}
/// Parses a plug-in's objects: `{"objects": [...]}`, or `{"error": "message"}` when the plug-in