Skip to content

TsukiNi22/ai-utils / skills/ai/presentation

presentation

Verified

Make a presentation from a plan or an idea - a time (given, or estimated and confirmed) sets the number of slides; the format (PDF, one-file animated HTML, PPTX, several or all) and the style (several proposals for the subject, "White blueprint" by default, or copied from a PPTX / PDF / HTML the user gives) are asked through interactive-questions. One deck.json gives every format plus speaker notes. Use for "fais une présentation / des slides / un ppt / un pdf de présentation".

FileKindSize
SKILL.mdskill md16.0 KB
requires.txtmarkdown22 B
scripts/build_deck.pyexecutablescript35.8 KB
scripts/check_deck.pyexecutablescript13.2 KB
scripts/extract_style.pyexecutablescript7.6 KB
templates/canva.jsonconfig527 B
templates/custom-example/theme.cssother1.8 KB
templates/custom-example/theme.jsonconfig808 B
templates/deck-base.cssother2.1 KB
templates/deck.jsscript16.0 KB
templates/example.jsonconfig3.8 KB
templates/slides.cssother12.5 KB
templates/themes.jsonconfig4.7 KB

scripts/check_deck.py

View on GitHub
#!/usr/bin/env python3
"""Check a presentation: the model, then each built file, and write contact sheets to LOOK at.

    python3 check_deck.py deck.json [--dir OUTDIR] [--sheets SHEETDIR] [--canva]

- deck.json: slides per minute (the pace), points per slide, words per slide, missing notes / titles / images.
- <name>.pdf: pages = slides, then a contact sheet PNG (pdftoppm + Pillow) of every page.
- <name>.pptx: rendered to PDF with LibreOffice (soffice) when installed, then a contact sheet too.
- <name>.html: the built-in selftest of the web page (?selftest) in headless Firefox: a screenshot with
  "SELFTEST OK/FAIL" (text out of the slide, hidden by the bar, clipped, keys), to be read.
Exit 1 when the model has an error. The sheets are images: open them (Read) and look; no tool sees a bad layout for you.
"""
import argparse
import json
import re
import shutil
import subprocess
import sys
import tempfile
import unicodedata
from pathlib import Path

PER_MINUTE = (0.5, 1.0)  # content slides per minute: below = slow, above = rushed
MAX_POINTS, MAX_WORDS = 6, 60

def slug(text: str) -> str:
    """The file name build_deck.py gives the outputs (same rule: accents dropped, then non letters as '-')."""
    ascii_text = unicodedata.normalize("NFKD", text).encode("ascii", "ignore").decode("ascii")
    return re.sub(r"[^a-z0-9]+", "-", ascii_text.lower()).strip("-") or "deck"

def words(slide: dict) -> int:
    text = json.dumps({k: v for k, v in slide.items() if k not in ("notes", "svg", "kind", "chapter", "bg")}, ensure_ascii=False)
    return len(re.findall(r"[\w'-]+", re.sub(r'"[a-z_]+":', " ", text)))

def lint(deck: dict, base: Path) -> int:
    errors = 0
    slides = deck["slides"]
    content = [s for s in slides if s["kind"] not in ("title", "section", "end")]
    print(f"slides: {len(slides)} ({len(content)} of content)")
    minutes = deck.get("duration")
    if minutes:
        rate = len(content) / minutes
        verdict = "ok" if PER_MINUTE[0] <= rate <= PER_MINUTE[1] else ("too few slides for the time" if rate < PER_MINUTE[0] else "too many slides for the time")
        print(f"pace: {len(content)} content slides in {minutes} min = {rate:.2f} per minute -> {verdict}")
    for number, slide in enumerate(slides, 1):
        where = f"slide {number} ({slide['kind']} {slide.get('title', '')[:30]!r})"
        count = len(slide.get("points", [])) + len(slide.get("columns", [])) + len(slide.get("steps", []))
        if count > MAX_POINTS:
            print(f"WARN {where}: {count} points, split it")
        if words(slide) > MAX_WORDS and slide["kind"] in ("bullets", "columns", "steps"):
            print(f"WARN {where}: {words(slide)} words, move the detail to the notes")
        if slide["kind"] not in ("title", "section", "end", "quote") and not slide.get("notes"):
            print(f"WARN {where}: no notes (what is said aloud)")
        svg = slide.get("svg", "")
        if re.search(r"<text\b[^>]*\sopacity=", svg):
            print(f"WARN {where}: opacity on an SVG <text>: the PDF engine cuts or shifts the text, give it a dim fill instead")
        if re.search(r"<[a-zA-Z][^<>]*\sstyle=\"[^\"]*\"[^<>]*\sstyle=", svg):
            print(f"WARN {where}: two style attributes on one SVG tag (build_deck merges them, merge them in deck.json)")
        if slide["kind"] in ("image", "end") and slide.get("src") and not (base / slide["src"]).is_file():
            print(f"ERROR {where}: image {slide['src']} not found")
            errors += 1
    return errors

