[PR #1812] [MERGED] Card CSS theming: avatar override, typing indicator, message grouping #5282

Closed
opened 2026-10-22 04:14:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1812
Author: @kolacheee
Created: 6/1/2026
Status: ✅ Merged
Merged: 6/4/2026
Merged by: @cha1latte

Base: refactor ← Head: feat/card-css-content-fonts-grouping


📝 Commits (1)

  • 1539e0d Add card CSS avatar and typing theming hooks

📊 Changes

18 files changed (+1527 additions, -173 deletions)

View changed files

📝 docs/card-css-theming-guide.md (+92 -9)
📝 src/engine/contracts/types/character.ts (+18 -0)
📝 src/features/catalog/characters/components/CharacterColorsTab.tsx (+9 -0)
📝 src/features/catalog/characters/components/CharacterEditorTabContent.tsx (+6 -1)
📝 src/features/catalog/characters/components/CharacterMetadataTab.tsx (+35 -9)
➕ src/features/catalog/characters/components/ConversationAvatarControl.tsx (+207 -0)
📝 src/features/modes/conversation/components/ChatConversationSurface.tsx (+3 -0)
📝 src/features/modes/conversation/components/ConversationMessage.tsx (+88 -21)
📝 src/features/modes/conversation/components/ConversationModeRoute.tsx (+35 -2)
📝 src/features/modes/conversation/components/ConversationView.tsx (+206 -59)
➕ src/features/modes/conversation/hooks/use-conversation-avatar-overrides.ts (+87 -0)
📝 src/features/modes/shared/chat-ui/components/ChatMessage.tsx (+2 -0)
📝 src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.test.tsx (+38 -12)
📝 src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts (+10 -1)
📝 src/features/runtime/visuals/types.ts (+5 -0)
📝 src/features/shell/discovery/discovery-entries.json (+11 -0)
➕ src/shared/lib/chat-css.test.ts (+354 -0)
📝 src/shared/lib/chat-css.ts (+321 -59)

📄 Description

Linked issue

Closes #1967

Why this change

  • Card creators want real per-character identity in Conversation mode, but the card-CSS surface exposed almost nothing beyond the message wrapper: no themeable "typing?" indicator, no way to restyle or replace the avatar, and multi-paragraph replies rendered as several separate boxes that CSS couldn't treat as one container.
  • The CSS sanitizer also blocked common, harmless decorative needs (content text, embedded @font-face fonts) and mis-scoped chained [data-card-css] selectors in Exclusive mode.

What changed

Card CSS sanitizer + scoping (src/shared/lib/chat-css.ts)

  • Allow content: "text" after sanitization (strip <>, cap at 200 chars); allow CSS functions (attr(), counter(), quote keywords); unrecognized values still fall back to ''.
  • Allow @font-face blocks that reference only data: URIs (base64-embedded fonts); external-URL blocks are still stripped. Expanded the url() data-allowlist to also cover data:font/* and data:application/font*.
  • Fixed selector scoping for chained [data-card-css] selectors (e.g. [data-card-css]:not([data-grouped]), [data-card-css].mari-typing-indicator) so they chain onto the element in Exclusive mode and fall back to descendant in Chat mode.

Message structure + grouping

  • Added data-grouped to conversation and roleplay message wrappers, so card CSS can target first-in-group ([data-card-css]:not([data-grouped])) vs. continuations ([data-grouped]).
  • Conversation: collapsed split (multi-paragraph) assistant replies into a single .mari-message-body so card CSS styles one seamless container (continuous borders/corners/decorations); added mari-message-group / data-card-css-group hooks.

Themeable typing indicator

  • The "(character) is typing?" indicator is now CSS-targetable via .mari-typing-indicator / .mari-typing-dots / .mari-typing-text, scoped per character through data-card-css, with the character's name exposed as data-typing-name (usable as content: attr(data-typing-name) for custom labels).
  • It renders inside the generating message's bubble when that message has one on screen (e.g. during regeneration), otherwise as the standalone row below the list.

Per-character Conversation avatar override (new user-facing feature)

  • New extensions.conversationAvatar ({ mode: default | hide | emoji | sprite | gallery, value? }) with a ConversationAvatarOverride contract type.
  • New Conversation Avatar control in the character editor's Colors tab (ConversationAvatarControl) to choose the mode and pick an emoji / sprite / gallery image.
  • Sprite/gallery references are resolved to image URLs centrally in use-chat-surface-data (a single batched query, gated so it only fetches when an override is actually set) and rendered in ConversationMessage for both the single and grouped-speaker avatar paths. Conversation-mode only ? other modes ignore the field.

Other

  • Card CSS is now suppressed while a message is being edited, so the edit box renders in the app's plain style.
  • Expandable Creator Notes editor in the character metadata tab.
  • Updated docs/card-css-theming-guide.md with the new selector hooks, the typing-indicator section, the avatar control, edit-mode/grouping behavior, new tips, and a refreshed AI-prompt template.

Refactor impact

Primary owner: chat mode (conversation) + shared chat-ui

Impact areas reviewed:

  • src/shared/lib/chat-css.ts ? sanitizer + selector scoping
  • src/features/modes/conversation/components/ConversationView.tsx, ConversationMessage.tsx ? conversation rendering, grouping, avatar override, typing indicator
  • src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts ? shared CharacterMap builder (used by all chat modes); added a conversation-only avatar field + sprite/gallery resolution
  • src/features/modes/shared/chat-ui/components/ChatMessage.tsx ? roleplay data-grouped
  • src/features/catalog/characters/components/* ? character-editor Colors tab wiring + new ConversationAvatarControl
  • src/engine/contracts/types/character.ts, src/features/runtime/visuals/types.ts ? new optional types

Boundary notes:

  • Engine contract: character.ts gains an optional conversationAvatar extension field ? backward-compatible, no migration, ignored by older readers.
  • Shared hook: use-chat-surface-data is shared across conversation/roleplay/game. The added conversationAvatar / conversationAvatarSrc map fields and the resolution query are gated (only fetch when a sprite/gallery override exists) and are ignored by the roleplay/game renderers, so those surfaces are unchanged.
  • No Rust, storage, imports, or remote-runtime boundaries touched.

Pressure points touched:

  • Shared mode UI: use-chat-surface-data.ts (CharacterMap construction) and ChatMessage.tsx (RP wrapper). Not touched: ModeSurface, GameSurface, src-tauri/src/lib.rs command registration, import modules.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

Run locally on the merged branch (now up to date with refactor):

  • pnpm typecheck (tsc -b) ? pass
  • pnpm build (tsc -b + vite) ? pass
  • pnpm lint:eslint ? pass
  • pnpm check:architecture (depcruise + rust-structure) ? pass
  • pnpm check:unused (knip) ? pass
  • pnpm check:docs ? pass
  • pnpm check:discovery ? pass (38 entries; the new conversation-avatar entry validates)
  • pnpm check:line-endings ? fails only on pre-existing custom_components/marinara_engine/*.py (CRLF in a local Windows working tree); those files aren't touched by this PR and the check passes on an LF checkout such as CI.
  • pnpm check:rust (cargo) ? not run locally; this PR makes no Rust changes (the Rust deltas here come from the merged refactor base and are validated upstream).
  • Contributor manually playtested Conversation / Roleplay / Game modes ? avatar override modes (emoji/sprite/gallery/hide), the themeable + in-bubble typing indicator, grouping, and a multi-mode showcase theme.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Added a discovery entry (conversation-avatar, Library category) for the per-character Conversation Avatar control in src/features/shell/discovery/discovery-entries.json; its action opens the Characters panel. The card-CSS theming hooks themselves are documented in docs/card-css-theming-guide.md.

Docs and release impact

  • No docs changes needed
  • Updated docs/card-css-theming-guide.md

Proof

Core claim:

  • The Conversation avatar override (hide / emoji / sprite / gallery), the per-character group typing-row split, and the card-CSS theming hooks render correctly, and the risky surfaces they touch stay safe: untrusted card CSS cannot make network requests, escape its scope, override app theme tokens, spoof UI via content, or leak embedded fonts app-wide; and the avatar-resolution query stays gated and bounded so it can't regress chat into lag.

Verification run:

  • On the post-refactor-merge head: pnpm typecheck (clean), pnpm test (23 files / 97 passed), pnpm build (clean), pnpm lint:eslint, pnpm check:architecture, pnpm check:unused, pnpm check:docs, pnpm check:discovery ? all pass locally. (check:line-endings flags only pre-existing CRLF in custom_components/**/*.py, unrelated to this PR; no Rust changes.)

