[PR #674] [MERGED] fix(avatar-crop): use focal-point object-position on RP rectangle and glued-panel avatars #4724

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/674
Author: @Romuromylus
Created: 5/11/2026
Status: ✅ Merged
Merged: 5/11/2026
Merged by: @Romuromylus

Base: main ← Head: fix/avatar-crop-rectangle-focal-point


📝 Commits (1)

  • 4d6314f fix(avatar-crop): use focal-point object-position on RP rectangle and glued-panel avatars

📊 Changes

1 file changed (+48 additions, -7 deletions)

View changed files

📝 packages/client/src/components/chat/ChatMessage.tsx (+48 -7)

📄 Description

Linked issue

Closes #673

Why this change

PR #671 propagated the new source-rectangle avatar crop format through chat-side render sites. The format renders the <img> with position: absolute, width: 100/srcWidth%, height: 100/srcHeight%, and object-fit: fill — math that assumes the parent has the same aspect ratio as the (editor-enforced-square) crop.

For RP-mode rectangular sites — "Small Rectangles" compact style and "Glued Side Panel" — the parent is non-square. object-fit: fill then stretched the cropped face to the rectangle's aspect ratio. Symptoms (visible only when the user has saved a new-format avatar crop):

  • Glued Side Panel: face squished horizontally or vertically depending on bubble height.
  • Small Rectangles: face squished vertically.
  • Short user messages in Glued Side Panel: the panel renders as a wide rectangle and object-cover object-top showed only the top of the source (e.g. just the character's hair).

What changed

In packages/client/src/components/chat/ChatMessage.tsx:

  • Add a rectangleSafeCropStyle(crop, fallback) helper that returns:
    • Legacy {zoom, offsetX, offsetY} crops → the fallback (unchanged transform-based path; composes with object-cover).
    • New-format crops → { objectPosition: 'X% Y%' } derived from the crop's center, so object-cover keeps the user's chosen focal point centered in the rectangle.
  • Derive five styles from that helper:
    • compactAvatarCropStyle and compactMergedAvatarCropStyle(avatar) for compactAvatarFrameClass sites (gated on useCompactRectangleAvatar — the round Small Circles variant still uses the unmodified avatarCropStyle).
    • panelAvatarCropStyle and panelMergedAvatarCropStyle(avatar) for rpg-avatar-panel-tail-image and rpg-avatar-panel-media (always-rectangular sites).
  • Wire those into the six <img> sites in the file:
    • rpg-avatar-panel-tail single + merged (lines ~1146–1175).
    • compactAvatarFrameClass single + merged (lines ~1355–1400).
    • rpg-avatar-panel-media single + merged (lines ~1499–1542).

Round/square frames (Small Circles compact style + Conversation Mode bubble h-8 w-8 rounded-full) continue to use the unchanged avatarCropStyle, which is PR #661's original logic — correct when parent matches crop aspect ratio.

No data migration. Existing crops (both formats) render correctly without re-editing.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify a character with a new-format avatarCrop saved (square crop region of a non-square source) in Small Rectangles style: the side avatar tile renders the chosen face centered, no horizontal/vertical squish.
  • Manually verify the same character in Glued Side Panel style on both tall messages and short messages: the panel renders the face centered, no distortion, and short user-message panels (wide rectangles) center on the face instead of showing only the top of the source.
  • Manually verify a character with a legacy {zoom, offsetX, offsetY} crop renders identically to before in all three RP avatar styles — the customization should still apply via the unchanged transform path.
  • Manually verify Small Circles style and Conversation Mode chat bubbles still render new-format crops correctly with the unchanged PR #661 path (parent matches crop aspect ratio, no regression).
  • Manually verify a character with no avatarCrop extension renders identically to before in all styles (the helper returns the fallback unchanged for null crops).
  • Manually verify the user-side bubble in Conversation Mode still applies the persona crop on the round avatar (the persona-crop snapshot path from PR #671 is untouched).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Behavioral fix; the bug surface is identical to #673's repro steps. After: rectangles render the chosen face centered; no stretching, no banner-bleed on short messages.

Summary by CodeRabbit

  • Bug Fixes
    • Improved avatar image rendering to preserve aspect ratios and prevent stretching when using the latest avatar crop format.

Review Change Stack


🔄 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/674 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/11/2026 **Status:** ✅ Merged **Merged:** 5/11/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/avatar-crop-rectangle-focal-point` --- ### 📝 Commits (1) - [`4d6314f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4d6314fdcfb1a515e6ad37a2702cdc74a09f9140) fix(avatar-crop): use focal-point object-position on RP rectangle and glued-panel avatars ### 📊 Changes **1 file changed** (+48 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+48 -7) </details> ### 📄 Description ## Linked issue Closes #673 ## Why this change PR #671 propagated the new source-rectangle avatar crop format through chat-side render sites. The format renders the `<img>` with `position: absolute`, `width: 100/srcWidth%`, `height: 100/srcHeight%`, and `object-fit: fill` — math that assumes the parent has the same aspect ratio as the (editor-enforced-square) crop. For RP-mode rectangular sites — "Small Rectangles" compact style and "Glued Side Panel" — the parent is non-square. `object-fit: fill` then stretched the cropped face to the rectangle's aspect ratio. Symptoms (visible only when the user has saved a new-format avatar crop): - Glued Side Panel: face squished horizontally or vertically depending on bubble height. - Small Rectangles: face squished vertically. - Short user messages in Glued Side Panel: the panel renders as a wide rectangle and `object-cover object-top` showed only the top of the source (e.g. just the character's hair). ## What changed In `packages/client/src/components/chat/ChatMessage.tsx`: - Add a `rectangleSafeCropStyle(crop, fallback)` helper that returns: - **Legacy** `{zoom, offsetX, offsetY}` crops → the fallback (unchanged transform-based path; composes with `object-cover`). - **New-format** crops → `{ objectPosition: 'X% Y%' }` derived from the crop's center, so `object-cover` keeps the user's chosen focal point centered in the rectangle. - Derive five styles from that helper: - `compactAvatarCropStyle` and `compactMergedAvatarCropStyle(avatar)` for `compactAvatarFrameClass` sites (gated on `useCompactRectangleAvatar` — the round Small Circles variant still uses the unmodified `avatarCropStyle`). - `panelAvatarCropStyle` and `panelMergedAvatarCropStyle(avatar)` for `rpg-avatar-panel-tail-image` and `rpg-avatar-panel-media` (always-rectangular sites). - Wire those into the six `<img>` sites in the file: - `rpg-avatar-panel-tail` single + merged (lines ~1146–1175). - `compactAvatarFrameClass` single + merged (lines ~1355–1400). - `rpg-avatar-panel-media` single + merged (lines ~1499–1542). Round/square frames (Small Circles compact style + Conversation Mode bubble `h-8 w-8 rounded-full`) continue to use the unchanged `avatarCropStyle`, which is PR #661's original logic — correct when parent matches crop aspect ratio. No data migration. Existing crops (both formats) render correctly without re-editing. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify a character with a new-format `avatarCrop` saved (square crop region of a non-square source) in **Small Rectangles** style: the side avatar tile renders the chosen face centered, no horizontal/vertical squish. - Manually verify the same character in **Glued Side Panel** style on both tall messages and short messages: the panel renders the face centered, no distortion, and short user-message panels (wide rectangles) center on the face instead of showing only the top of the source. - Manually verify a character with a **legacy** `{zoom, offsetX, offsetY}` crop renders identically to before in all three RP avatar styles — the customization should still apply via the unchanged transform path. - Manually verify **Small Circles** style and **Conversation Mode** chat bubbles still render new-format crops correctly with the unchanged PR #661 path (parent matches crop aspect ratio, no regression). - Manually verify a character with **no** `avatarCrop` extension renders identically to before in all styles (the helper returns the fallback unchanged for `null` crops). - Manually verify the user-side bubble in **Conversation Mode** still applies the persona crop on the round avatar (the persona-crop snapshot path from PR #671 is untouched). ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) Behavioral fix; the bug surface is identical to #673's repro steps. After: rectangles render the chosen face centered; no stretching, no banner-bleed on short messages. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved avatar image rendering to preserve aspect ratios and prevent stretching when using the latest avatar crop format. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/674) <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:07 +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#4724
No description provided.