def squash(text: str) -> str:
    return re.sub(r"[^\w]+", "", re.sub(r"\*\*|`", "", text)).lower()

def strings_of(slide: dict) -> list[str]:
    """Every visible string of a slide (what must be found again in the built files)."""
    found: list[str] = []

    def walk(value: object) -> None:
        if isinstance(value, str):
            found.append(value)
        elif isinstance(value, list):
            for item in value:
                walk(item)
        elif isinstance(value, dict):
            for key, item in value.items():
                if key not in ("notes", "svg", "kind", "chapter", "src", "alt", "lang"):
                    walk(item)

    walk({k: v for k, v in slide.items() if k != "notes"})
    return [t for t in found if squash(t)]

def canva_pdf(deck: dict, pdf: Path, allowed: list[str]) -> int:
    """What a PDF import (Canva) needs: real text on each page, every font embedded and in its library, no font made of
    shapes, a page not flattened to a picture. Returns the number of errors."""
    errors = 0
    rows = subprocess.run(["pdffonts", str(pdf)], capture_output=True, text=True, check=True).stdout.splitlines()[2:]
    families = set()
    for row in rows:
        parts = row.split()
        name = re.sub(r"^[A-Z]{6}\+", "", parts[0])
        family = re.sub(r"-(Bold|Italic|Regular|Medium|Light|Semi\w*|Extra\w*|Condensed)+.*$", "", name).replace("-", " ")
        families.add(family)
        if "Type 3" in row:
            print(f"ERROR canva pdf: font {name} is Type 3 (letters drawn as shapes: Canva imports them as pictures)")
            errors += 1
        if parts[-5] == "no":  # the "emb" column
            print(f"ERROR canva pdf: font {name} not embedded (Canva replaces it)")
            errors += 1
    for family in sorted(families):
        if family not in allowed:
            print(f"WARN canva pdf: font {family!r} is not in canva.json (replaced by Canva on import, the lines may change)")
    print(f"canva pdf: {len(rows)} font faces, families {sorted(families)}")
    pages = subprocess.run(["pdftotext", str(pdf), "-"], capture_output=True, text=True, check=True).stdout.split("\f")
    images = subprocess.run(["pdfimages", "-list", str(pdf)], capture_output=True, text=True, check=False).stdout.splitlines()[2:]
    per_page = {}
    for row in images:
        per_page[int(row.split()[0])] = per_page.get(int(row.split()[0]), 0) + 1
    for number, slide in enumerate(deck["slides"], 1):
        page = squash(pages[number - 1]) if number <= len(pages) else ""
        missing = [t for t in strings_of(slide) if squash(t) not in page]
        if missing:
            print(f"ERROR canva pdf: page {number} misses text {missing[0][:50]!r}" + (f" (+{len(missing) - 1})" if len(missing) > 1 else "") + " (not real text, or cut in pieces)")
            errors += 1
        if slide["kind"] not in ("image", "end") and per_page.get(number):
            print(f"WARN canva pdf: page {number} holds {per_page[number]} picture(s) (a background or text turned into an image)")
    return errors

def canva_pptx(deck: dict, pptx: Path, allowed: list[str]) -> int:
    """What a PPTX import needs: every text in a Canva font, no group / placeholder / empty box, no shrink-on-overflow,
    the text of each slide present in its shapes."""
    try:
        from pptx import Presentation
        from pptx.enum.shapes import MSO_SHAPE_TYPE
        from pptx.enum.text import MSO_AUTO_SIZE
    except ImportError:
        print("SKIP canva pptx: python-pptx not installed")
        return 0
    errors = 0
    fonts: set[str] = set()
    for number, (spec, slide) in enumerate(zip(deck["slides"], Presentation(str(pptx)).slides), 1):
        have, body = "", ""
        for shape in slide.shapes:
            if shape.shape_type == MSO_SHAPE_TYPE.GROUP:
                print(f"ERROR canva pptx: slide {number} has a group (Canva imports it as one flat picture)")
                errors += 1
            if shape.is_placeholder:
                print(f"WARN canva pptx: slide {number} has a placeholder ({shape.name})")
            frames = []
            if shape.has_text_frame:
                frames.append(shape.text_frame)
            if getattr(shape, "has_table", False) and shape.has_table:
                frames += [cell.text_frame for row in shape.table.rows for cell in row.cells]
            for frame in frames:
                if shape.has_text_frame and frame.auto_size not in (None, MSO_AUTO_SIZE.NONE):
                    print(f"WARN canva pptx: slide {number} {shape.name}: auto-fit is on (the size Canva reads differs)")
                for paragraph in frame.paragraphs:
                    for run in paragraph.runs:
                        body += run.text
                        if run.font.name:
                            fonts.add(run.font.name)
                        else:
                            print(f"WARN canva pptx: slide {number}: a text run without a font name (Canva takes its default)")
        have = squash(body)
        missing = [t for t in strings_of(spec) if squash(t) not in have and spec["kind"] != "svg"]
        if missing:
            print(f"ERROR canva pptx: slide {number} misses text {missing[0][:50]!r}")
            errors += 1
    for family in sorted(fonts - set(allowed)):
        print(f"WARN canva pptx: font {family!r} is not in canva.json (replaced by Canva on import)")
    print(f"canva pptx: fonts {sorted(fonts)}")
    return errors

