mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-15 18:30:42 -06:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
988d721d7d | ||
|
|
1af57126a0 | ||
|
|
b0c532d2d1 | ||
|
|
3bad02d1f1 | ||
|
|
1ff3b87f5a | ||
|
|
9f7d1c426f | ||
|
|
a4674dbd1c | ||
|
|
04907481c1 | ||
|
|
3c60448691 | ||
|
|
772219838e | ||
|
|
e86c25af9c | ||
|
|
10fef35fe6 |
Generated
+10
@@ -986,6 +986,15 @@ dependencies = [
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10#ea24422ae9859dc5da398d0462bc87f8e02e0d10"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.2"
|
||||
@@ -1219,6 +1228,7 @@ dependencies = [
|
||||
name = "deckcraft-pptx"
|
||||
version = "0.19.0"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"deckcraft-color",
|
||||
"deckcraft-engine",
|
||||
"deckcraft-geom",
|
||||
|
||||
@@ -11,6 +11,8 @@ rust-version = "1.95"
|
||||
repository = "https://github.com/storytold/deckcraft"
|
||||
|
||||
[workspace.dependencies]
|
||||
# XML writer primitives; parser admission and OOXML policy stay app-local.
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9859dc5da398d0462bc87f8e02e0d10", version = "0.1.0" }
|
||||
# internal
|
||||
deckcraft-geom = { path = "crates/geom" }
|
||||
deckcraft-color = { path = "crates/color" }
|
||||
|
||||
@@ -628,6 +628,7 @@ pub fn base64_decode(s: &str) -> Option<Vec<u8>> {
|
||||
let mut out = Vec::with_capacity(s.len() / 4 * 3);
|
||||
let mut acc = 0u32;
|
||||
let mut bits = 0;
|
||||
let mut padded = false;
|
||||
for c in s.bytes() {
|
||||
let v = match c {
|
||||
b'A'..=b'Z' => c - b'A',
|
||||
@@ -635,9 +636,17 @@ pub fn base64_decode(s: &str) -> Option<Vec<u8>> {
|
||||
b'0'..=b'9' => c - b'0' + 52,
|
||||
b'+' | b'-' => 62,
|
||||
b'/' | b'_' => 63,
|
||||
b'=' | b'\n' | b'\r' | b' ' => continue,
|
||||
b'=' => {
|
||||
padded = true;
|
||||
continue;
|
||||
}
|
||||
b'\n' | b'\r' | b' ' => continue,
|
||||
_ => return None,
|
||||
} as u32;
|
||||
// Padding ends the payload; no further data may be decoded.
|
||||
if padded {
|
||||
return None;
|
||||
}
|
||||
acc = (acc << 6) | v;
|
||||
bits += 6;
|
||||
if bits >= 8 {
|
||||
@@ -645,13 +654,42 @@ pub fn base64_decode(s: &str) -> Option<Vec<u8>> {
|
||||
out.push(((acc >> bits) & 0xff) as u8);
|
||||
}
|
||||
}
|
||||
Some(out)
|
||||
// A trailing lone Base64 character cannot encode another byte.
|
||||
(bits != 6).then_some(out)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn base64_rejects_a_single_character_tail() {
|
||||
for (encoded, decoded) in [
|
||||
("", b"".as_slice()),
|
||||
("Zg==", b"f"),
|
||||
("Zg", b"f"),
|
||||
("Zm8=", b"fo"),
|
||||
("Zm8", b"fo"),
|
||||
(" Zm9v \r\n", b"foo"),
|
||||
("data:text/plain;base64,Zm9v", b"foo"),
|
||||
("+/8=", &[0xfb, 0xff]),
|
||||
("-_8=", &[0xfb, 0xff]),
|
||||
] {
|
||||
assert_eq!(base64_decode(encoded).as_deref(), Some(decoded), "{encoded:?}");
|
||||
}
|
||||
for encoded in ["A", "AAAAA", "Zm9vZ", " Zm9vZ \r\n", "data:text/plain;base64,Z"] {
|
||||
assert!(base64_decode(encoded).is_none(), "{encoded:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn base64_rejects_data_after_padding() {
|
||||
assert_eq!(base64_decode("Zg== \r\n=="), Some(b"f".to_vec()));
|
||||
for encoded in ["Zg==A", "Zg== Zm8=", "Zm8=A", "=Zg", "Zg==\r\nA", "data:text/plain;base64,Zg==A"] {
|
||||
assert!(base64_decode(encoded).is_none(), "{encoded:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_palette_skips_a_command_that_needs_a_value() {
|
||||
assert!(needs_arguments("{path}"));
|
||||
|
||||
@@ -276,6 +276,9 @@ impl Outline<'_> {
|
||||
while k > 0 && self.i < self.b.len() {
|
||||
if self.b[self.i] == b'\\' && self.b.get(self.i + 1) == Some(&b'\'') {
|
||||
self.i = advance(self.rtf, self.i, 4);
|
||||
} else if self.b[self.i] == b'\\' && self.b.get(self.i + 1).is_some_and(|b| !b.is_ascii_alphabetic()) {
|
||||
// An escaped control symbol counts as one Unicode fallback character.
|
||||
self.i = advance(self.rtf, self.i + 1, 1);
|
||||
} else if matches!(self.b[self.i], b'{' | b'}' | b'\\') {
|
||||
break;
|
||||
} else {
|
||||
@@ -422,6 +425,23 @@ mod tests {
|
||||
assert_eq!(rtf_to_outline(r"{\rtf1 x\u-70000?y\par}"), "x\u{ee90}y\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unicode_fallback_control_symbols_are_skipped() {
|
||||
for (rtf, expected) in [
|
||||
(r"{\rtf1\uc1 \u92\\X\par}", "\\X\n"),
|
||||
(r"{\rtf1\uc1 \u123\{X\par}", "{X\n"),
|
||||
(r"{\rtf1\uc1 \u125\}X\par}", "}X\n"),
|
||||
(r"{\rtf1\uc2 \u233\{\}X\par}", "éX\n"),
|
||||
(r"{\rtf1\uc0 \u92\\X\par}", "\\\\X\n"),
|
||||
(r"{\rtf1 \\ \{ \}X\par}", "\\ { }X\n"),
|
||||
(r"{\rtf1\uc1 \u233{X}\par}", "éX\n"),
|
||||
(r"{\rtf1\uc1 \u233\éX\par}", "éX\n"),
|
||||
(r"{\rtf1\uc1 \u233\", "é\n"),
|
||||
] {
|
||||
assert_eq!(rtf_to_outline(rtf), expected, "{rtf:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multibyte_control_symbol_keeps_character_and_following_text() {
|
||||
assert_eq!(rtf_to_outline("{\\rtf1 A\\éB\\par}"), "AéB\n");
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
/// Cyrillic, CJK…) give `false`. Neutral, weak, and whitespace characters are skipped.
|
||||
pub fn first_strong_is_rtl(text: &str) -> bool {
|
||||
for c in text.chars() {
|
||||
if c == '\u{200F}' {
|
||||
// Right-to-Left Mark (RLM)
|
||||
if c == '\u{200F}' || c == '\u{061C}' {
|
||||
// RLM and ALM are strong RTL controls, although neither is alphabetic.
|
||||
return true;
|
||||
}
|
||||
if c == '\u{200E}' {
|
||||
@@ -76,6 +76,10 @@ mod tests {
|
||||
#[test]
|
||||
fn honours_directional_marks() {
|
||||
assert!(first_strong_is_rtl("\u{200F}Hello"));
|
||||
assert!(first_strong_is_rtl("\u{061C}Hello"));
|
||||
assert!(first_strong_is_rtl("\u{061C}"));
|
||||
assert!(!first_strong_is_rtl("Hello\u{061C}"));
|
||||
assert!(!first_strong_is_rtl("\u{200E}\u{061C}"));
|
||||
assert!(!first_strong_is_rtl("\u{200E}مرحبا"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,6 +528,12 @@ pub fn change_case(s: &str, mode: &str) -> String {
|
||||
/// `title` and `sentence` carry their word/sentence state across piece boundaries. Each output
|
||||
/// piece is the changed form of the matching input piece, even where a character changes length.
|
||||
pub fn change_case_parts(parts: &[&str], mode: &str) -> Vec<String> {
|
||||
if mode == "lower" {
|
||||
let lower = parts.concat().to_lowercase();
|
||||
let mut chars = lower.chars();
|
||||
// Context changes sigma's form, while each character's expansion length stays the same.
|
||||
return parts.iter().map(|s| chars.by_ref().take(s.chars().map(|c| c.to_lowercase().count()).sum()).collect()).collect();
|
||||
}
|
||||
let mut start = true;
|
||||
// All characters of all pieces, so word-final sigma sees neighbours across piece boundaries.
|
||||
let all: Vec<char> = parts.iter().flat_map(|s| s.chars()).collect();
|
||||
@@ -536,7 +542,6 @@ pub fn change_case_parts(parts: &[&str], mode: &str) -> Vec<String> {
|
||||
.iter()
|
||||
.map(|s| match mode {
|
||||
"upper" => s.to_uppercase(),
|
||||
"lower" => s.to_lowercase(),
|
||||
"toggle" => s.chars().map(|c| if c.is_uppercase() { c.to_lowercase().collect::<String>() } else { c.to_uppercase().collect() }).collect(),
|
||||
_ => {
|
||||
// `title` restarts after whitespace, sentence case after sentence punctuation.
|
||||
@@ -593,6 +598,18 @@ mod tests {
|
||||
assert_eq!(change_case_parts(&["ΟΔΟΣ", " ΜΟΥ"], "title"), ["Οδος", " Μου"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lowercase_keeps_context_and_run_boundaries() {
|
||||
assert_eq!(change_case_parts(&["ΟΔΟ", "Σ"], "lower"), ["οδο", "ς"]);
|
||||
assert_eq!(change_case_parts(&["ΟΣ", "Α"], "lower"), ["οσ", "α"]);
|
||||
assert_eq!(change_case_parts(&["", "ΟΔΟ", "", "Σ", ""], "lower"), ["", "οδο", "", "ς", ""]);
|
||||
assert_eq!(change_case_parts(&["İΟΔΟ", "Σ"], "lower"), ["i\u{307}οδο", "ς"]);
|
||||
assert_eq!(change_case_parts(&["Ο", "\u{301}", "Σ"], "lower"), ["ο", "\u{301}", "ς"]);
|
||||
assert_eq!(change_case_parts(&["ΟΣ", "\u{301}", "Α"], "lower"), ["οσ", "\u{301}", "α"]);
|
||||
assert_eq!(change_case_parts(&["", "", ""], "lower"), ["", "", ""]);
|
||||
assert!(change_case_parts(&[], "lower").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_and_split() {
|
||||
let mut b = body("Hello");
|
||||
|
||||
@@ -234,16 +234,18 @@ fn sci(toks: &[Tok], v: f64, sep: char, dec: char) -> Option<String> {
|
||||
m *= 10.0;
|
||||
exp -= 1;
|
||||
}
|
||||
// Rounding the mantissa to its digits can reach 10 (9.999 as `0.00`).
|
||||
if format!("{m:.mant_frac$}").starts_with("10") {
|
||||
m /= 10.0;
|
||||
exp += 1;
|
||||
}
|
||||
}
|
||||
let step = mant.iter().take_while(|t| **t != Tok::Dot).filter(|t| matches!(t, Tok::Digit(_))).count().max(1) as i32;
|
||||
let shift = exp.rem_euclid(step);
|
||||
exp -= shift;
|
||||
m *= 10f64.powi(shift);
|
||||
// Round after forming the engineering mantissa: 999.94 as `##0.0` stays 999.9.
|
||||
// Carry only when rounding exceeds all of the format's integer placeholders.
|
||||
let carry = 10f64.powi(step);
|
||||
if format!("{m:.mant_frac$}").parse::<f64>().is_ok_and(|rounded| rounded >= carry) {
|
||||
m /= carry;
|
||||
exp += step;
|
||||
}
|
||||
let mantissa = fixed(mant, mfirst, mlast, m, sep, dec);
|
||||
let sign = if exp < 0 {
|
||||
"-"
|
||||
@@ -404,6 +406,21 @@ mod tests {
|
||||
assert_eq!(format("##0.0E+0", 999.96, None), "1.0E+3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn engineering_formats_round_the_full_mantissa() {
|
||||
for (code, value, expected) in [
|
||||
("##0.0E+00", 999.94, "999.9E+00"),
|
||||
("##0.0E+00", 0.99994, "999.9E-03"),
|
||||
("##0.0E+00", -999.94, "-999.9E+00"),
|
||||
("#0.0E+00", 99.94, "99.9E+00"),
|
||||
("##0.0E+00", 999.96, "1.0E+03"),
|
||||
("#0.0E+00", 99.96, "1.0E+02"),
|
||||
] {
|
||||
assert_eq!(format(code, value, None), expected, "{code}, {value}");
|
||||
}
|
||||
assert_eq!(format("##0.0E+00", 999.94, Some("de-DE")), "999,9E+00");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn never_panics() {
|
||||
for code in ["", ";", ";;;", "\"", "[", "\\", "0.", ".", "#,", "%", "_", "*", "@", "0E+00", "[$", "\"unterminated"] {
|
||||
|
||||
@@ -9,6 +9,7 @@ description = "DeckCraft PPTX: Office Open XML (PresentationML/DrawingML) import
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-xml.workspace = true
|
||||
deckcraft-model = { workspace = true }
|
||||
deckcraft-geom = { workspace = true }
|
||||
deckcraft-color = { workspace = true }
|
||||
|
||||
+33
-39
@@ -354,45 +354,8 @@ fn decode_utf16(bytes: &[u8]) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Is `c` allowed in XML 1.0 text?
|
||||
fn xml_char(c: char) -> bool {
|
||||
matches!(c, '\t' | '\n' | '\r') || (c >= ' ' && c != '\u{FFFE}' && c != '\u{FFFF}')
|
||||
}
|
||||
|
||||
/// Escape text content (and drop characters XML 1.0 forbids).
|
||||
pub fn esc(s: &str) -> String {
|
||||
let mut o = String::with_capacity(s.len());
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
'&' => o.push_str("&"),
|
||||
'<' => o.push_str("<"),
|
||||
'>' => o.push_str(">"),
|
||||
'\r' => o.push_str(" "),
|
||||
c if xml_char(c) => o.push(c),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
o
|
||||
}
|
||||
|
||||
/// Escape an attribute value.
|
||||
pub fn esc_attr(s: &str) -> String {
|
||||
let mut o = String::with_capacity(s.len());
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
'&' => o.push_str("&"),
|
||||
'<' => o.push_str("<"),
|
||||
'>' => o.push_str(">"),
|
||||
'"' => o.push_str("""),
|
||||
'\n' => o.push_str(" "),
|
||||
'\r' => o.push_str(" "),
|
||||
'\t' => o.push_str("	"),
|
||||
c if xml_char(c) => o.push(c),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
o
|
||||
}
|
||||
// Preserve the public writer helpers while sharing the XML 1.0 escaping rules.
|
||||
pub use craft_xml::{esc, esc_attr};
|
||||
|
||||
/// A string builder for XML parts.
|
||||
#[derive(Default)]
|
||||
@@ -542,6 +505,37 @@ mod tests {
|
||||
assert_eq!(esc_attr("\"x\"\n"), ""x" ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_escaping_preserves_xml_wire_bytes() {
|
||||
let text = "&<>\"'\t\n\r\0\u{b}\u{fffe}\u{ffff}é😀 ";
|
||||
assert_eq!(esc(text), "&<>\"'\t\n é😀&#13;");
|
||||
assert_eq!(esc_attr(text), "&<>"'	 é😀&#13;");
|
||||
assert_eq!(esc(""), "");
|
||||
assert_eq!(esc_attr(""), "");
|
||||
for code in 0..32 {
|
||||
let c = char::from_u32(code).unwrap();
|
||||
let text = c.to_string();
|
||||
match c {
|
||||
'\t' => {
|
||||
assert_eq!(esc(&text), "\t");
|
||||
assert_eq!(esc_attr(&text), "	");
|
||||
}
|
||||
'\n' => {
|
||||
assert_eq!(esc(&text), "\n");
|
||||
assert_eq!(esc_attr(&text), " ");
|
||||
}
|
||||
'\r' => {
|
||||
assert_eq!(esc(&text), " ");
|
||||
assert_eq!(esc_attr(&text), " ");
|
||||
}
|
||||
_ => {
|
||||
assert_eq!(esc(&text), "");
|
||||
assert_eq!(esc_attr(&text), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roundtrip_serialize() {
|
||||
let d = parse(b"<p:sp a=\"1\"><p:t>x & y</p:t><e/></p:sp>").unwrap();
|
||||
|
||||
@@ -32,16 +32,11 @@ Coordinates are slide points (1/72 inch; a 16:9 slide is 960 × 540) unless note
|
||||
| `engine.execute` / `ui.menu.invoke` / `command` | `{command, params}` | Run any command (see `engine.commands`; `deckcraft-cli describe COMMAND` documents one) |
|
||||
| `engine.commands` | — | Every command: id, label, menu path, shortcut, params doc, enabled / disabled reason |
|
||||
| `document.inspect` | — | Slides, sections, layouts, shapes, selection |
|
||||
| `slide.actions` | `{index?}` | Actions on one slide; returns `{index, slideId, actions}`. Each action has an `owner` (shape id/name and group path; text actions also include paragraph/run indexes and run text, plus table row/cell indexes for table text), `event` (`click`, `hover`, `textLink`, or `textHover`), action `type`, `target`, and the full `hyperlink`. Listing is read-only and never executes an action. An empty slide returns `"actions": []`. |
|
||||
| `ui.inspect` | — | UI state, active tool, window/canvas/slide rects, dialog, `home` (the File tab open over a presentation), `backstage` (its page, also the start screen), slide show state (`grid`, `zoomArm`, `zoom`, `blank`, `presenterPaused`, `presenterSecs`, `notesPx`, `custom`, `goto`; `cells` while See All Slides is open), documents, perf (fps, render ms) |
|
||||
| `ui.inspect` | — | UI state, active tool, window/canvas/slide rects, dialog, `home` (the File tab open over a presentation), `backstage` (its page, also the start screen), slide show state, `animPreview` (canvas playback: slide, time, duration), documents, perf (fps, render ms) |
|
||||
| `ui.inspect` | — | UI state, active tool, window/canvas/slide rects, dialog, `home` (the File tab over an open presentation), `backstage` (the current File page, including the start screen), slide show state (`grid`, `zoomArm`, `zoom`, `blank`, `presenterPaused`, `presenterSecs`, `notesPx`, `custom`, `goto`; `cells` when See All Slides is open), `animPreview` (canvas playback: slide, time, duration), documents, perf (fps, render ms) |
|
||||
| `ui.tool.select` | `{tool, preset?}` | `select`, `text`, `shape` + preset, any preset name, `curve`, `freeform`, `scribble`, `pen`, `highlighter`, `eraser` |
|
||||
| `ui.pointer` | `{events: [{kind: down\|drag\|up\|move\|doubleclick\|tripleclick\|contextclick, x, y, mods?}], mods?}` | Drive the active tool in slide points through the same code path as the mouse (`contextclick`: the right-button press that selects before the context menu) |
|
||||
| `ui.key` / `ui.text` | `{key, shift?, alt?, cmd?}` / `{text}` | Keyboard input (also drives a running slide show: digits then Enter go to that slide, G is See All Slides, Z arms zoom, T pauses the presenter timer, R resets it, `[` and `]` change notes size, Esc clears a slide number, the grid and zoom before it leaves the show) |
|
||||
| `ui.pointer` | `{events: [{kind: down\|drag\|up\|move\|doubleclick\|tripleclick, x, y, mods?}], mods?}` | Drive the active tool in slide points through the same code path as the mouse |
|
||||
| `ui.key` / `ui.text` | `{key, shift?, alt?, cmd?}` / `{text}` | Keyboard input (also drives a running slide show; Escape stops the canvas animation preview) |
|
||||
| `ui.pointer` | `{events: [{kind: down\|drag\|up\|move\|doubleclick\|tripleclick, x, y, mods?, pressure?}], mods?}` | Drive the active tool in slide points through the same code path as the mouse. `pressure` is `0..=1` for a pen; omit it for a mouse |
|
||||
| `ui.key` / `ui.text` | `{key, shift?, alt?, cmd?}` / `{text}` | Keyboard input (also drives a running slide show) |
|
||||
| `ui.pointer` | `{events: [{kind: down\|drag\|up\|move\|doubleclick\|tripleclick\|contextclick, x, y, mods?, pressure?}], mods?}` | Send slide-point pointer events through the active tool's mouse path. `contextclick` performs the right-click selection used by context menus; `pressure` is `0..=1` for a pen and can be omitted for a mouse |
|
||||
| `ui.key` | `{key, shift?, alt?, cmd?}` | Send a key press. During an active slide show, digits followed by Enter jump to that slide; G opens See All Slides, Z arms zoom, T toggles the presenter timer's pause, R resets it, and `[` / `]` resize notes. Esc clears a typed slide number or backs out of the grid/zoom before ending the active show. Close See All Slides with Esc or G before using the other listed show shortcuts. Slide-show keys ignore modifier flags; use `show.end` to leave the end-of-show screen. Outside a show, Escape stops canvas animation preview |
|
||||
| `ui.text` | `{text}` | Insert into the current text edit. With one shape selected and no active text edit, begin editing and replace the shape's existing text |
|
||||
| `ui.ime` | `{preedit, active?: [start, end]}` / `{commit}` | An input method's composition through egui, as a real one arrives: shown in place on the slide or in a focused field; `{"preedit": ""}` cancels |
|
||||
| `ui.move` / `ui.click` / `ui.drag` | screen points | Real egui pointer input — reaches every widget, menu and pane |
|
||||
| `ui.set` | `{tab?, view?, pane?, notes?, zoom?, brightness?, ruler?, gridlines?, guides?, …}` | UI state (returns the full state) |
|
||||
@@ -54,3 +49,18 @@ Coordinates are slide points (1/72 inch; a 16:9 slide is 960 × 540) unless note
|
||||
|
||||
The MCP server (`deckcraft-cli mcp`, see [mcp.md](mcp.md)) wraps the same methods for Claude
|
||||
and other agents; `deckcraft-cli app --method METHOD [PARAMS]` sends one request from a shell.
|
||||
|
||||
## Inspecting slide actions
|
||||
|
||||
Run the `slide.actions` engine command through `engine.execute`:
|
||||
|
||||
```json
|
||||
{"id": 2, "method": "engine.execute", "params": {"command": "slide.actions", "params": {"index": 0}}}
|
||||
```
|
||||
|
||||
`index` is zero-based and optional; omitting it inspects the selected slide. The reply's `result`
|
||||
contains `{index, slideId, actions}`. Each action includes an `owner` with the shape id/name and
|
||||
its group path; text actions also identify the paragraph/run and run text, plus the table row/cell
|
||||
for table text. Actions report their `event` (`click`, `hover`, `textLink`, or `textHover`),
|
||||
`type`, `target`, and full `hyperlink`. Inspection never runs an action. A slide without actions
|
||||
returns `"actions": []`.
|
||||
|
||||
+24
-3
@@ -45,11 +45,20 @@ pub fn validate(v: &str) -> Result<(), String> {
|
||||
None => (v, None),
|
||||
};
|
||||
let nums: Vec<&str> = core.split('.').collect();
|
||||
if nums.len() != 3 || nums.iter().any(|n| n.is_empty() || !n.bytes().all(|b| b.is_ascii_digit()) || (n.len() > 1 && n.starts_with('0'))) {
|
||||
if nums.len() != 3
|
||||
|| nums
|
||||
.iter()
|
||||
.any(|n| n.is_empty() || !n.bytes().all(|b| b.is_ascii_digit()) || n.parse::<u64>().is_err() || (n.len() > 1 && n.starts_with('0')))
|
||||
{
|
||||
return bad();
|
||||
}
|
||||
if let Some(p) = pre
|
||||
&& (p.is_empty() || p.split('.').any(|id| id.is_empty() || !id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-')))
|
||||
&& (p.is_empty()
|
||||
|| p.split('.').any(|id| {
|
||||
id.is_empty()
|
||||
|| !id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-')
|
||||
|| (id.len() > 1 && id.starts_with('0') && id.bytes().all(|b| b.is_ascii_digit()))
|
||||
}))
|
||||
{
|
||||
return bad();
|
||||
}
|
||||
@@ -138,12 +147,24 @@ mod tests {
|
||||
for ok in ["0.1.0", "1.20.300", "1.0.0-rc.1", "1.0.0-alpha", "1.0.0-x-y.2"] {
|
||||
assert!(validate(ok).is_ok(), "{ok}");
|
||||
}
|
||||
for bad in ["1.0", "1.0.0.0", "v1.0.0", "01.0.0", "1.0.0-", "1.0.0-a..b", "1.0.0+meta", "1.a.0", ""] {
|
||||
for bad in ["1.0", "1.0.0.0", "v1.0.0", "01.0.0", "1.0.0-", "1.0.0-a..b", "1.0.0+meta", "1.a.0", "18446744073709551616.0.0", ""] {
|
||||
assert!(validate(bad).is_err(), "{bad}");
|
||||
}
|
||||
assert!(replace(MANIFEST, "nope").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numeric_prerelease_identifiers_have_no_leading_zeroes() {
|
||||
for bad in ["1.0.0-00", "1.0.0-01", "1.0.0-rc.01"] {
|
||||
assert!(validate(bad).is_err(), "{bad}");
|
||||
assert!(replace(MANIFEST, bad).is_err(), "{bad} must not reach the manifest");
|
||||
}
|
||||
for ok in ["1.0.0-0", "1.0.0-rc.0", "1.0.0-01a", "1.0.0-0-1"] {
|
||||
assert!(validate(ok).is_ok(), "{ok}");
|
||||
assert_eq!(read(&replace(MANIFEST, ok).unwrap()).unwrap(), ok);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_real_manifest_has_a_valid_version() {
|
||||
let text = std::fs::read_to_string(crate::root().join("Cargo.toml")).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user