Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(pets): done cards arrive as pixel-art letters
rubenluetke10-beep62ef7b4891a5
diff --git a/docs/pets.md b/docs/pets.mdindex dd82ac6fe9..fa9126030e 100644--- a/docs/pets.md+++ b/docs/pets.md@@ -43,9 +43,9 @@ one click.never the reply. It can be switched off (`[ui] pet_bubble`). See *Thethought bubble*.- **Done cards** under the strip (above the pet when there is no room below):- a dark, slightly see-through surface with a hairline rim, soft corners and a- soft shadow, when Jarvis answered a typed chat or a job Jarvis started came- back — a check, what was asked, the start of the answer (see *Cards*).+ little pixel-art letters — the pet gets mail — when Jarvis answered a typed+ chat or a job Jarvis started came back: a pixel envelope with a check badge,+ what was asked, the start of the answer (see *Cards*).- **The pet "None"** (`pet_id = "none"`) shows the control strip and thecards without a figure.@@ -58,12 +58,16 @@ Wayland, global shortcuts are a no-op, as for every other shortcut.## CardsOne window (`ui/orb/notice_stack.py`) holds the done cards;-`ui/orb/pet_cards.py` draws them. Both it and the thought bubble show their-frames through `ui/orb/layered_surface.py`: on Windows with real per-pixel-alpha (`jarvis/platform/layered_window.py`, `UpdateLayeredWindow`) — the-desktop shows faintly through the cards, shadows and fades are soft —-elsewhere, or when Windows refuses a frame, flattened onto the colour key:-opaque with hard edges, no shadow.+`ui/orb/pet_cards.py` draws them in the same pixel-art language as the thought+bubble, at the pet sprite's pixel size: a sheet of cream paper with the+sprites' dark outline, a shaded bottom row, a folded top-right corner and a+hard one-pixel drop shadow; a pixel envelope that drops in, then a green check+badge (a red cross when it failed) that pops onto its corner; the text in the+pets' dark ink. Both windows show their frames through+`ui/orb/layered_surface.py`: on Windows with real per-pixel alpha+(`jarvis/platform/layered_window.py`, `UpdateLayeredWindow`), so cards fade in+and out; elsewhere, or when Windows refuses a frame, flattened onto the colour+key with hard edges.Done cards are about Jarvis and nothing else (`jarvis/ui/pets/notices.py`):@@ -78,12 +82,12 @@ error gets no card; neither does a spoken turn (the answer was heard).Done cards are always the column's width, so they stack edge to edge: thenewest in front, up to two older ones peeking out behind it, each a step-smaller and fainter and showing its surface only; at most three are kept.+smaller and fainter and showing its paper only; at most three are kept.Hovering fans them into a column; leaving folds them back. A click sends thecard under the pointer away. A card leaves on its own after 9 s (`error` 14s), never while the pointer rests on the stack; the same card twice within 3 srefreshes instead of stacking. Cards drift in and fade on springs, and the-check ticks itself in. The column repaints at ~60 fps only while something+envelope and its badge arrive in steps. The column repaints at ~60 fps only while somethingmoves and not at all at rest. Done cards are dropped while the bell is off,the pet is hidden, or the look is not the pet; the strip stays in sight whilethey show.diff --git a/tests/unit/ui/test_pet_notices.py b/tests/unit/ui/test_pet_notices.pyindex 9e8a173804..5c4caab5ca 100644--- a/tests/unit/ui/test_pet_notices.py+++ b/tests/unit/ui/test_pet_notices.py@@ -122,23 +122,24 @@ def test_a_spring_settles_with_a_small_overshoot() -> None:# --- the cards themselves -----------------------------------------------------------def test_a_done_card_is_see_through_with_a_soft_shadow() -> None:- card = pet_cards.render_card("done", "Hi", "Hi! How can I help?", scale=1.0, max_width=360)+def test_a_done_card_is_a_pixel_art_letter() -> None:+ card = pet_cards.render_card("done", "Hi", "Hi! How can I help?", max_width=360, art_px=4)assert card.mode == "RGBA"- x0, y0, x1, y1 = pet_cards.card_box(card, 1.0)- middle = card.getpixel(((x0 + x1) // 2, y1 - 3))- assert 150 < middle[3] < 255 # the desktop shows through the surface- shadow = card.getpixel(((x0 + x1) // 2, y1 + 3))- assert 0 < shadow[3] < 120 # a soft shadow under it, not a hard edge+ assert card.width % 4 == 0 and card.height % 4 == 0 # whole art pixels+ # Hard sprite edges: opaque, transparent, or the hard drop shadow.+ assert set(card.getchannel("A").getdata()) <= {0, pet_cards.SHADOW_ALPHA, 255}+ x0, y0, x1, y1 = pet_cards.card_box(card, 4)+ assert card.getpixel((x0 + 6, y1 - 12))[:3] == pet_cards.PAPER+ assert card.getpixel((x0 + 6, y0 - 1))[:3] == pet_cards.OUTLINE # the rim hugs the sheetassert card.getpixel((0, 0))[3] == 0def test_done_cards_share_one_width_and_wrap_the_answer() -> None:- short = pet_cards.render_card("done", "Hi", "Hello", scale=1.0, max_width=300)- long = pet_cards.render_card("done", "word " * 40, "word " * 80, scale=1.0, max_width=300)- pad = 2 * pet_cards.SHADOW_PAD- assert short.width == long.width == 300 + pad- assert long.height - pad < 120 # title on one line, the answer on two+ short = pet_cards.render_card("done", "Hi", "Hello", max_width=300, art_px=3)+ long = pet_cards.render_card("done", "word " * 40, "word " * 80, max_width=300, art_px=3)+ assert short.width == long.width == 300 + 2 * pet_cards.card_pad(3)+ assert long.height > short.height+ assert long.height - 2 * pet_cards.card_pad(3) < 120 # the answer stops at two linesdef test_text_helpers_ellipsize_and_wrap() -> None:@@ -157,8 +158,8 @@ def test_a_keyed_frame_has_hard_edges_only() -> None:def test_the_icon_ticks_itself() -> None:- empty = pet_cards.render_icon("done", 0, 20)- full = pet_cards.render_icon("done", pet_cards.ICON_FRAMES, 20)+ empty = pet_cards.render_icon("done", 0)+ full = pet_cards.render_icon("done", pet_cards.ICON_FRAMES)assert empty.getchannel("A").getextrema()[1] == 0assert full.getchannel("A").getextrema()[1] == 255diff --git a/ui/orb/notice_stack.py b/ui/orb/notice_stack.pyindex 7ba435626e..7a1ab70c68 100644--- a/ui/orb/notice_stack.py+++ b/ui/orb/notice_stack.py@@ -60,10 +60,6 @@ COLLAPSE_GRACE_MS = 280DRIFT_PX = 10-def _spx(value: float, scale: float) -> int:- return max(1, int(round(value * max(0.25, float(scale)))))--# --- model -------------------------------------------------------------------@@ -215,8 +211,11 @@ class _Item:class PetNoticeStack:"""The card column's own frameless window. Every method runs on the Tk thread."""- def __init__(self, parent: tk.Misc, *, scale: float = 1.0, width: int = 360) -> None:+ def __init__(+ self, parent: tk.Misc, *, scale: float = 1.0, width: int = 360, art_px: int = 3+ ) -> None:self._scale = max(0.25, float(scale))+ self._art_px = max(1, int(art_px))self._card_w = max(160, int(width))self._model = NoticeModel()self._items: dict[int, _Item] = {}@@ -243,18 +242,23 @@ class PetNoticeStack:@propertydef _pad(self) -> int:- return _spx(pet_cards.SHADOW_PAD, self._scale)+ return pet_cards.card_pad(self._art_px)@propertydef window_size(self) -> tuple[int, int]:- """Room for every kept card fanned out."""- s = self._scale- tallest_card = _spx(- 2 * pet_cards.PAD_Y + 1.45 * pet_cards.TITLE_PX + 3 + 2 * 1.45 * pet_cards.BODY_PX, s+ """Room for every kept card fanned out (each as tall as a card gets)."""+ tallest = pet_cards.render_card(+ "done",+ "x",+ "word " * 80,+ scale=round(self._scale, 3),+ max_width=self._card_w,+ art_px=self._art_px,+ content=False,)- gap = CARD_GAP * s- height = NOTICE_KEEP * (tallest_card + gap)- return self._card_w + 2 * self._pad, int(height) + 2 * self._pad+ tallest_card = tallest.height - 2 * self._pad+ height = NOTICE_KEEP * (tallest_card + CARD_GAP * self._scale)+ return tallest.width, int(height) + 2 * self._pad# -- public ---------------------------------------------------------------@@ -268,11 +272,12 @@ class PetNoticeStack:"""The column's toplevel while it is on screen (for Z-order repair)."""return self._window.top if self._window.shown else None- def set_scale(self, scale: float, width: int) -> None:+ def set_scale(self, scale: float, width: int, art_px: int | None = None) -> None:scale, width = max(0.25, float(scale)), max(160, int(width))- if (scale, width) == (self._scale, self._card_w):+ px = self._art_px if art_px is None else max(1, int(art_px))+ if (scale, width, px) == (self._scale, self._card_w, self._art_px):return- self._scale, self._card_w = scale, width+ self._scale, self._card_w, self._art_px = scale, width, pxself._window.resize(self.window_size)self._retarget(snap=True)self._place()@@ -368,6 +373,7 @@ class PetNoticeStack:item.detail,scale=round(self._scale, 3),max_width=self._card_w,+ art_px=self._art_px,hovered=hovered,icon_frame=pet_cards.ICON_FRAMES if frame is None else frame,content=content,@@ -491,7 +497,7 @@ class PetNoticeStack:if abs(size - 1.0) > 0.004:image = image.resize((max(1, int(image.width * size)), max(1, int(image.height * size))),- Image.Resampling.BILINEAR,+ Image.Resampling.NEAREST, # pixel art stays crisp)if opacity < 0.995:image = image.copy()diff --git a/ui/orb/overlay.py b/ui/orb/overlay.pyindex 5a77b0756e..13a5bed47b 100644--- a/ui/orb/overlay.py+++ b/ui/orb/overlay.py@@ -2696,7 +2696,9 @@ class OrbOverlay:notices = self._noticesif notices is not None:strip_w, _strip_h = orb_controls.pet_strip_size(scale)- notices.set_scale(scale, int(round(strip_w * PET_NOTICE_WIDTH_PER_STRIP)))+ notices.set_scale(+ scale, int(round(strip_w * PET_NOTICE_WIDTH_PER_STRIP)), self._thought_art_px()+ )self._sync_notice_anchor()def _clamp_position(@@ -3836,6 +3838,7 @@ class OrbOverlay:self._root,scale=scale,width=int(round(strip_w * PET_NOTICE_WIDTH_PER_STRIP)),+ art_px=self._thought_art_px(),)except tk.TclError:logging.getLogger("jarvis.orb").debug("card column unavailable", exc_info=True)@@ -3864,6 +3867,11 @@ class OrbOverlay:notices = self._noticesif notices is None:return+ scale = self._pet_strip_scale()+ strip_w, _strip_h = orb_controls.pet_strip_size(scale)+ notices.set_scale(+ scale, int(round(strip_w * PET_NOTICE_WIDTH_PER_STRIP)), self._thought_art_px()+ )notices.set_anchor(self._notice_anchor(refresh_limit=refresh_limit))def _thought_art_px(self) -> int:diff --git a/ui/orb/pet_cards.py b/ui/orb/pet_cards.pyindex 5671054ac2..0138fa7852 100644--- a/ui/orb/pet_cards.py+++ b/ui/orb/pet_cards.py@@ -1,13 +1,18 @@-"""The pet's done cards, drawn.--A Jarvis turn or a task Jarvis started has finished: a small green check (a-red cross when it failed) and a bold title — what was asked — over the first-line or two of the answer, on a dark, slightly see-through surface with a-hairline rim, soft rounded corners and a soft shadow.--Everything is pure PIL and returns RGBA with real alpha, ready for-:class:`ui.orb.layered_surface.AlphaWindow`, which flattens it onto a colour-key where a platform has no per-pixel alpha. The text helpers (:func:`font`,+"""The pet's done cards, drawn as little pixel-art letters.++A Jarvis turn or a task Jarvis started has finished, and the pet gets mail:+a sheet of cream paper in the pets' pixel-art language (``thought_bubble``+draws the thinking in the same one) — the sprites' dark one-pixel outline,+a shaded bottom row, a folded corner and a hard pixel drop shadow. On the+left a pixel envelope with a green check badge (a red cross when it failed);+on the right a bold title — what was asked — over the first line or two of+the answer.++Pixel art is drawn at art resolution (one art pixel = ``art_px`` screen+pixels, the pet sprite's own size) and scaled up nearest-neighbour, so every+edge stays a crisp step; only the text is drawn at screen resolution on top.+Everything is pure PIL and returns RGBA, ready for+:class:`ui.orb.layered_surface.AlphaWindow`. The text helpers (:func:`font`,:func:`ellipsize`, :func:`wrap`) serve the thought bubble too."""@@ -22,51 +27,47 @@ from pathlib import Pathfrom PIL import Image, ImageChops, ImageDraw, ImageFilter, ImageFont_Rgb = tuple[int, int, int]-_Rgba = tuple[int, int, int, int]#: What a card shows.CARD_KINDS: tuple[str, ...] = ("done", "error")-#: Unscaled geometry (logical px at 100 % and ``pet_scale`` 1.0).-PAD_X = 16-PAD_Y = 11-LINE_GAP = 3-ICON = 17-ICON_GAP = 7-RADIUS = 18-MIN_WIDTH = 120-#: Room around a card for its shadow.-SHADOW_PAD = 14-SHADOW_BLUR = 9-SHADOW_OFFSET_Y = 3-SHADOW_ALPHA = 110-#: Font sizes in px.-TITLE_PX = 14.5-BODY_PX = 14.0-#: Lines of the answer under a done card's title.+#: Art-pixel geometry of a card.+PAD_X_A = 4+PAD_Y_A = 3+ICON_W_A = 13+ICON_H_A = 10+ICON_GAP_A = 4+LINE_GAP_A = 1+#: The folded corner's size and the drop shadow's offset, in art pixels.+FOLD_A = 5+SHADOW_A = 1+#: Room around the paper for the shadow (art pixels).+MARGIN_A = 2+#: Text sizes, logical px at 100 %.+TITLE_PX = 14.0+BODY_PX = 13.5+#: Lines of the answer under the title.DETAIL_LINES = 2-#: The surface: a dark grey just see-through enough that the desktop shows-#: as a shade, a hairline rim, and the text colours.-FILL: _Rgba = (34, 34, 37, 226)-RIM: _Rgba = (255, 255, 255, 30)-#: The fill a colour-keyed window uses instead (no alpha there).-FILL_SOLID: _Rgb = (30, 30, 33)-RIM_SOLID: _Rgb = (58, 58, 63)-TITLE: _Rgb = (242, 242, 245)-BODY: _Rgb = (190, 191, 198)-ICON_FILL: dict[str, _Rgb] = {"done": (34, 197, 94), "error": (239, 68, 68)}-ICON_MARK: dict[str, _Rgb] = {"done": (10, 26, 16), "error": (40, 8, 8)}-#: Hover lifts a card a shade.-HOVER_LIFT = 10--#: The icon draws itself in this many steps (the check is ticked).+#: The pets' palette: the sprites' outline, cream paper, its shading and fold,+#: the ink, and the envelope.+OUTLINE: _Rgb = (27, 22, 34)+PAPER: _Rgb = (252, 248, 237)+PAPER_HOVER: _Rgb = (255, 253, 246)+PAPER_SHADE: _Rgb = (232, 224, 206)+FOLD: _Rgb = (219, 209, 186)+INK: _Rgb = (46, 36, 58)+INK_SOFT: _Rgb = (104, 94, 112)+ENVELOPE: _Rgb = (255, 255, 255)+ENVELOPE_SHADE: _Rgb = (214, 214, 226)+BADGE: dict[str, _Rgb] = {"done": (76, 196, 98), "error": (226, 82, 82)}+SHADOW_ALPHA = 105+#: The backdrop a colour-keyed window flattens a card onto.+FILL_SOLID: _Rgb = PAPER++#: The icon arrives in this many steps: the envelope drops in, then the badge+#: pops onto its corner.ICON_FRAMES = 10-_SS = 3 # supersampling for the card silhouette---def _px(value: float, scale: float) -> int:- return max(1, int(round(value * max(0.25, float(scale)))))# --- fonts -------------------------------------------------------------------@@ -162,105 +163,68 @@ def wrap(return lines[:max_lines]-# --- shapes ------------------------------------------------------------------+# --- pixel art -----------------------------------------------------------------[email protected]_cache(maxsize=64)-def _rounded_mask(width: int, height: int, radius: int) -> Image.Image:- """An antialiased rounded-rectangle mask (drawn large, scaled down)."""- big = Image.new("L", (width * _SS, height * _SS), 0)- ImageDraw.Draw(big).rounded_rectangle(- [0, 0, width * _SS - 1, height * _SS - 1], radius=radius * _SS, fill=255- )- return big.resize((width, height), Image.Resampling.LANCZOS)+def card_pad(art_px: int) -> int:+ """Screen pixels around the paper (room for its drop shadow)."""+ return MARGIN_A * max(1, int(art_px))[email protected]_cache(maxsize=64)-def _surface(width: int, height: int, radius: int, scale: float, hovered: bool) -> Image.Image:- """Shadow, fill and rim of one card, with ``SHADOW_PAD`` around it."""- pad = _px(SHADOW_PAD, scale)- full = Image.new("RGBA", (width + 2 * pad, height + 2 * pad), (0, 0, 0, 0))- mask = _rounded_mask(width, height, radius)- shadow = Image.new("L", full.size, 0)- shadow.paste(- mask.point(lambda v: v * SHADOW_ALPHA // 255), (pad, pad + _px(SHADOW_OFFSET_Y, scale))- )- shadow = shadow.filter(ImageFilter.GaussianBlur(_px(SHADOW_BLUR, scale) / 2.0))- full.putalpha(shadow)- lift = HOVER_LIFT if hovered else 0- fill = (FILL[0] + lift, FILL[1] + lift, FILL[2] + lift, FILL[3])- body = Image.new("RGBA", (width, height), fill)- body.putalpha(ImageChops.multiply(mask, Image.new("L", mask.size, fill[3])))- full.alpha_composite(body, (pad, pad))- # The rim: the silhouette minus itself shrunk by one pixel.- inner = _rounded_mask(max(1, width - 2), max(1, height - 2), max(1, radius - 1))- ring = mask.copy()- hole = Image.new("L", mask.size, 0)- hole.paste(inner, (1, 1))- ring = ImageChops.subtract(ring, hole)- rim = Image.new("RGBA", (width, height), RIM[:3] + (0,))- rim.putalpha(ring.point(lambda v: v * RIM[3] // 255))- full.alpha_composite(rim, (pad, pad))- return full---def _ease_out_back(t: float) -> float:- t = max(0.0, min(1.0, t))- c1 = 1.70158- return 1.0 + (c1 + 1.0) * (t - 1.0) ** 3 + c1 * (t - 1.0) ** 2+def _ring(mask: Image.Image) -> Image.Image:+ """The one-pixel outline around ``mask``."""+ return ImageChops.subtract(mask.filter(ImageFilter.MaxFilter(3)), mask)[email protected]_cache(maxsize=64)-def render_icon(kind: str, frame: int, diameter: int) -> Image.Image:- """The round check (or cross) at animation ``frame``, RGBA."""- ss = 4- size = max(2, diameter) * ss- layer = Image.new("RGBA", (size, size), (0, 0, 0, 0))- d = ImageDraw.Draw(layer)- t = max(0, min(ICON_FRAMES, frame)) / ICON_FRAMES- r = size / 2.0 * _ease_out_back(min(1.0, t / 0.5))- c = size / 2.0- fill = ICON_FILL.get(kind, ICON_FILL["done"])- mark = ICON_MARK.get(kind, ICON_MARK["done"])- if r > 0.5:- d.ellipse([c - r, c - r, c + r, c + r], fill=fill + (255,))- share = max(0.0, min(1.0, (t - 0.3) / 0.7))- width = max(1, int(round(size * 0.12)))- unit = size / 24.0-- def pt(u: float, v: float) -> tuple[float, float]:- return (c + (u - 12.0) * unit, c + (v - 12.0) * unit)-- def stroke(points: list[tuple[float, float]], amount: float) -> None:- if amount <= 0:- return- pts = [pt(u, v) for u, v in points]- lengths = [math.dist(a, b) for a, b in zip(pts, pts[1:], strict=False)]- want = sum(lengths) * amount- line = [pts[0]]- for (a, b), length in zip(zip(pts, pts[1:], strict=False), lengths, strict=False):- if want >= length:- line.append(b)- want -= length- continue- f = want / length if length else 0.0- line.append((a[0] + (b[0] - a[0]) * f, a[1] + (b[1] - a[1]) * f))- break- d.line(line, fill=mark + (255,), width=width, joint="curve")- for x, y in (line[0], line[-1]):- d.ellipse(- [x - width / 2, y - width / 2, x + width / 2, y + width / 2], fill=mark + (255,)- )-- if kind == "error":- stroke([(8.4, 8.4), (15.6, 15.6)], min(1.0, share * 2))- stroke([(15.6, 8.4), (8.4, 15.6)], max(0.0, share * 2 - 1))- else:- stroke([(7.0, 12.4), (10.6, 15.8), (17.0, 8.8)], share)- return layer.resize((diameter, diameter), Image.Resampling.LANCZOS)[email protected]_cache(maxsize=32)+def _paper_mask(w: int, h: int) -> Image.Image:+ """The sheet's silhouette at art resolution: a rectangle with stepped+ corners and its top-right corner folded away."""+ mask = Image.new("L", (w, h), 255)+ px = mask.load()+ for x, y in ((0, 0), (w - 1, h - 1), (0, h - 1)):+ px[x, y] = 0+ for y in range(FOLD_A):+ for x in range(w - FOLD_A + y + 1, w):+ px[x, y] = 0+ return mask-# --- cards -------------------------------------------------------------------[email protected]_cache(maxsize=64)+def render_icon(kind: str, frame: int) -> Image.Image:+ """The pixel envelope with its badge at animation ``frame``, at art resolution.++ The envelope drops in from two pixels up, then the badge pops onto its+ corner: small first, then full size.+ """+ t = max(0, min(ICON_FRAMES, frame)) / ICON_FRAMES+ art = Image.new("RGBA", (ICON_W_A + 2, ICON_H_A + 3), (0, 0, 0, 0))+ if t <= 0.0:+ return art+ drop = 2 if t < 0.2 else (1 if t < 0.35 else 0)+ d = ImageDraw.Draw(art)+ x0, y0 = 0, 1 - drop + 1+ x1, y1 = ICON_W_A - 2, y0 + ICON_H_A - 3+ d.rectangle([x0, y0, x1, y1], fill=(*ENVELOPE, 255), outline=(*OUTLINE, 255))+ d.line([(x0 + 1, y1 - 1), (x1 - 1, y1 - 1)], fill=(*ENVELOPE_SHADE, 255))+ mid = (x0 + x1) // 2+ d.line([(x0 + 1, y0 + 1), (mid, y0 + 4), (x1 - 1, y0 + 1)], fill=(*OUTLINE, 255))+ if t >= 0.6:+ size = 4 if t < 0.8 else 6+ bx = ICON_W_A + 1 - size+ by = ICON_H_A + 2 - size+ badge = BADGE.get(kind, BADGE["done"])+ d.ellipse([bx, by, bx + size - 1, by + size - 1], fill=(*badge, 255))+ d.ellipse([bx, by, bx + size - 1, by + size - 1], outline=(*OUTLINE, 255))+ if size == 6:+ white = (255, 255, 255, 255)+ if kind == "error":+ d.point([(bx + 2, by + 2), (bx + 3, by + 3), (bx + 3, by + 2), (bx + 2, by + 3)],+ fill=white) # fmt: skip+ else:+ d.point([(bx + 1, by + 3), (bx + 2, by + 4), (bx + 3, by + 3), (bx + 4, by + 2)],+ fill=white) # fmt: skip+ return art@functools.lru_cache(maxsize=128)@@ -271,69 +235,83 @@ def render_card(*,scale: float = 1.0,max_width: int = 360,+ art_px: int = 3,hovered: bool = False,icon_frame: int = ICON_FRAMES,content: bool = True,) -> Image.Image:- """One card as RGBA, shadow included (``SHADOW_PAD`` on every side).+ """One letter as RGBA, ``card_pad(art_px)`` of shadow room on every side.- A done card is always ``max_width`` wide, so stacked cards line up edge- to edge. ``content=False`` draws the- surface alone — a card peeking out behind another must not show its- text through the see-through card in front.-- Pure and cached — never mutate the result.+ Every card is ``max_width`` wide, so stacked letters line up edge to edge.+ ``content=False`` draws the sheet alone — a letter peeking out behind+ another shows its edge, not its text. Pure and cached — never mutate the+ result."""- pad_x, pad_y = _px(PAD_X, scale), _px(PAD_Y, scale)- max_inner = max(40, max_width - 2 * pad_x)- title_font = font("semibold", _px(TITLE_PX, scale))- body_font = font("regular", _px(BODY_PX, scale))- icon_d = _px(ICON, scale)- icon_gap = _px(ICON_GAP, scale)- title_text = ellipsize(" ".join(title.split()), title_font, max_inner - icon_d - icon_gap)- lines = wrap(" ".join(detail.split()), body_font, max_inner, DETAIL_LINES) if detail else []- widest = max(- [icon_d + icon_gap + _text_w(title_font, title_text)]- + [_text_w(body_font, line) for line in lines]+ u = max(1, int(art_px))+ w_a = max(40, int(max_width) // u)+ title_font = font("semibold", max(9, int(round(TITLE_PX * scale))))+ body_font = font("regular", max(9, int(round(BODY_PX * scale))))+ text_x_a = PAD_X_A + ICON_W_A + ICON_GAP_A+ text_w = (w_a - text_x_a - PAD_X_A - FOLD_A // 2) * u+ title_text = ellipsize(" ".join(title.split()), title_font, text_w)+ lines = wrap(" ".join(detail.split()), body_font, text_w, DETAIL_LINES) if detail else []+ title_lh, body_lh = _line_h(title_font), _line_h(body_font)+ th_a = math.ceil(title_lh / u)+ bh_a = math.ceil(body_lh / u)+ text_h_a = th_a + (LINE_GAP_A + len(lines) * bh_a if lines else 0)+ h_a = 2 * PAD_Y_A + max(ICON_H_A + 1, text_h_a)+ m = MARGIN_A+ art = Image.new("RGBA", (w_a + 2 * m, h_a + 2 * m), (0, 0, 0, 0))+ paper = _paper_mask(w_a, h_a)+ # A hard pixel drop shadow, then the sheet, its shaded bottom row, the+ # folded corner and the outline around it all.+ shadow = Image.new("RGBA", paper.size, (*OUTLINE, SHADOW_ALPHA))+ art.paste(shadow, (m + SHADOW_A, m + SHADOW_A), paper)+ art.paste((*(PAPER_HOVER if hovered else PAPER), 255), (m, m, m + w_a, m + h_a), paper)+ lifted = Image.new("L", paper.size, 0)+ lifted.paste(paper, (0, -1))+ shade = Image.new("L", art.size, 0)+ shade.paste(ImageChops.subtract(paper, lifted), (m, m))+ art.paste((*PAPER_SHADE, 255), (0, 0), shade)+ d = ImageDraw.Draw(art)+ fx = m + w_a - FOLD_A+ d.polygon([(fx, m), (fx, m + FOLD_A - 1), (m + w_a - 1, m + FOLD_A - 1)], fill=(*FOLD, 255))+ whole = Image.new("L", art.size, 0)+ whole.paste(paper, (m, m))+ fold = Image.new("L", art.size, 0)+ ImageDraw.Draw(fold).polygon(+ [(fx, m), (fx, m + FOLD_A - 1), (m + w_a - 1, m + FOLD_A - 1)], fill=255)- _ = widest # measured for the wrap; the width itself is fixed- width = max(_px(MIN_WIDTH, scale), max_width)- title_h = max(_line_h(title_font), icon_d)- body_h = _line_h(body_font)- gap = _px(LINE_GAP, scale)- height = 2 * pad_y + title_h + (gap + body_h * len(lines) if lines else 0)- radius = min(height // 2, _px(RADIUS, scale))- card = _surface(width, height, radius, round(scale, 3), hovered).copy()+ whole = ImageChops.lighter(whole, fold)+ art.paste((*OUTLINE, 255), (0, 0), _ring(whole))+ d.line([(fx, m), (fx, m + FOLD_A - 1), (m + w_a - 1, m + FOLD_A - 1)], fill=(*OUTLINE, 255))+ if content:+ icon = render_icon(kind, icon_frame)+ art.alpha_composite(icon, (m + PAD_X_A, m + (h_a - ICON_H_A - 1) // 2))+ image = art.resize((art.width * u, art.height * u), Image.Resampling.NEAREST)if not content:- return card- pad = _px(SHADOW_PAD, scale)- x0, y0 = pad + pad_x, pad + pad_y- icon = render_icon(kind, icon_frame, icon_d)- card.alpha_composite(icon, (x0, int(round(y0 + (title_h - icon_d) / 2.0))))- d = ImageDraw.Draw(card)- d.text(- (x0 + icon_d + icon_gap, y0 + title_h / 2.0),- title_text,- font=title_font,- fill=TITLE + (255,),- anchor="lm",- )- y = y0 + title_h + gap+ return image+ td = ImageDraw.Draw(image)+ x = (m + text_x_a) * u+ y = (m + (h_a - text_h_a) / 2.0) * u+ td.text((x, y), title_text, font=title_font, fill=(*INK, 255))+ y += th_a * u + LINE_GAP_A * ufor line in lines:- d.text((x0, y), line, font=body_font, fill=BODY + (255,))- y += body_h- return card+ td.text((x, y), line, font=body_font, fill=(*INK_SOFT, 255))+ y += bh_a * u+ return image-def card_box(image: Image.Image, scale: float) -> tuple[int, int, int, int]:- """The card's own rectangle inside its shadow-padded image."""- pad = _px(SHADOW_PAD, scale)+def card_box(image: Image.Image, art_px: int) -> tuple[int, int, int, int]:+ """The sheet's own rectangle inside its padded image."""+ pad = card_pad(art_px)return pad, pad, image.width - pad, image.height - pad__all__ = ["CARD_KINDS","card_box",+ "card_pad","ellipsize","font","render_card",