def sheet(pdf: Path, out: Path) -> None:
    from PIL import Image
    with tempfile.TemporaryDirectory() as tmp:
        subprocess.run(["pdftoppm", "-r", "30", "-png", str(pdf), f"{tmp}/p"], check=True)
        pages = [Image.open(f) for f in sorted(Path(tmp).glob("p-*.png"))]
        if not pages:
            print(f"ERROR no page in {pdf}")
            return
        w, h = pages[0].size
        cols = 3
        rows = (len(pages) + cols - 1) // cols
        canvas = Image.new("RGB", (cols * (w + 6) + 6, rows * (h + 6) + 6), "#888888")
        for i, page in enumerate(pages):
            canvas.paste(page.convert("RGB"), (6 + (i % cols) * (w + 6), 6 + (i // cols) * (h + 6)))
        canvas.save(out)
        print(f"sheet: {out} ({len(pages)} pages)")

def selftest(page: Path, out: Path) -> None:
    firefox = shutil.which("firefox")
    if not firefox:
        print("SKIP selftest: firefox not installed")
        return
    with tempfile.TemporaryDirectory() as profile:
        subprocess.run(["timeout", "90", firefox, "--headless", "--no-remote", "--profile", profile, "--window-size", "1280,720",
                        "--screenshot", str(out), f"file://{page}?selftest"], capture_output=True, check=False)
    print(f"selftest screenshot: {out} (read the first line: SELFTEST OK or FAIL and the list)" if out.exists() else "ERROR selftest screenshot not written")

def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument("deck")
    parser.add_argument("--dir", default=None, help="folder of the built files (default: next to deck.json)")
    parser.add_argument("--canva", action="store_true", help="also check the PDF / PPTX for an import into Canva (text kept, fonts embedded and in its library)")
    parser.add_argument("--sheets", default=None, help="folder of the PNG sheets (default: the same folder)")
    args = parser.parse_args()
    source = Path(args.deck).expanduser().resolve()
    if not source.is_file():
        sys.exit(f"check_deck: {args.deck!r} not found")
    try:
        deck = json.loads(source.read_text(encoding="utf-8"))
    except json.JSONDecodeError as error:
        sys.exit(f"check_deck: {source.name}: not valid JSON ({error})")
    if not isinstance(deck, dict) or not isinstance(deck.get("slides"), list) or not all(isinstance(s, dict) and s.get("kind") for s in deck["slides"]):
        sys.exit(f"check_deck: {source.name} needs a 'slides' list of objects with a 'kind' (build_deck.py says what is wrong)")
    folder = Path(args.dir).resolve() if args.dir else source.parent
    sheets = Path(args.sheets).resolve() if args.sheets else folder
    sheets.mkdir(parents=True, exist_ok=True)
    errors = lint(deck, source.parent)
    allowed = json.loads((Path(__file__).resolve().parent.parent / "templates" / "canva.json").read_text(encoding="utf-8"))["fonts"]
    stem = slug(re.sub(r"\*\*|`", "", deck.get("title", "deck")))
    pdf, pptx, page = folder / f"{stem}.pdf", folder / f"{stem}.pptx", folder / f"{stem}.html"
    if not any(f.exists() for f in (pdf, pptx, page)):
        print(f"WARN no {stem}.pdf / .pptx / .html in {folder}: nothing built there to check (build_deck.py first, same -o)")
    if pdf.exists():
        pages = int(re.search(r"Pages:\s+(\d+)", subprocess.run(["pdfinfo", str(pdf)], capture_output=True, text=True, check=True).stdout).group(1))
        print(f"pdf: {pages} pages" + ("" if pages == len(deck["slides"]) else f" ERROR expected {len(deck['slides'])}"))
        errors += pages != len(deck["slides"])
        sheet(pdf, sheets / f"{stem}-pdf.png")
        if args.canva:
            errors += canva_pdf(deck, pdf, allowed)
    if pptx.exists() and args.canva:
        errors += canva_pptx(deck, pptx, allowed)
    if pptx.exists():
        soffice = shutil.which("soffice")
        if soffice:
            with tempfile.TemporaryDirectory() as tmp:
                subprocess.run([soffice, "--headless", "--convert-to", "pdf", "--outdir", tmp, str(pptx)], capture_output=True, check=False)
                if (Path(tmp) / f"{stem}.pdf").exists():
                    sheet(Path(tmp) / f"{stem}.pdf", sheets / f"{stem}-pptx.png")
        else:
            print("SKIP pptx render: soffice (LibreOffice) not installed")
    if page.exists():
        selftest(page, sheets / f"{stem}-selftest.png")
    sys.exit(1 if errors else 0)

if __name__ == "__main__":
    main()
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 197kUpdated Claude CodeCodexVerifiedInstall