Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 分享图片对齐聊天气泡样式

Dashcc85fb843229
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index 55c5c0bc6b..2d74ff7a02 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -729,6 +729,8 @@ import type { MobileCodexRateLimitsResult } from '@cindy/maker-shared/device-lin
import { useTranslation } from 'react-i18next';
import { i18n } from '@/i18n';
import { useTheme, useThemedStyles, type ThemeColors } from '@/theme';
+import { resolveMobileUserBubbleColors, useUserBubbleAppearance } from '@/theme/userBubblePreference';
+import { isOwnUserBubble } from '@/session/userBubbleOwnership';
import { fontWeight, iconSize, iconStroke, lineHeight, navigationChrome, radius, spacing, typeScale } from '@/theme/tokens';
const SESSION_ACTION_TEST_IDS = {
@@ -6130,17 +6132,21 @@ function SessionScreenContent() {
[messageListItems, shareSelectionActive],
);
const shareExpansionSnapshot = useFoldableExpandedBlocksSnapshot(shareExpandableBlockIds);
+ const viewerAccountId = auth.user?.id;
const shareMessages = useMemo(() => {
if (!shareSelectionActive) return [];
return collectConversationShareMessages(
messageListItems,
isFoldableBlockExpanded,
+ (message) => isOwnUserBubble(message, { accountId: viewerAccountId, remoteDeviceId: deviceId }),
);
}, [
+ deviceId,
i18nInstance.language,
messageListItems,
shareExpansionSnapshot,
shareSelectionActive,
+ viewerAccountId,
]);
const shareMessageById = useMemo(
() => new Map(shareMessages.map((message) => [message.clientId, message])),
@@ -6163,9 +6169,16 @@ function SessionScreenContent() {
.map((clientId) => shareMessageById.get(clientId))
.filter((message): message is ConversationShareMessage => message !== undefined);
}, [allShareableIds, shareMessageById, shareSelectionActive, shareSelectionRevision]);
+ const { preference: userBubblePreference } = useUserBubbleAppearance();
+ // 分享图与聊天气泡共用「我的消息气泡颜色」;按偏好 memo,避免每次渲染换新对象重排分享图。
+ const userBubbleColors = useMemo(
+ () => resolveMobileUserBubbleColors(userBubblePreference, mode, colors),
+ [colors, mode, userBubblePreference],
+ );
const conversationShareColors = useMemo<ConversationShareWebViewColors>(() => ({
background: colors.surface,
border: colors.border,
+ ownUserBubble: userBubbleColors,
codeSurface: colors.chatCodeSurface,
inlineCode: colors.chatInlineCodeText,
surfaceChip: colors.surfaceChip,
@@ -6182,7 +6195,7 @@ function SessionScreenContent() {
textSecondary: colors.textSecondary,
textTertiary: colors.textTertiary,
dark: mode === 'dark',
- }), [colors, mode]);
+ }), [colors, mode, userBubbleColors]);
const shareImages = useConversationShareImages(selectedShareMessages, resolveRemoteMedia, {
workdir: currentSession?.workingDir ?? undefined,
remoteHostId: currentSession?.remoteHostId ?? undefined,
diff --git a/apps/mobile/src/__tests__/conversationShareMessages.test.ts b/apps/mobile/src/__tests__/conversationShareMessages.test.ts
index c4a7c80071..143db8955f 100644
--- a/apps/mobile/src/__tests__/conversationShareMessages.test.ts
+++ b/apps/mobile/src/__tests__/conversationShareMessages.test.ts
@@ -139,3 +139,23 @@ describe('collectConversationShareMessages', () => {
]);
});
});
+
+describe('collectConversationShareMessages 气泡归属', () => {
+ it('只给判定为自己发的用户消息标记 ownUserBubble', () => {
+ const items = [
+ messageItem('mine', 'user'),
+ messageItem('guest', 'user', { sharedAuthorName: 'Guest' }),
+ messageItem('reply', 'assistant'),
+ ];
+ const messages = collectConversationShareMessages(
+ items,
+ () => false,
+ (message) => !message.sharedAuthorName,
+ );
+ expect(messages.map((message) => [message.clientId, message.ownUserBubble === true])).toEqual([
+ ['mine', true],
+ ['guest', false],
+ ['reply', false],
+ ]);
+ });
+});
diff --git a/apps/mobile/src/__tests__/conversationShareSvg.test.ts b/apps/mobile/src/__tests__/conversationShareSvg.test.ts
index 34b135b636..4335f6a376 100644
--- a/apps/mobile/src/__tests__/conversationShareSvg.test.ts
+++ b/apps/mobile/src/__tests__/conversationShareSvg.test.ts
@@ -457,3 +457,32 @@ describe("ConversationShareSvg", () => {
expect(renderSize.width).toBeLessThan(conversationShareSvgRenderSize(layout).width);
});
});
+
+describe("ConversationShareSvg 与聊天气泡同款渲染", () => {
+ const ownUserBubble = { background: "#e8f0ff", border: "#b5c8ef" };
+ const layout = buildConversationShareSvgLayout({
+ allShareableIds: ["short", "own", "multi"],
+ colors: { ...colors, ownUserBubble },
+ messages: [
+ { body: "短消息", clientId: "short", kind: "user" },
+ { body: "自己发的", clientId: "own", kind: "user", ownUserBubble: true },
+ { body: "第一行\n第二行", clientId: "multi", kind: "user" },
+ ],
+ width: 390,
+ });
+
+ it("用户气泡描边用边框色,自己的消息用气泡颜色", () => {
+ const [short, own, multi] = layout.bubbles;
+ expect(short).toMatchObject({ fill: colors.surfaceElevated, stroke: colors.border });
+ expect(own).toMatchObject({ fill: ownUserBubble.background, stroke: ownUserBubble.border });
+ expect(multi!.stroke).toBe(colors.border);
+ });
+
+ it("左右边距与消息流一致,短消息上下内边距更紧凑", () => {
+ const [short, , multi] = layout.bubbles;
+ expect(short!.x + short!.width).toBe(390 - 16);
+ expect(short!.textBlocks[0]!.y - short!.y).toBeLessThan(
+ multi!.textBlocks[0]!.y - multi!.y,
+ );
+ });
+});
diff --git a/apps/mobile/src/__tests__/conversationShareWebViewHtml.test.ts b/apps/mobile/src/__tests__/conversationShareWebViewHtml.test.ts
index 2c3002b388..206f0b4d5a 100644
--- a/apps/mobile/src/__tests__/conversationShareWebViewHtml.test.ts
+++ b/apps/mobile/src/__tests__/conversationShareWebViewHtml.test.ts
@@ -579,3 +579,51 @@ describe("buildConversationShareHtml 富内容导出", () => {
expect(html).not.toContain('share-bubble-user">');
});
});
+
+describe("buildConversationShareHtml 与聊天气泡同款渲染", () => {
+ const ownUserBubble = { background: "#e8f0ff", border: "#b5c8ef" };
+ const html = buildConversationShareHtml({
+ allShareableIds: ["short", "own", "multi"],
+ colors: { ...colors, ownUserBubble },
+ contentWidth: 390,
+ selectedMessages: [
+ { body: "短消息", clientId: "short", kind: "user" },
+ { body: "自己发的", clientId: "own", kind: "user", ownUserBubble: true },
+ { body: "第一行\n第二行", clientId: "multi", kind: "user" },
+ ],
+ });
+ const css = (selector: string) =>
+ html.match(new RegExp(`\\n\\s*${selector.replace(/\./g, "\\.")} \\{([^}]*)\\}`))?.[1] ?? "";
+
+ it("用户气泡用细描边与普通边框色,不用次要文字色的粗框", () => {
+ expect(css(".share-bubble-user")).toContain("border: 0.5px solid #dddddd");
+ expect(css(".share-bubble-user")).not.toContain("#555555");
+ });
+
+ it("左右边距与消息流一致,短消息气泡上下更紧凑", () => {
+ expect(css("#xdt-content.share-stage")).toContain("padding: 24px 16px");
+ expect(css(".share-bubble-user.share-bubble-compact")).toContain("padding: 8px 12px");
+ expect(html).toContain("share-bubble-user share-bubble-compact");
+ expect(html).toContain("share-bubble-user share-bubble-standard");
+ });
+
+ it("自己发的消息沿用「我的消息气泡颜色」", () => {
+ expect(css(".share-bubble-own")).toContain("background: #e8f0ff");
+ expect(css(".share-bubble-own")).toContain("border-color: #b5c8ef");
+ expect(html.match(/share-bubble-own"/g)).toHaveLength(1);
+ });
+
+ it("默认气泡外观不输出自定义颜色规则", () => {
+ const plain = buildConversationShareHtml({
+ allShareableIds: ["own"],
+ colors,
+ contentWidth: 390,
+ selectedMessages: [{ body: "x", clientId: "own", kind: "user", ownUserBubble: true }],
+ });
+ expect(plain).not.toContain(".share-bubble-own {");
+ });
+
+ it("段内换行像聊天里一样保留", () => {
+ expect(html).toMatch(/#xdt-content p,[^{]*\{\s*white-space: pre-wrap;/);
+ });
+});
diff --git a/apps/mobile/src/session/ConversationShareSvg.tsx b/apps/mobile/src/session/ConversationShareSvg.tsx
index 788b2d655a..ccd06a4b8c 100644
--- a/apps/mobile/src/session/ConversationShareSvg.tsx
+++ b/apps/mobile/src/session/ConversationShareSvg.tsx
@@ -16,9 +16,10 @@ import Svg, {
TSpan,
} from "react-native-svg";
-import type {
- ConversationShareMessage,
- ConversationShareWebViewColors,
+import {
+ CONVERSATION_SHARE_HAIRLINE,
+ type ConversationShareMessage,
+ type ConversationShareWebViewColors,
} from "@/session/conversationShareWebViewHtml";
import { createConversationShareAssetGate } from "@/session/conversationShareAssetGate";
import {
@@ -44,8 +45,9 @@ const SHARE_LOCKUP_GAP = 6;
const SHARE_EXPORT_TIMEOUT_MS = 20_000;
// Leave time within the existing export deadline for fallback layout + capture.
const SHARE_DECODE_TIMEOUT_MS = 15_000;
-// Export-card geometry: this is a 1px bubble border in the SVG coordinate
-// system, not a Lucide icon stroke (whose thinnest token is intentionally 1.75).
+// Export-card geometry: a 1px code/table border in the SVG coordinate system,
+// not a Lucide icon stroke (whose thinnest token is intentionally 1.75). Message
+// bubbles use the chat's hairline instead.
const SHARE_BUBBLE_STROKE_WIDTH = 1;
export const ConversationShareSvg = forwardRef<
@@ -385,7 +387,7 @@ function SvgBubbleView({ bubble }: { bubble: ConversationShareSvgBubble }) {
height={bubble.height}
rx={12}
stroke={bubble.stroke}
- strokeWidth={bubble.stroke ? SHARE_BUBBLE_STROKE_WIDTH : undefined}
+ strokeWidth={bubble.stroke ? CONVERSATION_SHARE_HAIRLINE : undefined}
width={bubble.width}
x={bubble.x}
y={bubble.y}
diff --git a/apps/mobile/src/session/conversationShareMessages.ts b/apps/mobile/src/session/conversationShareMessages.ts
index abacdde8d3..3b40cbbbaa 100644
--- a/apps/mobile/src/session/conversationShareMessages.ts
+++ b/apps/mobile/src/session/conversationShareMessages.ts
@@ -1,3 +1,4 @@
+import type { NormalizedRemoteMessage } from '@/session/messageNormalize';
import type {
MobileMessageRenderItem,
MobileWorkChildItem,
@@ -45,6 +46,8 @@ export function collectConversationShareBlockIds(
export function collectConversationShareMessages(
items: readonly MobileMessageRenderItem[],
isBlockExpanded: (blockId: string) => boolean,
+ /** 与聊天气泡同一判据:自己发的消息才用「我的消息气泡颜色」。 */
+ isOwnUserMessage?: (message: NormalizedRemoteMessage) => boolean,
): ConversationShareMessage[] {
const messages: ConversationShareMessage[] = [];
const visit = (item: ConversationShareRenderItem): void => {
@@ -67,6 +70,9 @@ export function collectConversationShareMessages(
maxVisibleLines,
visualLineCapacity: maxVisibleLines ? MIN_HALF_WIDTH_UNITS_PER_VISUAL_LINE : undefined,
});
+ if (projected?.kind === 'user' && isOwnUserMessage?.(item.message)) {
+ projected.ownUserBubble = true;
+ }
if (projected) messages.push(projected);
return;
}
diff --git a/apps/mobile/src/session/conversationShareSvgLayout.ts b/apps/mobile/src/session/conversationShareSvgLayout.ts
index 3057ef9620..b13584788f 100644
--- a/apps/mobile/src/session/conversationShareSvgLayout.ts
+++ b/apps/mobile/src/session/conversationShareSvgLayout.ts
@@ -1,4 +1,5 @@
import { redactSensitiveText } from "@cindy/maker-shared/error-redaction";
+import { summarizeMessageBubblePresentation } from "@cindy/maker-shared/message-presentation";
import { i18n } from "@/i18n";
import {
@@ -12,14 +13,19 @@ import {
type MobileMarkdownBlock,
type MobileMarkdownInline,
} from "@/session/messageMarkdown";
-import type {
- ConversationShareMessage,
- ConversationShareImage,
- ConversationShareWebViewColors,
+import {
+ CONVERSATION_SHARE_PADDING_X,
+ CONVERSATION_SHARE_PADDING_Y,
+ type ConversationShareMessage,
+ type ConversationShareImage,
+ type ConversationShareWebViewColors,
} from "@/session/conversationShareWebViewHtml";
+import { buildMessageContentLayout } from "@/session/messageContentLayout";
+import { spacing } from "@/theme/tokens";
-const PADDING = 28;
-const MESSAGE_GAP = 16;
+const PADDING_X = CONVERSATION_SHARE_PADDING_X;
+const PADDING_Y = CONVERSATION_SHARE_PADDING_Y;
+const MESSAGE_GAP = spacing.lg;
const TEXT_FONT_SIZE = 15;
const TEXT_LINE_HEIGHT = 22;
const META_FONT_SIZE = 12;
@@ -102,13 +108,14 @@ export function buildConversationShareSvgLayout({
width: number;
}): ConversationShareSvgLayout {
const canvasWidth = Math.max(280, Math.round(width));
- const contentWidth = canvasWidth - PADDING * 2;
+ const contentWidth = canvasWidth - PADDING_X * 2;
+ const contentLayout = buildMessageContentLayout({ screenWidth: canvasWidth });
const bubbles: ConversationShareSvgBubble[] = [];
const images: ConversationShareSvgLayout["images"] = [];
const gaps: Array<{ color: string; y: number }> = [];
const messageIndex = new Map(allShareableIds.map((id, index) => [id, index]));
let previousIndex: number | null = null;
- let cursorY = PADDING;
+ let cursorY = PADDING_Y;
for (const message of messages) {
const currentIndex = messageIndex.get(message.clientId) ?? null;
@@ -122,8 +129,23 @@ export function buildConversationShareSvgLayout({
}
const user = message.kind === "user";
const bubbleWidth = user ? Math.round(contentWidth * 0.86) : contentWidth;
- const bubbleX = user ? canvasWidth - PADDING - bubbleWidth : PADDING;
- const horizontalPadding = user ? 12 : 0;
+ const bubbleX = user ? canvasWidth - PADDING_X - bubbleWidth : PADDING_X;
+ const horizontalPadding = user ? spacing.md : 0;
+ // 与聊天气泡一致:短消息上下 8,其余 12;助手回复无框,上下 4。
+ const compact =
+ summarizeMessageBubblePresentation({
+ attachmentCount: message.attachments?.length ?? 0,
+ body: message.body,
+ kind: message.kind,
+ secondaryBody: message.secondaryBody,
+ }).density === "compact";
+ const paddingY = user ? (compact ? spacing.sm : spacing.md) : spacing.xs;
+ const minBubbleHeight = user ? 20 + paddingY * 2 : 30;
+ const ownBubble = user && message.ownUserBubble ? colors.ownUserBubble : null;
+ const bubbleFill = user
+ ? (ownBubble?.background ?? colors.surfaceElevated)
+ : undefined;
+ const bubbleStroke = user ? (ownBubble?.border ?? colors.border) : undefined;
const textWidth = bubbleWidth - horizontalPadding * 2;
const appendMetadata = (text: string, color: string, gap: number) => {
const lines = wrapSvgText(
@@ -154,14 +176,18 @@ export function buildConversationShareSvgLayout({
// their own occurrence rather than moving into the bubble. Share images
// carry no message-source labels (automation / device / plugin / author).
const appendImage = (image: ConversationShareImage) => {
- const scale = Math.min(1, bubbleWidth / image.width, 320 / image.height);
+ const scale = Math.min(
+ 1,
+ contentLayout.attachmentImageMaxWidth / image.width,
+ contentLayout.attachmentImageMaxHeight / image.height,
+ );
const imageWidth = image.width * scale;
const imageHeight = image.height * scale;
images.push({
uri: image.uri,
width: imageWidth,
height: imageHeight,
- x: user ? canvasWidth - PADDING - imageWidth : PADDING,
+ x: user ? canvasWidth - PADDING_X - imageWidth : PADDING_X,
y: cursorY,
});
cursorY += imageHeight + MESSAGE_GAP;
@@ -188,7 +214,6 @@ export function buildConversationShareSvgLayout({
// Preserve the existing whole-message redaction path for secrets spanning
// formatting, paragraphs or images. Never redact isolated styled runs.
if (!needsRedaction && bodyParts.length > 0) {
- const paddingY = user ? 12 : 4;
const body = layoutConversationShareRichBody(
message,
colors,
@@ -196,14 +221,14 @@ export function buildConversationShareSvgLayout({
cursorY + paddingY,
textWidth,
);
- const height = Math.max(user ? 44 : 30, body.height + paddingY * 2);
+ const height = Math.max(minBubbleHeight, body.height + paddingY * 2);
bubbles.push({
x: bubbleX,
y: cursorY,
width: bubbleWidth,
height,
- fill: user ? colors.surfaceElevated : undefined,
- stroke: user ? colors.textSecondary : undefined,
+ fill: bubbleFill,
+ stroke: bubbleStroke,
textBlocks: body.textBlocks,
rectangles: body.rectangles,
});
@@ -234,7 +259,7 @@ export function buildConversationShareSvgLayout({
}
const textBlocks: ConversationShareSvgTextBlock[] = [];
- let innerY = user ? 12 : 4;
+ let innerY = paddingY;
for (const block of blocks) {
if ("image" in block) {
const scale = Math.min(
@@ -265,12 +290,12 @@ export function buildConversationShareSvgLayout({
innerY += lines.length * block.lineHeight + 5;
}
if (blocks.length > 0) innerY -= 5;
- const bubbleHeight = Math.max(user ? 44 : 30, innerY + (user ? 12 : 4));
+ const bubbleHeight = Math.max(minBubbleHeight, innerY + paddingY);
if (blocks.length > 0)
bubbles.push({
- fill: user ? colors.surfaceElevated : undefined,
+ fill: bubbleFill,
height: bubbleHeight,
- stroke: user ? colors.textSecondary : undefined,
+ stroke: bubbleStroke,
textBlocks,
width: bubbleWidth,
x: bubbleX,
@@ -286,7 +311,7 @@ export function buildConversationShareSvgLayout({
images,
footerY,
gaps,
- height: footerY + 22 + PADDING,
+ height: footerY + 22 + PADDING_Y,
width: canvasWidth,
};
}
diff --git a/apps/mobile/src/session/conversationShareWebViewHtml.ts b/apps/mobile/src/session/conversationShareWebViewHtml.ts
index 07ed01b5b6..383273fc02 100644
--- a/apps/mobile/src/session/conversationShareWebViewHtml.ts
+++ b/apps/mobile/src/session/conversationShareWebViewHtml.ts
@@ -1,4 +1,5 @@
import { redactSensitiveText } from "@cindy/maker-shared/error-redaction";
+import { summarizeMessageBubblePresentation } from "@cindy/maker-shared/message-presentation";
import { buildKatexLoaderJs } from "@/session/mathWebViewHtml";
import { buildMermaidLoaderJs } from "@/session/mermaidWebViewHtml";
import {
@@ -8,7 +9,7 @@ import {
} from "@/session/selectableMarkdownHtml";
import { buildMessageContentLayout } from "@/session/messageContentLayout";
import { collectMobileMarkdownImages } from "@/session/messageMarkdown";
-import { lineHeight, typeScale } from "@/theme/tokens";
+import { lineHeight, radius, spacing, typeScale } from "@/theme/tokens";
/** 分享图只含消息内容:不带任何消息来源(自动化 / 任务 / 设备 / 插件 / 作者)。 */
export interface ConversationShareMessage {
@@ -18,6 +19,8 @@ export interface ConversationShareMessage {
body: string;
bodyParts?: readonly ConversationShareBodyPart[];
secondaryBody?: string;
+ /** 自己发的消息:聊天里按「我的消息气泡颜色」着色,分享图同样着色。 */
+ ownUserBubble?: boolean;
/** Export-only decoded images, keyed by attachment/Markdown source. */
images?: ReadonlyMap<string, ConversationShareImage>;
}
@@ -48,6 +51,8 @@ export interface ConversationShareWebViewColors {
textPrimary: string;
textSecondary: string;
textTertiary: string;
+ /** 「我的消息气泡颜色」;默认外观为 null,沿用 surfaceElevated / border。 */
+ ownUserBubble?: { background: string; border: string } | null;
dark?: boolean;
syntax: NonNullable<SelectableMarkdownHtmlOptions["syntaxColors"]>;
}
@@ -61,6 +66,12 @@ export interface BuildConversationShareHtmlOptions {
selectedMessages: readonly ConversationShareMessage[];
}
+/** 左右边距与聊天消息流一致(spacing.lg),同一屏宽下换行位置相同;上下留白给分享卡片。 */
+export const CONVERSATION_SHARE_PADDING_X = spacing.lg;
+export const CONVERSATION_SHARE_PADDING_Y = spacing.xl;
+/** 气泡与 chip 描边对应聊天里的 StyleSheet.hairlineWidth。 */
+export const CONVERSATION_SHARE_HAIRLINE = 0.5;
+
export function buildConversationShareHtml({
allShareableIds,
characterSrc,
@@ -110,7 +121,7 @@ export function buildConversationShareHtml({
'<meta charset="utf-8">',
'<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">',
"<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; font-src data:; object-src 'none'; base-uri 'none'; form-action 'none';\">",
- `<style id="share-style">${markdownCss}${buildConversationShareCss({ background, border: colors.border, surfaceChip: colors.surfaceChip, surfaceElevated: colors.surfaceElevated, textPrimary: colors.textPrimary, textSecondary: colors.textSecondary, textTertiary: colors.textTertiary, width })}</style>`,
+ `<style id="share-style">${markdownCss}${buildConversationShareCss({ background, border: colors.border, ownUserBubble: colors.ownUserBubble ?? null, surfaceChip: colors.surfaceChip, surfaceElevated: colors.surfaceElevated, textPrimary: colors.textPrimary, textSecondary: colors.textSecondary, textTertiary: colors.textTertiary, width })}</style>`,
"</head>",
"<body>",
`<main id="xdt-content" class="share-stage" data-share-background="${escapeAttribute(background)}">`,
@@ -169,11 +180,20 @@ function buildMessageHtml(
message.attachments ?? [],
message.images,
);
+ // 与聊天气泡同一套疏密档:短消息上下更紧凑,带附件 / 补充说明时间距更大。
+ const density = summarizeMessageBubblePresentation({
+ attachmentCount: message.attachments?.length ?? 0,
+ body: message.body,
+ kind: message.kind,
+ secondaryBody: message.secondaryBody,
+ }).density;
+ const ownBubbleClass =
+ message.kind === "user" && message.ownUserBubble ? " share-bubble-own" : "";
const bubbleHtml =
bodyHtml || secondaryHtml
? [
- `<div class="share-bubble share-bubble-${message.kind}">`,
- bodyHtml,
+ `<div class="share-bubble share-bubble-${message.kind} share-bubble-${density}${ownBubbleClass}">`,
+ bodyHtml ? `<div class="share-bubble-body">${bodyHtml}</div>` : "",
secondaryHtml
? `<div class="share-secondary">${secondaryHtml}</div>`
: "",
@@ -258,6 +278,7 @@ function buildConversationShareMarkdownOptions(
function buildConversationShareCss({
background,
border,
+ ownUserBubble,
surfaceChip,
surfaceElevated,
textPrimary,
@@ -267,6 +288,7 @@ function buildConversationShareCss({
}: {
background: string;
border: string;
+ ownUserBubble: { background: string; border: string } | null;
surfaceChip: string;
surfaceElevated: string;
textPrimary: string;
@@ -274,9 +296,9 @@ function buildConversationShareCss({
textTertiary: string;
width: number;
}): string {
- const bodyGap = buildMessageContentLayout({
- screenWidth: width,
- }).markdownBodyGap;
+ // 尺寸与间距照搬聊天消息流(MessageRenderer):同屏宽下换行、气泡与附件一致。
+ const layout = buildMessageContentLayout({ screenWidth: width });
+ const bodyGap = layout.markdownBodyGap;
return `
html, body {
margin: 0;
@@ -291,15 +313,16 @@ function buildConversationShareCss({
flex-direction: column;
width: ${width}px;
min-width: ${width}px;
- padding: 28px;
+ padding: ${CONVERSATION_SHARE_PADDING_Y}px ${CONVERSATION_SHARE_PADDING_X}px;
background: ${background};
color: ${cssValue(textPrimary)};
- gap: 16px;
+ gap: ${spacing.lg}px;
overflow: visible;
}
.share-message {
display: flex;
flex-direction: column;
+ gap: 2px;
width: 100%;
min-width: 0;
}
@@ -308,33 +331,33 @@ function buildConversationShareCss({
.share-attachments {
display: flex;
flex-direction: column;
- gap: 8px;
- max-width: 86%;
- margin-bottom: 4px;
+ gap: ${layout.attachmentGap}px;
+ max-width: 100%;
+ margin-bottom: ${spacing.xs}px;
}
.share-message-user .share-attachments { align-items: flex-end; }
.share-message-assistant .share-attachments { align-items: flex-start; }
.share-attachment-image {
display: block;
- max-width: 100%;
- max-height: 320px;
+ max-width: ${layout.attachmentImageMaxWidth}px;
+ max-height: ${layout.attachmentImageMaxHeight}px;
object-fit: contain;
- border-radius: 12px;
+ border-radius: ${radius.container}px;
}
.share-attachment-chip {
box-sizing: border-box;
display: flex;
align-items: center;
- gap: 8px;
- min-height: 32px;
- max-width: 228px;
- padding: 5px 10px;
- border: 1px solid ${cssValue(border)};
- border-radius: 9999px;
+ gap: ${spacing.xs}px;
+ min-height: ${layout.fileChipMinHeight}px;
+ max-width: ${layout.fileChipMaxWidth}px;
+ padding: 0 ${spacing.sm}px;
+ border-radius: ${radius.pill}px;
background: ${cssValue(surfaceChip)};
color: ${cssValue(textPrimary)};
- font-size: 12px;
- line-height: 18px;
+ font-size: ${typeScale.caption}px;
+ font-weight: 500;
+ line-height: ${lineHeight.caption}px;
}
.share-attachment-icon {
position: relative;
@@ -342,6 +365,7 @@ function buildConversationShareCss({
width: 15px;
height: 17px;
flex: 0 0 15px;
+ margin: 0 ${(layout.fileChipIconWidth - 15) / 2}px;
border: 1.5px solid ${cssValue(textSecondary)};
border-radius: 3px;
}
@@ -367,24 +391,42 @@ function buildConversationShareCss({
min-width: 0;
display: flex;
flex-direction: column;
- gap: ${bodyGap}px;
+ gap: ${spacing.xs}px;
}
+ .share-bubble-compact { gap: 6px; }
+ .share-bubble-rich { gap: ${spacing.sm}px; }
.share-bubble-user {
max-width: 86%;
- padding: 12px;
- border: 1px solid ${cssValue(textSecondary)};
- border-radius: 12px;
+ padding: ${spacing.md}px;
+ border: ${CONVERSATION_SHARE_HAIRLINE}px solid ${cssValue(border)};
+ border-radius: ${radius.container}px;
background: ${cssValue(surfaceElevated)};
}
+ .share-bubble-user.share-bubble-compact {
+ padding: ${spacing.sm}px ${spacing.md}px;
+ }
+ ${
+ ownUserBubble
+ ? `.share-bubble-own {
+ border-color: ${cssValue(ownUserBubble.border)};
+ background: ${cssValue(ownUserBubble.background)};
+ }`
+ : ""
+ }
.share-bubble-assistant {
width: 100%;
- padding: 4px 0;
+ padding: ${spacing.xs}px 0;
}
.share-secondary {
- margin-top: 8px;
color: ${cssValue(textSecondary)};
}
- .share-secondary, .share-content-text {
+ /* 聊天正文按原文换行(RN Text 保留段内换行),HTML 默认会把它折叠成空格。 */
+ #xdt-content p, #xdt-content h1, #xdt-content h2, #xdt-content h3,
+ #xdt-content h4, #xdt-content h5, #xdt-content h6,
+ #xdt-content blockquote, #xdt-content .list-text {
+ white-space: pre-wrap;
+ }
+ .share-bubble-body, .share-secondary, .share-content-text {
display: flex;
flex-direction: column;
gap: ${bodyGap}px;
@@ -393,7 +435,7 @@ function buildConversationShareCss({
display: flex;
align-items: center;
flex-wrap: wrap;
- gap: 4px;
+ gap: ${spacing.xs}px;
max-width: 100%;
}
.share-content-text {
@@ -407,13 +449,13 @@ function buildConversationShareCss({
align-items: center;
gap: 6px;
max-width: 240px;
- padding: 2px 8px;
- border: 1px solid ${cssValue(border)};
- border-radius: 9999px;
+ padding: 2px ${spacing.sm}px;
+ border: ${CONVERSATION_SHARE_HAIRLINE}px solid ${cssValue(border)};
+ border-radius: ${radius.pill}px;
background: ${cssValue(surfaceChip)};
color: ${cssValue(textPrimary)};
- font-size: 12px;
- line-height: 18px;
+ font-size: ${typeScale.caption}px;
+ line-height: ${lineHeight.bodySmall}px;
}
.share-inline-chip-icon {
flex: 0 0 auto;