drawlib.anim generates lossless multi-frame APNG (.png) and Animated WebP (.webp) illustrations via the Animation frame manager, while drawlib.slide provides 1920×1080 presentation stage helpers (current_slide, draw_page_number, draw_section_header) and compilers (build_slide, build_pptx) for interactive HTML and native editable PowerPoint decks.
Static Overview of drawlib.anim Keyframe Timeline and drawlib.slide 16:9 Stage ArchitectureSource Code
fromdrawlib.canvasimportsave,setupfromdrawlib.iconsimportphosphorfromdrawlib.linesimportlinefromdrawlib.shapesimportcircle,rectanglefromdrawlib.smartartsimportBoxListfromdrawlib.stylesimportColors,Stylesfromdrawlib.textimporttextsetup(width=134,height=62)# Left Panel: drawlib.anim Keyframe Timelinerectangle((35,31),width=60,height=52,style=Styles.Neutral.patch(shape_r=2.5))phosphor.play_circle((11.5,51.5),width=4.6,style=Styles.PrimaryBold)text((37.5,51.5),"drawlib.anim · Keyframe Loop",style=Styles.DarkBold.patch(text_size=11.5))frames=[(16.5,"Frame 1","0.0s",Styles.PrimaryNeutral,Styles.DarkBold,Styles.Dark),(35.0,"Frame 2","0.5s",Styles.PrimaryNeutral,Styles.DarkBold,Styles.Dark),(53.5,"Frame 3","1.0s",Styles.PrimaryFlat,Styles.WhiteBold,Styles.White),]forfx,title,ts,fst,tst,sstinframes:rectangle((fx,35.5),width=16.5,height=16.5,style=fst.patch(shape_r=1.8))text((fx,38.5),title,style=tst.patch(text_size=10.5))text((fx,32.0),ts,style=sst.patch(text_size=10.0))line((14,21.5),(56,21.5),arrow_head="->",style=Styles.PrimaryBold)forfxin(16.5,35.0,53.5):circle((fx,21.5),radius=1.2,style=Styles.PrimaryFlat)anim_out=BoxList(style=Styles.SecondaryNeutral,text_style=Styles.DarkBold.patch(text_size=10.0))anim_out.add("save('flow.png') APNG")anim_out.add("save('flow.webp') WebP")anim_out.draw(xy=(8.5,8.5),box_width=26.5,box_height=7.5,direction="left")# Right Panel: drawlib.slide 16:9 Presentation Stagerectangle((99,31),width=60,height=52,style=Styles.SecondaryNeutral.patch(shape_r=2.5))phosphor.presentation_chart((75.0,51.5),width=4.6,style=Styles.SecondaryBold)text((101.5,51.5),"drawlib.slide · 16:9 Stage",style=Styles.DarkBold.patch(text_size=11.5))# Miniature 16:9 Stage (50 x 28)rectangle((99,32.5),width=50,height=28,style=Styles.Neutral.patch(shape_fill_color=Colors.White,shape_r=1.5),)rectangle((81.5,32.5),width=15,height=28,style=Styles.PrimaryFlat.patch(shape_r=1.2))text((81.5,36.0),"SEC 02",style=Styles.WhiteBold.patch(text_size=10.0))text((81.5,30.0),"split",style=Styles.White.patch(text_size=10.0))rectangle((107.5,35.5),width=29,height=15,style=Styles.Neutral.patch(line_style="dashed",shape_r=1.2))text((107.5,38.2),"BoundingBox",style=Styles.DarkBold.patch(text_size=10.2))text((107.5,32.5),"1920 x 1080 px",style=Styles.Dark.patch(text_size=10.0))text((117.5,22.2),"4 / 9",style=Styles.PrimaryBold.patch(text_size=10.0))slide_out=BoxList(style=Styles.Neutral,text_style=Styles.DarkBold.patch(text_size=10.0))slide_out.add("build_slide() -> HTML")slide_out.add("build_pptx() -> .pptx",style=Styles.PrimaryNeutral)slide_out.draw(xy=(72.5,8.5),box_width=26.5,box_height=7.5,direction="left")save()
Multi-frame animation coordinator imported from drawlib.anim. Initializing an Animation instance registers it with the active Drawlib canvas so calling drawlib.canvas.save() writes all captured frames into a lossless APNG (.png, .apng) or Animated WebP (.webp) file.
Immutable dataclass imported from drawlib.slide holding the 1-based slide index and total slide count during deck compilation (stored inside a contextvars.ContextVar and exposed via current_slide).
Rasterization DPI for embedded drawlib static PNG diagrams (> 0).
anim_frame
Literal["first", "last"]
"last"
Frame extracted as a static PNG when a slide block uses Animation.
styles_path
str | None
None
Optional path to a custom styles.py script.
utils_path
str | None
None
Optional path to a custom utils.py script.
no_cache
bool
False
Bypass reading and writing the .drawlib/cache.db SQLite image cache.
timestamp
bool
False
Write the current build timestamp into OpenXML metadata instead of deterministic normalization.
Returns (str): Absolute path to the generated default-locale <stem>_<default_lang>.pptx file.
Raises: ValueError if input_dir is invalid, lacks drawlib.toml, dpi <= 0, or anim_frame is invalid; RuntimeError if Playwright, Chromium, or python-pptx fails.
Compile an i18n-native Markdown slide project directory into a standalone multi-locale 16:9 HTML presentation deck with Presenter View (?presenter=1), keyboard HUD controls, inline SVG font bundling, and <canvas> animation playback (also re-exported in drawlib.tools).
Dynamic runtime proxy (_CurrentSlideProxy instance imported from drawlib.slide) that reads the active SlideContext during build_slide() or build_pptx() execution. Outside slide compilation (e.g., standalone drawlib show), it safely falls back to SlideContext(index=1, total=1).
fromdrawlib.slideimportcurrent_slidecounter_str:str=current_slide.textcustom_str:str=current_slide.format("Slide {index} of {total}")
Member
Type
Description
current_slide.index
int
1-based index of the slide currently being rendered.
current_slide.total
int
Total number of slides in the active locale's deck.
current_slide.text
str
Formatted counter string "{index} / {total}" (also returned by str(current_slide)).
Render a standardized transparent slide page counter badge (14×3 canvas by default) using current_slide, designed for placement inside a bottom-right ::: block xy=(1700, 1010) width=140 height=30 stage block.
Optional topic titles or (title, description) tuples rendered as CardList preview cards.
total_sections
PosInt
0
Total sections in the deck (> 0 enables progress indicator dots and a "Part X of Y" badge).
variant
Literal["split", "centered", "banner", "minimal"]
"split"
Layout design: "split" (left dark panel + right neutral workspace), "centered" (centered badge + horizontal cards), "banner" (top dark hero band), or "minimal" (light editorial with left accent stripe).
section_label
str
"SECTION"
Uppercase label prefix displayed above or beside section_num.
badge_text
str | None
None
Custom badge string overriding the auto-generated "Part X of Y" text.
show_page_number
bool
True
Draw current_slide.text at the bottom-right corner when True.
show_decorations
bool
True
Draw subtle geometric background circles when True.
auto_setup
bool
True
Automatically call clear() and setup(width=192, height=108) before drawing.