Evidence:

  • Sanitizer (pnpm test covers chat-css): the url() / @import / @font-face / :has() / position:fixed / theme-token / content guards; the @font-face data-font-only contract (external, image/*, non-font, local(), and source-less blocks all rejected); @keyframes + @font-face family namespacing with a per-card salt; and escaped-function-name canonicalization (\75rl( ? url(, lo\63al( ? local().
  • Avatar query (use-chat-surface-data suite): resolution is gated (no fetch without an override or outside Conversation mode), resolves once with no per-render refetch, and revalidates exactly once on remount.
  • Typing-CSS detection: cssTargetsTypingIndicator covered for styled / unstyled / comment-only inputs and @chat-mode surface filtering.

Risk coverage:

  • Positive rows: sprite / gallery / emoji avatar overrides resolve and render; per-character typing rows render in Exclusive mode; data-font @font-face is kept; benign card CSS (escaped selectors, content strings) is preserved.
  • Negative controls: external/escaped url() ? url(about:invalid); image/* / non-font / local() / source-less / escaped @font-face stripped; theme-token and !important overrides stripped; :has() removed; the avatar query stays disabled with no override and in Roleplay/Game.
  • Untested/manual blockers: visual rendering across Conversation/Roleplay/GM surfaces is covered by the screenshots under UI evidence (author playtest); not asserted by automated UI tests.

Manual verification requested:

  • Author playtested the avatar selector, Conversation/Roleplay/GM card-CSS rendering, and the typing indicator across modes (see UI evidence below).

UI evidence

Conversation Avatar selector
image

Convo mode example (Chat-scoped)
image

Convo mode examples (Character-scoped)
image
image
image

RP mode example (Chat-scoped)
image

RP mode example (Character-scoped)
image

GM mode example (Chat-scoped)
image


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1812 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 6/1/2026 **Status:** ✅ Merged **Merged:** 6/4/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `feat/card-css-content-fonts-grouping` --- ### 📝 Commits (1) - [`1539e0d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1539e0d3a2ba8ddcad9a2a06828a9b4a15ed4b10) Add card CSS avatar and typing theming hooks ### 📊 Changes **18 files changed** (+1527 additions, -173 deletions) <details> <summary>View changed files</summary> 📝 `docs/card-css-theming-guide.md` (+92 -9) 📝 `src/engine/contracts/types/character.ts` (+18 -0) 📝 `src/features/catalog/characters/components/CharacterColorsTab.tsx` (+9 -0) 📝 `src/features/catalog/characters/components/CharacterEditorTabContent.tsx` (+6 -1) 📝 `src/features/catalog/characters/components/CharacterMetadataTab.tsx` (+35 -9) ➕ `src/features/catalog/characters/components/ConversationAvatarControl.tsx` (+207 -0) 📝 `src/features/modes/conversation/components/ChatConversationSurface.tsx` (+3 -0) 📝 `src/features/modes/conversation/components/ConversationMessage.tsx` (+88 -21) 📝 `src/features/modes/conversation/components/ConversationModeRoute.tsx` (+35 -2) 📝 `src/features/modes/conversation/components/ConversationView.tsx` (+206 -59) ➕ `src/features/modes/conversation/hooks/use-conversation-avatar-overrides.ts` (+87 -0) 📝 `src/features/modes/shared/chat-ui/components/ChatMessage.tsx` (+2 -0) 📝 `src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.test.tsx` (+38 -12) 📝 `src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts` (+10 -1) 📝 `src/features/runtime/visuals/types.ts` (+5 -0) 📝 `src/features/shell/discovery/discovery-entries.json` (+11 -0) ➕ `src/shared/lib/chat-css.test.ts` (+354 -0) 📝 `src/shared/lib/chat-css.ts` (+321 -59) </details> ### 📄 Description ## Linked issue Closes #1967 ## Why this change - Card creators want real per-character identity in **Conversation** mode, but the card-CSS surface exposed almost nothing beyond the message wrapper: no themeable "typing?" indicator, no way to restyle or replace the avatar, and multi-paragraph replies rendered as several separate boxes that CSS couldn't treat as one container. - The CSS sanitizer also blocked common, harmless decorative needs (`content` text, embedded `@font-face` fonts) and mis-scoped chained `[data-card-css]` selectors in Exclusive mode. ## What changed **Card CSS sanitizer + scoping (`src/shared/lib/chat-css.ts`)** - Allow `content: "text"` after sanitization (strip `<>`, cap at 200 chars); allow CSS functions (`attr()`, `counter()`, quote keywords); unrecognized values still fall back to `''`. - Allow `@font-face` blocks that reference only `data:` URIs (base64-embedded fonts); external-URL blocks are still stripped. Expanded the `url()` data-allowlist to also cover `data:font/*` and `data:application/font*`. - Fixed selector scoping for chained `[data-card-css]` selectors (e.g. `[data-card-css]:not([data-grouped])`, `[data-card-css].mari-typing-indicator`) so they chain onto the element in Exclusive mode and fall back to descendant in Chat mode. **Message structure + grouping** - Added `data-grouped` to conversation and roleplay message wrappers, so card CSS can target first-in-group (`[data-card-css]:not([data-grouped])`) vs. continuations (`[data-grouped]`). - Conversation: collapsed split (multi-paragraph) assistant replies into a single `.mari-message-body` so card CSS styles one seamless container (continuous borders/corners/decorations); added `mari-message-group` / `data-card-css-group` hooks. **Themeable typing indicator** - The "(character) is typing?" indicator is now CSS-targetable via `.mari-typing-indicator` / `.mari-typing-dots` / `.mari-typing-text`, scoped per character through `data-card-css`, with the character's name exposed as `data-typing-name` (usable as `content: attr(data-typing-name)` for custom labels). - It renders **inside** the generating message's bubble when that message has one on screen (e.g. during regeneration), otherwise as the standalone row below the list. **Per-character Conversation avatar override (new user-facing feature)** - New `extensions.conversationAvatar` (`{ mode: default | hide | emoji | sprite | gallery, value? }`) with a `ConversationAvatarOverride` contract type. - New **Conversation Avatar** control in the character editor's *Colors* tab (`ConversationAvatarControl`) to choose the mode and pick an emoji / sprite / gallery image. - Sprite/gallery references are resolved to image URLs centrally in `use-chat-surface-data` (a single batched query, gated so it only fetches when an override is actually set) and rendered in `ConversationMessage` for both the single and grouped-speaker avatar paths. Conversation-mode only ? other modes ignore the field. **Other** - Card CSS is now suppressed while a message is being **edited**, so the edit box renders in the app's plain style. - Expandable **Creator Notes** editor in the character metadata tab. - Updated `docs/card-css-theming-guide.md` with the new selector hooks, the typing-indicator section, the avatar control, edit-mode/grouping behavior, new tips, and a refreshed AI-prompt template. ## Refactor impact Primary owner: chat mode (conversation) + shared chat-ui Impact areas reviewed: - `src/shared/lib/chat-css.ts` ? sanitizer + selector scoping - `src/features/modes/conversation/components/ConversationView.tsx`, `ConversationMessage.tsx` ? conversation rendering, grouping, avatar override, typing indicator - `src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts` ? **shared** CharacterMap builder (used by all chat modes); added a conversation-only avatar field + sprite/gallery resolution - `src/features/modes/shared/chat-ui/components/ChatMessage.tsx` ? roleplay `data-grouped` - `src/features/catalog/characters/components/*` ? character-editor *Colors* tab wiring + new `ConversationAvatarControl` - `src/engine/contracts/types/character.ts`, `src/features/runtime/visuals/types.ts` ? new optional types Boundary notes: - **Engine contract:** `character.ts` gains an *optional* `conversationAvatar` extension field ? backward-compatible, no migration, ignored by older readers. - **Shared hook:** `use-chat-surface-data` is shared across conversation/roleplay/game. The added `conversationAvatar` / `conversationAvatarSrc` map fields and the resolution query are gated (only fetch when a sprite/gallery override exists) and are ignored by the roleplay/game renderers, so those surfaces are unchanged. - No Rust, storage, imports, or remote-runtime boundaries touched. Pressure points touched: - Shared mode UI: `use-chat-surface-data.ts` (CharacterMap construction) and `ChatMessage.tsx` (RP wrapper). **Not** touched: ModeSurface, GameSurface, `src-tauri/src/lib.rs` command registration, import modules. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [x] Human/manual validation completed by contributor or reviewer ### Manual verification notes Run locally on the merged branch (now up to date with `refactor`): - `pnpm typecheck` (tsc -b) ? pass - `pnpm build` (tsc -b + vite) ? pass - `pnpm lint:eslint` ? pass - `pnpm check:architecture` (depcruise + rust-structure) ? pass - `pnpm check:unused` (knip) ? pass - `pnpm check:docs` ? pass - `pnpm check:discovery` ? pass (38 entries; the new `conversation-avatar` entry validates) - `pnpm check:line-endings` ? fails only on pre-existing `custom_components/marinara_engine/*.py` (CRLF in a local Windows working tree); those files aren't touched by this PR and the check passes on an LF checkout such as CI. - `pnpm check:rust` (cargo) ? not run locally; this PR makes no Rust changes (the Rust deltas here come from the merged `refactor` base and are validated upstream). - Contributor manually playtested Conversation / Roleplay / Game modes ? avatar override modes (emoji/sprite/gallery/hide), the themeable + in-bubble typing indicator, grouping, and a multi-mode showcase theme. ## Feature Discoverability Check exactly one: - [x] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [ ] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Added a discovery entry (`conversation-avatar`, Library category) for the per-character **Conversation Avatar** control in `src/features/shell/discovery/discovery-entries.json`; its action opens the Characters panel. The card-CSS theming hooks themselves are documented in `docs/card-css-theming-guide.md`. ## Docs and release impact - [ ] No docs changes needed - [x] Updated `docs/card-css-theming-guide.md` ## Proof Core claim: - The Conversation avatar override (hide / emoji / sprite / gallery), the per-character group typing-row split, and the card-CSS theming hooks render correctly, and the risky surfaces they touch stay safe: untrusted card CSS cannot make network requests, escape its scope, override app theme tokens, spoof UI via `content`, or leak embedded fonts app-wide; and the avatar-resolution query stays gated and bounded so it can't regress chat into lag. Verification run: - On the post-`refactor`-merge head: `pnpm typecheck` (clean), `pnpm test` (23 files / 97 passed), `pnpm build` (clean), `pnpm lint:eslint`, `pnpm check:architecture`, `pnpm check:unused`, `pnpm check:docs`, `pnpm check:discovery` ? all pass locally. (`check:line-endings` flags only pre-existing CRLF in `custom_components/**/*.py`, unrelated to this PR; no Rust changes.) Evidence: - Sanitizer (`pnpm test` covers `chat-css`): the `url()` / `@import` / `@font-face` / `:has()` / `position:fixed` / theme-token / `content` guards; the `@font-face` data-font-only contract (external, `image/*`, non-font, `local()`, and source-less blocks all rejected); `@keyframes` + `@font-face` family namespacing with a per-card salt; and escaped-function-name canonicalization (`\75rl(` ? `url(`, `lo\63al(` ? `local(`). - Avatar query (`use-chat-surface-data` suite): resolution is gated (no fetch without an override or outside Conversation mode), resolves once with no per-render refetch, and revalidates exactly once on remount. - Typing-CSS detection: `cssTargetsTypingIndicator` covered for styled / unstyled / comment-only inputs and `@chat-mode` surface filtering. Risk coverage: - Positive rows: sprite / gallery / emoji avatar overrides resolve and render; per-character typing rows render in Exclusive mode; data-font `@font-face` is kept; benign card CSS (escaped selectors, `content` strings) is preserved. - Negative controls: external/escaped `url()` ? `url(about:invalid)`; `image/*` / non-font / `local()` / source-less / escaped `@font-face` stripped; theme-token and `!important` overrides stripped; `:has()` removed; the avatar query stays disabled with no override and in Roleplay/Game. - Untested/manual blockers: visual rendering across Conversation/Roleplay/GM surfaces is covered by the screenshots under UI evidence (author playtest); not asserted by automated UI tests. Manual verification requested: - Author playtested the avatar selector, Conversation/Roleplay/GM card-CSS rendering, and the typing indicator across modes (see UI evidence below). ## UI evidence Conversation Avatar selector <img width="1603" height="1310" alt="image" src="https://github.com/user-attachments/assets/213dc340-9571-44db-8fbe-900344cdf8d6" /> Convo mode example (Chat-scoped) <img width="2560" height="1368" alt="image" src="https://github.com/user-attachments/assets/a2a21176-8e2c-49ae-9c91-10ce985adc72" /> Convo mode examples (Character-scoped) <img width="2560" height="1368" alt="image" src="https://github.com/user-attachments/assets/8202f6b7-0e58-4756-883f-f712ac64ab66" /> <img width="1603" height="326" alt="image" src="https://github.com/user-attachments/assets/4b04b753-9cbe-40ca-8a8c-838f8caa2f3e" /> <img width="2560" height="1367" alt="image" src="https://github.com/user-attachments/assets/982b93a8-7bc8-4ee2-907a-d7d36b19d05e" /> RP mode example (Chat-scoped) <img width="2560" height="1369" alt="image" src="https://github.com/user-attachments/assets/3597d1d3-b530-4a1f-8716-201f2bcd321e" /> RP mode example (Character-scoped) <img width="2560" height="1369" alt="image" src="https://github.com/user-attachments/assets/6339972e-7a54-491f-98d3-e300f88396ec" /> GM mode example (Chat-scoped) <img width="2560" height="1364" alt="image" src="https://github.com/user-attachments/assets/321a8b35-6fb3-4ada-948b-183869bc6755" /> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:14:54 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5282
No description provided.