feat: imgage feature

This commit is contained in:
2026-04-01 12:31:23 +02:00
parent 175de893aa
commit 528d2d8519
11 changed files with 431 additions and 7 deletions

View File

@@ -19,7 +19,7 @@ from uframe.ir import (
Gauge, Sparkline, Status, Table, TextSpan,
Form, Field, Password, Radio, Checkbox, FormButton,
Let, Source, IfBlock, ForLoop, CacheControl, OnSubmit, StateDecl,
BigTitle,
BigTitle, ImageNode,
ComponentDef, ComponentUse,
SourceType,
BorderWeight, HeadingLevel, DividerStyle, ListStyle, Align, Style,
@@ -427,6 +427,22 @@ def _parse_line(keyword: str, args: list[str], line_num: int) -> IRNode:
content = " ".join([keyword] + args)
return Text(content=content, source_line=line_num)
elif keyword == "image":
path = args[0] if args else ""
mode = args[1] if len(args) > 1 else "braille"
img_width = int(args[2]) if len(args) > 2 else 30
return ImageNode(path=path, mode=mode, img_width=img_width, source_line=line_num)
elif keyword == "dither":
# Style directive for image node
return _StyleDirective("dither_val", args[0] if args else "floyd", line_num)
elif keyword == "invert":
return _StyleDirective("invert_val", True, line_num)
elif keyword == "caption":
return _StyleDirective("caption_val", args[0] if args else "", line_num)
elif keyword == "bigtitle":
text = args[0] if args else ""
font = args[1] if len(args) > 1 else "block"
@@ -776,7 +792,17 @@ def parse(source: str, components: dict[str, ComponentDef] | None = None) -> Pag
if isinstance(node, _StyleDirective):
if stack:
parent = stack[-1][1]
setattr(parent.style, node.attr, node.value)
# Image-specific directives
if node.attr == "dither_val" and isinstance(parent, ImageNode):
parent.dither = node.value
elif node.attr == "invert_val" and isinstance(parent, ImageNode):
parent.invert = node.value
elif node.attr == "caption_val" and isinstance(parent, ImageNode):
parent.caption = node.value
elif node.attr in ("dither_val", "invert_val", "caption_val"):
pass # ignore if not on ImageNode
else:
setattr(parent.style, node.attr, node.value)
continue
if isinstance(node, _ThemeDirective):