You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1145 lines
31 KiB
1145 lines
31 KiB
/**
|
|
* 样式注入模块 - CSS 自动注入,csk- 命名空间隔离
|
|
*
|
|
* 设计语言:现代克制、柔和阴影、圆角气泡、主色渐变、入场动效。
|
|
* 主题色由配置驱动,通过 CSS 变量透传,可在运行时热替换。
|
|
*/
|
|
import { ResolvedConfig } from './types';
|
|
|
|
let styleElement: HTMLStyleElement | null = null;
|
|
|
|
/** 将 hex 颜色解析为 "r, g, b" 字符串,用于 rgba() 拼接 */
|
|
function hexToRgb(hex: string): string {
|
|
const match = hex.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
|
if (!match) return '79, 70, 229';
|
|
return `${parseInt(match[1], 16)}, ${parseInt(match[2], 16)}, ${parseInt(match[3], 16)}`;
|
|
}
|
|
|
|
/** CSS 变量:将配置中的主题色转换为 CSS 自定义属性 */
|
|
function cssVars(config: ResolvedConfig): string {
|
|
const darker = adjustColor(config.primaryColor, -15);
|
|
const lighter = adjustColor(config.primaryColor, 18);
|
|
const rgb = hexToRgb(config.primaryColor);
|
|
|
|
return `
|
|
--csk-primary: ${config.primaryColor};
|
|
--csk-primary-hover: ${darker};
|
|
--csk-primary-light: ${lighter};
|
|
--csk-primary-rgb: ${rgb};
|
|
--csk-bg-user: linear-gradient(135deg, ${config.primaryColor}, ${darker});
|
|
--csk-bg-ai: #F3F3F3;
|
|
--csk-text-user: #ffffff;
|
|
--csk-text-ai: rgba(0, 0, 0, 0.9);
|
|
--csk-window-width: ${config.width}px;
|
|
--csk-window-height: ${config.height}px;
|
|
--csk-radius: 16px;
|
|
--csk-shadow-window: 0 12px 48px rgba(15, 23, 42, 0.18), 0 2px 8px rgba(15, 23, 42, 0.06);
|
|
--csk-shadow-bubble: 0 1px 10px rgba(0, 0, 0, 0.05), 0 4px 5px rgba(0, 0, 0, 0.08);
|
|
--csk-border: #E8E8E8;
|
|
--csk-border-strong: #DDDDDD;
|
|
--csk-text-secondary: rgba(0, 0, 0, 0.6);
|
|
--csk-text-muted: rgba(0, 0, 0, 0.4);
|
|
--csk-bg-app: #FFFFFF;
|
|
/* TDesign 组件品牌色覆盖:让 primaryColor 透传到 t-chat-item/t-chat-sender/t-tag 等 */
|
|
/* CSS 变量会穿透 shadow DOM,故在 .csk-root 上定义即可被内部组件继承 */
|
|
--td-brand-color: ${config.primaryColor};
|
|
--td-brand-color-hover: ${darker};
|
|
--td-brand-color-active: ${darker};
|
|
--td-brand-color-focus: ${config.primaryColor};
|
|
--td-brand-color-disabled: ${lighter};
|
|
--td-brand-color-light: ${lighter};
|
|
--td-brand-color-light-hover: ${lighter};
|
|
/* 覆盖 TDesign chat-item 默认 800px 限制,使 AI 回复内容自适应 SDK 弹窗宽度 */
|
|
--td-chat-item-content-max-width: 100%;
|
|
/* 压缩输入组件:缩小内容区上下 padding 与字号(变量穿透 shadow DOM 生效于 t-chat-sender) */
|
|
--td-chat-input-padding: 8px 12px;
|
|
--td-chat-input-font-size: 14px;
|
|
`;
|
|
}
|
|
|
|
/** 简单的颜色加深(按通道加减) */
|
|
function adjustColor(hex: string, amount: number): string {
|
|
const match = hex.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
|
if (!match) {
|
|
return hex;
|
|
}
|
|
const clamp = (v: number) => Math.max(0, Math.min(255, v));
|
|
const r = clamp(parseInt(match[1], 16) + amount);
|
|
const g = clamp(parseInt(match[2], 16) + amount);
|
|
const b = clamp(parseInt(match[3], 16) + amount);
|
|
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
|
|
}
|
|
|
|
/** 完整 CSS 样式表 */
|
|
function getStyles(config: ResolvedConfig): string {
|
|
return `
|
|
/* ChatbotSDK 样式 - csk- 命名空间 */
|
|
.csk-root {
|
|
${cssVars(config)}
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
|
|
font-size: 14px;
|
|
line-height: 1.55;
|
|
color: #1F2937;
|
|
-webkit-font-smoothing: antialiased;
|
|
-moz-osx-font-smoothing: grayscale;
|
|
box-sizing: border-box;
|
|
}
|
|
.csk-root *, .csk-root *::before, .csk-root *::after { box-sizing: border-box; }
|
|
|
|
/* ========== 悬浮按钮 ========== */
|
|
.csk-launcher {
|
|
position: fixed;
|
|
bottom: 24px;
|
|
z-index: 9998;
|
|
width: 60px;
|
|
height: 60px;
|
|
border-radius: 50%;
|
|
/* 白色背景,简洁克制 */
|
|
background: #ffffff;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
cursor: pointer;
|
|
color: #fff;
|
|
user-select: none;
|
|
overflow: hidden;
|
|
/* 浅灰边框 */
|
|
border: 2px solid #E5E7EB;
|
|
/* 简洁柔和阴影 */
|
|
box-shadow:
|
|
0 2px 8px rgba(0, 0, 0, 0.08),
|
|
0 4px 16px rgba(0, 0, 0, 0.06);
|
|
transition:
|
|
transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
|
|
box-shadow 0.25s ease,
|
|
border-color 0.25s ease;
|
|
animation:
|
|
csk-launcher-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
|
|
}
|
|
.csk-launcher--right { right: 24px; }
|
|
.csk-launcher--left { left: 24px; }
|
|
|
|
.csk-launcher:hover {
|
|
transform: translateY(-3px) scale(1.08);
|
|
border-color: #D1D5DB;
|
|
box-shadow:
|
|
0 4px 12px rgba(0, 0, 0, 0.10),
|
|
0 8px 24px rgba(0, 0, 0, 0.08);
|
|
}
|
|
.csk-launcher:active { transform: scale(0.93); }
|
|
.csk-launcher svg {
|
|
width: 30px;
|
|
height: 30px;
|
|
position: relative;
|
|
z-index: 1;
|
|
filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
|
|
}
|
|
.csk-launcher img {
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
position: relative;
|
|
z-index: 1;
|
|
-webkit-user-drag: none;
|
|
user-select: none;
|
|
}
|
|
|
|
@keyframes csk-launcher-in {
|
|
0% { opacity: 0; transform: scale(0.5) translateY(16px); }
|
|
60% { transform: scale(1.06) translateY(-2px); }
|
|
100% { opacity: 1; transform: scale(1) translateY(0); }
|
|
}
|
|
|
|
/* ========== 聊天弹窗 ========== */
|
|
.csk-window {
|
|
position: fixed;
|
|
bottom: 24px;
|
|
z-index: 9999;
|
|
width: var(--csk-window-width);
|
|
height: var(--csk-window-height);
|
|
max-height: calc(100vh - 48px);
|
|
background: #fff;
|
|
border-radius: var(--csk-radius);
|
|
box-shadow: var(--csk-shadow-window);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
transform-origin: bottom right;
|
|
transition: opacity 0.24s ease, transform 0.24s cubic-bezier(0.34, 1.2, 0.64, 1), visibility 0.24s;
|
|
opacity: 1;
|
|
transform: translateY(0) scale(1);
|
|
visibility: visible;
|
|
pointer-events: auto;
|
|
}
|
|
.csk-window--right { right: 24px; transform-origin: bottom right; }
|
|
.csk-window--left { left: 24px; transform-origin: bottom left; }
|
|
.csk-window--hidden {
|
|
opacity: 0;
|
|
transform: translateY(12px) scale(0.96);
|
|
visibility: hidden;
|
|
pointer-events: none;
|
|
}
|
|
|
|
/* ========== 水印层 ========== */
|
|
.csk-watermark {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
pointer-events: none;
|
|
user-select: none;
|
|
z-index: 0;
|
|
background-repeat: repeat;
|
|
opacity: 0.8;
|
|
}
|
|
|
|
/* ========== 头部 ========== */
|
|
.csk-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 12px 16px;
|
|
min-height: 60px;
|
|
background: var(--csk-bg-user);
|
|
color: #fff;
|
|
cursor: move;
|
|
user-select: none;
|
|
position: relative;
|
|
flex-shrink: 0;
|
|
}
|
|
.csk-header::after {
|
|
content: '';
|
|
position: absolute;
|
|
left: 0; right: 0; bottom: 0;
|
|
height: 24px;
|
|
background: linear-gradient(to bottom, rgba(0,0,0,0.04), transparent);
|
|
pointer-events: none;
|
|
}
|
|
.csk-header__left {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
min-width: 0;
|
|
}
|
|
.csk-header__avatar {
|
|
width: 38px;
|
|
height: 38px;
|
|
border-radius: 50%;
|
|
background: rgba(255, 255, 255, 0.22);
|
|
backdrop-filter: blur(4px);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex-shrink: 0;
|
|
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
|
|
}
|
|
.csk-header__avatar svg { width: 22px; height: 22px; }
|
|
.csk-header__info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-width: 0;
|
|
}
|
|
.csk-header__title {
|
|
font-size: 15px;
|
|
font-weight: 600;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
letter-spacing: 0.2px;
|
|
}
|
|
.csk-header__status {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 5px;
|
|
font-size: 11.5px;
|
|
opacity: 0.9;
|
|
margin-top: 2px;
|
|
}
|
|
.csk-status-dot {
|
|
width: 7px;
|
|
height: 7px;
|
|
border-radius: 50%;
|
|
background: #6EE7B7;
|
|
box-shadow: 0 0 0 0 rgba(110, 231, 183, 0.7);
|
|
animation: csk-status-pulse 2s infinite;
|
|
}
|
|
@keyframes csk-status-pulse {
|
|
0% { box-shadow: 0 0 0 0 rgba(110, 231, 183, 0.7); }
|
|
70% { box-shadow: 0 0 0 6px rgba(110, 231, 183, 0); }
|
|
100% { box-shadow: 0 0 0 0 rgba(110, 231, 183, 0); }
|
|
}
|
|
.csk-header__actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 2px;
|
|
flex-shrink: 0;
|
|
}
|
|
.csk-header__btn,
|
|
.csk-history-btn {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 32px;
|
|
height: 32px;
|
|
border: none;
|
|
background: transparent;
|
|
color: #fff;
|
|
cursor: pointer;
|
|
border-radius: 8px;
|
|
transition: background 0.15s, transform 0.15s;
|
|
}
|
|
.csk-header__btn:hover,
|
|
.csk-history-btn:hover {
|
|
background: rgba(255, 255, 255, 0.2);
|
|
}
|
|
.csk-header__btn:active,
|
|
.csk-history-btn:active { transform: scale(0.92); }
|
|
|
|
/* ========== 角色选择器 ========== */
|
|
.csk-role-select-wrap {
|
|
display: flex;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
margin: 0 4px;
|
|
}
|
|
|
|
/* ========== 消息区 ========== */
|
|
.csk-messages {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 16px;
|
|
background: var(--csk-bg-app);
|
|
scroll-behavior: smooth;
|
|
}
|
|
.csk-messages::-webkit-scrollbar { width: 6px; }
|
|
.csk-messages::-webkit-scrollbar-track { background: transparent; }
|
|
.csk-messages::-webkit-scrollbar-thumb {
|
|
background: #D8DCE3;
|
|
border-radius: 3px;
|
|
}
|
|
.csk-messages::-webkit-scrollbar-thumb:hover { background: #C2C7D0; }
|
|
|
|
/* 欢迎空状态 */
|
|
.csk-welcome {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
text-align: center;
|
|
padding: 48px 24px 32px;
|
|
color: #6B7280;
|
|
animation: csk-fade-in 0.3s ease;
|
|
}
|
|
.csk-welcome__avatar {
|
|
width: 56px;
|
|
height: 56px;
|
|
border-radius: 50%;
|
|
background: var(--csk-bg-user);
|
|
color: #fff;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin-bottom: 14px;
|
|
box-shadow: 0 6px 18px rgba(var(--csk-primary-rgb), 0.3);
|
|
}
|
|
.csk-welcome__avatar svg { width: 30px; height: 30px; }
|
|
.csk-welcome__title {
|
|
font-size: 15px;
|
|
font-weight: 600;
|
|
color: #1F2937;
|
|
margin-bottom: 4px;
|
|
}
|
|
.csk-welcome__desc {
|
|
font-size: 13px;
|
|
color: #9CA3AF;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
/* 消息气泡 */
|
|
/* 注意:.csk-msg 为块级纵向容器。头像 + 气泡的横向对齐由 t-chat-item 内部(placement 属性)完成,
|
|
sources / suggestions 直接 append 到 wrapper 末尾,须纵向堆叠在气泡下方,不能用 flex row 排布 */
|
|
.csk-msg {
|
|
margin-bottom: 16px;
|
|
max-width: 100%;
|
|
word-break: break-word;
|
|
animation: csk-msg-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
|
|
}
|
|
|
|
@keyframes csk-msg-in {
|
|
from { opacity: 0; transform: translateY(8px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
@keyframes csk-fade-in {
|
|
from { opacity: 0; }
|
|
to { opacity: 1; }
|
|
}
|
|
|
|
/* ========== 输入区 ========== */
|
|
.csk-input-area {
|
|
padding: 8px 12px 10px;
|
|
background: #fff;
|
|
border-top: 1px solid var(--csk-border);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
/* ========== 保密声明脚注 ========== */
|
|
.csk-disclaimer {
|
|
margin-top: 4px;
|
|
padding: 4px 8px 2px;
|
|
font-size: 10px;
|
|
color: #9CA3AF;
|
|
line-height: 1.4;
|
|
user-select: none;
|
|
cursor: pointer;
|
|
}
|
|
.csk-disclaimer__title {
|
|
font-weight: 600;
|
|
margin-bottom: 2px;
|
|
color: #9CA3AF;
|
|
}
|
|
/* 折叠态:默认只显示首行(标题),其余条文隐藏;标题末尾加 ▾ 提示可展开 */
|
|
.csk-disclaimer > :not(:first-child) { display: none; }
|
|
.csk-disclaimer > :first-child::after { content: ' ▾'; }
|
|
.csk-disclaimer--expanded > :not(:first-child) { display: block; }
|
|
.csk-disclaimer--expanded > :first-child::after { content: ' ▴'; }
|
|
.csk-dark .csk-disclaimer { color: #6B7280; }
|
|
.csk-dark .csk-disclaimer__title { color: #6B7280; }
|
|
|
|
/* ========== 新对话按钮 ========== */
|
|
.csk-clear-btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 5px;
|
|
padding: 5px 12px;
|
|
border: 1px solid var(--csk-border);
|
|
border-radius: 999px;
|
|
background: #fff;
|
|
color: #6B7280;
|
|
font-size: 12px;
|
|
cursor: pointer;
|
|
margin: 0 auto 8px;
|
|
transition: all 0.15s;
|
|
font-family: inherit;
|
|
}
|
|
.csk-clear-btn:hover {
|
|
background: #FEF2F2;
|
|
border-color: #FCA5A5;
|
|
color: #DC2626;
|
|
}
|
|
|
|
/* ========== P1: 知识库分类下拉 ========== */
|
|
.csk-category-bar {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 8px 12px;
|
|
border-top: 1px solid var(--csk-border);
|
|
background: #FBFBFC;
|
|
gap: 8px;
|
|
flex-shrink: 0;
|
|
}
|
|
.csk-category-bar__label {
|
|
font-size: 13px;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
/* ========== P1: RAG 引用来源卡片 ========== */
|
|
.csk-sources {
|
|
margin-top: 8px;
|
|
border: 1px solid var(--csk-border);
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
font-size: 12px;
|
|
max-width: 100%;
|
|
background: #fff;
|
|
}
|
|
.csk-sources__header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 6px 10px;
|
|
background: var(--csk-bg-ai);
|
|
cursor: pointer;
|
|
user-select: none;
|
|
transition: background 0.15s;
|
|
}
|
|
.csk-sources__header:hover { background: var(--csk-border); }
|
|
.csk-sources__title {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 5px;
|
|
font-weight: 500;
|
|
color: #374151;
|
|
}
|
|
.csk-sources__arrow {
|
|
transition: transform 0.2s;
|
|
color: #9CA3AF;
|
|
font-size: 10px;
|
|
}
|
|
.csk-sources--collapsed .csk-sources__arrow { transform: rotate(-90deg); }
|
|
.csk-sources__body {
|
|
border-top: 1px solid var(--csk-border);
|
|
padding: 0;
|
|
}
|
|
.csk-sources--collapsed .csk-sources__body { display: none; }
|
|
.csk-source-item {
|
|
padding: 6px 10px;
|
|
border-bottom: 1px solid #F0F1F4;
|
|
transition: background 0.15s;
|
|
}
|
|
.csk-source-item:last-child { border-bottom: none; }
|
|
.csk-source-item:hover { background: var(--csk-bg-ai); }
|
|
.csk-source-item__name {
|
|
font-weight: 500;
|
|
color: #1F2937;
|
|
margin-bottom: 2px;
|
|
}
|
|
.csk-source-item__snippet {
|
|
color: #6B7280;
|
|
line-height: 1.5;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
display: -webkit-box;
|
|
-webkit-line-clamp: 2;
|
|
-webkit-box-orient: vertical;
|
|
}
|
|
.csk-source-item__meta {
|
|
font-size: 11px;
|
|
color: #9CA3AF;
|
|
margin-top: 2px;
|
|
}
|
|
|
|
/* ========== P2: 会话管理面板 ========== */
|
|
.csk-history-panel {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background: #fff;
|
|
z-index: 10;
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
animation: csk-slide-in 0.24s ease;
|
|
}
|
|
.csk-history-panel--hidden { display: none; }
|
|
@keyframes csk-slide-in {
|
|
from { transform: translateX(100%); opacity: 0.4; }
|
|
to { transform: translateX(0); opacity: 1; }
|
|
}
|
|
.csk-history-panel__header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 14px 16px;
|
|
border-bottom: 1px solid var(--csk-border);
|
|
background: var(--csk-bg-app);
|
|
flex-shrink: 0;
|
|
}
|
|
.csk-history-panel__title {
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
color: #1F2937;
|
|
}
|
|
.csk-history-panel__back {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
padding: 5px 12px;
|
|
border: 1px solid var(--csk-border);
|
|
border-radius: 8px;
|
|
background: #fff;
|
|
color: #374151;
|
|
font-size: 12px;
|
|
cursor: pointer;
|
|
transition: all 0.15s;
|
|
font-family: inherit;
|
|
}
|
|
.csk-history-panel__back:hover { background: #F3F4F6; }
|
|
.csk-history-panel__list {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 10px;
|
|
}
|
|
.csk-history-panel__list::-webkit-scrollbar { width: 5px; }
|
|
.csk-history-panel__list::-webkit-scrollbar-thumb { background: #E5E7EB; border-radius: 2px; }
|
|
.csk-history-item {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 11px 12px;
|
|
border-radius: 10px;
|
|
cursor: pointer;
|
|
transition: background 0.15s;
|
|
margin-bottom: 5px;
|
|
border: 1px solid transparent;
|
|
}
|
|
.csk-history-item:hover { background: #F3F4F6; }
|
|
.csk-history-item--active {
|
|
background: rgba(var(--csk-primary-rgb), 0.08);
|
|
border-color: rgba(var(--csk-primary-rgb), 0.2);
|
|
}
|
|
.csk-history-item--active:hover { background: rgba(var(--csk-primary-rgb), 0.12); }
|
|
.csk-history-item__info { flex: 1; min-width: 0; }
|
|
.csk-history-item__id {
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
color: #1F2937;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
.csk-history-item__meta {
|
|
font-size: 11px;
|
|
color: #9CA3AF;
|
|
margin-top: 3px;
|
|
}
|
|
.csk-history-item__actions {
|
|
display: flex;
|
|
gap: 4px;
|
|
margin-left: 8px;
|
|
opacity: 0;
|
|
transition: opacity 0.15s;
|
|
}
|
|
.csk-history-item:hover .csk-history-item__actions { opacity: 1; }
|
|
.csk-history-action {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 28px;
|
|
height: 28px;
|
|
border: none;
|
|
border-radius: 7px;
|
|
cursor: pointer;
|
|
font-size: 12px;
|
|
transition: all 0.15s;
|
|
}
|
|
.csk-history-action--export { background: #EFF6FF; color: #2563EB; }
|
|
.csk-history-action--export:hover { background: #DBEAFE; }
|
|
.csk-history-action--delete { background: #FEF2F2; color: #DC2626; }
|
|
.csk-history-action--delete:hover { background: #FEE2E2; }
|
|
.csk-history-panel__empty {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 48px 20px;
|
|
color: #9CA3AF;
|
|
font-size: 13px;
|
|
text-align: center;
|
|
}
|
|
.csk-history-panel__empty-icon {
|
|
font-size: 34px;
|
|
margin-bottom: 10px;
|
|
opacity: 0.5;
|
|
}
|
|
.csk-history-panel__loading {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 24px;
|
|
color: #9CA3AF;
|
|
font-size: 13px;
|
|
}
|
|
|
|
/* ========== 快捷问题芯片 ========== */
|
|
.csk-quick-replies {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
justify-content: center;
|
|
margin-top: 18px;
|
|
max-width: 320px;
|
|
}
|
|
|
|
/* ========== 推荐问题(suggest-message-list) ========== */
|
|
.csk-suggestions {
|
|
margin-top: 6px;
|
|
padding: 4px 0 0 0;
|
|
}
|
|
.csk-suggestions__list {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 4px;
|
|
}
|
|
|
|
/* ========== 新消息提示按钮 ========== */
|
|
.csk-newmsg {
|
|
position: absolute;
|
|
bottom: 82px;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
z-index: 5;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 5px;
|
|
padding: 7px 14px;
|
|
border: none;
|
|
background: var(--csk-primary);
|
|
color: #fff;
|
|
font-size: 12px;
|
|
font-family: inherit;
|
|
border-radius: 999px;
|
|
cursor: pointer;
|
|
box-shadow: 0 4px 14px rgba(var(--csk-primary-rgb), 0.38);
|
|
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
|
animation: csk-msg-in 0.25s ease;
|
|
white-space: nowrap;
|
|
}
|
|
.csk-newmsg:hover { transform: translateX(-50%) translateY(-1px); box-shadow: 0 6px 18px rgba(var(--csk-primary-rgb), 0.48); }
|
|
.csk-newmsg:active { transform: translateX(-50%) scale(0.95); }
|
|
.csk-newmsg--hidden { display: none; }
|
|
|
|
/* ========== 窗口缩放拖拽手柄 ========== */
|
|
.csk-resize-handle {
|
|
position: absolute;
|
|
right: 4px;
|
|
bottom: 4px;
|
|
width: 20px;
|
|
height: 20px;
|
|
display: flex;
|
|
align-items: flex-end;
|
|
justify-content: flex-end;
|
|
cursor: nwse-resize;
|
|
z-index: 5;
|
|
user-select: none;
|
|
-webkit-user-select: none;
|
|
/* 圆形半透明背景,与整体圆润风格一致 */
|
|
border-radius: 50%;
|
|
background: transparent;
|
|
transition: background 0.2s ease;
|
|
}
|
|
.csk-resize-handle:hover {
|
|
background: rgba(var(--csk-primary-rgb), 0.08);
|
|
}
|
|
|
|
/* 三斜线抓手 — 纯 CSS 绘制,用两条间距微调的线,视觉上是三条 */
|
|
.csk-resize-grip {
|
|
display: block;
|
|
width: 10px;
|
|
height: 10px;
|
|
background:
|
|
linear-gradient(135deg,
|
|
transparent 0%, transparent 38%,
|
|
#C8CCD2 38%, #C8CCD2 42%,
|
|
transparent 42%, transparent 54%,
|
|
#C8CCD2 54%, #C8CCD2 58%,
|
|
transparent 58%, transparent 70%,
|
|
#C8CCD2 70%, #C8CCD2 74%,
|
|
transparent 74%
|
|
);
|
|
transition: background 0.2s ease;
|
|
border-radius: 2px;
|
|
}
|
|
/* hover 时线条变为主色 */
|
|
.csk-resize-handle:hover .csk-resize-grip {
|
|
background:
|
|
linear-gradient(135deg,
|
|
transparent 0%, transparent 38%,
|
|
var(--csk-primary) 38%, var(--csk-primary) 42%,
|
|
transparent 42%, transparent 54%,
|
|
var(--csk-primary) 54%, var(--csk-primary) 58%,
|
|
transparent 58%, transparent 70%,
|
|
var(--csk-primary) 70%, var(--csk-primary) 74%,
|
|
transparent 74%
|
|
);
|
|
}
|
|
|
|
/* 暗色模式 */
|
|
.csk-dark .csk-resize-grip {
|
|
background:
|
|
linear-gradient(135deg,
|
|
transparent 0%, transparent 38%,
|
|
#5B6070 38%, #5B6070 42%,
|
|
transparent 42%, transparent 54%,
|
|
#5B6070 54%, #5B6070 58%,
|
|
transparent 58%, transparent 70%,
|
|
#5B6070 70%, #5B6070 74%,
|
|
transparent 74%
|
|
);
|
|
}
|
|
.csk-dark .csk-resize-handle:hover .csk-resize-grip {
|
|
background:
|
|
linear-gradient(135deg,
|
|
transparent 0%, transparent 38%,
|
|
var(--csk-primary-light) 38%, var(--csk-primary-light) 42%,
|
|
transparent 42%, transparent 54%,
|
|
var(--csk-primary-light) 54%, var(--csk-primary-light) 58%,
|
|
transparent 58%, transparent 70%,
|
|
var(--csk-primary-light) 70%, var(--csk-primary-light) 74%,
|
|
transparent 74%
|
|
);
|
|
}
|
|
|
|
/* 缩放拖拽中:禁用过渡动画 + 全局光标 */
|
|
.csk-window--resizing {
|
|
transition: none !important;
|
|
user-select: none;
|
|
}
|
|
.csk-window--resizing * { cursor: nwse-resize !important; }
|
|
|
|
/* ========== 暗色模式 ========== */
|
|
.csk-root.csk-dark {
|
|
--csk-bg-ai: #1E1E2E;
|
|
--csk-text-ai: #E2E8F0;
|
|
--csk-border: #3B3B52;
|
|
--csk-border-strong: #454560;
|
|
--csk-text-secondary: rgba(255, 255, 255, 0.6);
|
|
--csk-text-muted: rgba(255, 255, 255, 0.4);
|
|
--csk-bg-app: #141421;
|
|
/* TDesign 底层语义变量暗色覆盖:让 t-chat-item/t-chat-sender/t-tag 等适配暗色
|
|
语义变量(--td-bg-color-container / --td-text-color-primary 等)都引用这几个底层变量 */
|
|
--td-gray-color-1: #1E1E2E;
|
|
--td-gray-color-2: #141421;
|
|
--td-gray-color-3: #3B3B52;
|
|
--td-gray-color-4: #454560;
|
|
--td-font-gray-1: rgba(255, 255, 255, 0.9);
|
|
--td-font-gray-2: rgba(255, 255, 255, 0.6);
|
|
--td-font-gray-3: rgba(255, 255, 255, 0.4);
|
|
color: #E2E8F0;
|
|
}
|
|
.csk-dark .csk-window {
|
|
background: #1A1A2E;
|
|
box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2);
|
|
}
|
|
.csk-dark .csk-watermark {
|
|
opacity: 1;
|
|
}
|
|
.csk-dark .csk-header::after { background: linear-gradient(to bottom, rgba(0,0,0,0.12), transparent); }
|
|
.csk-dark .csk-input-area { background: #1A1A2E; border-top-color: var(--csk-border); }
|
|
.csk-dark .csk-category-bar { background: #1A1A2E; border-top-color: var(--csk-border); }
|
|
.csk-dark .csk-sources { background: #1E1E2E; border-color: var(--csk-border); }
|
|
.csk-dark .csk-sources__header { background: #25253A; }
|
|
.csk-dark .csk-sources__header:hover { background: #2D2D48; }
|
|
.csk-dark .csk-source-item:hover { background: var(--csk-bg-ai); }
|
|
.csk-dark .csk-source-item__name { color: #E2E8F0; }
|
|
.csk-dark .csk-source-item__meta { color: #6B7280; }
|
|
.csk-dark .csk-history-panel { background: #1A1A2E; }
|
|
.csk-dark .csk-history-panel__header { background: var(--csk-bg-app); border-bottom-color: var(--csk-border); }
|
|
.csk-dark .csk-history-panel__back { background: var(--csk-bg-app); border-color: var(--csk-border); color: #E2E8F0; }
|
|
.csk-dark .csk-history-panel__back:hover { background: #2D2D48; }
|
|
.csk-dark .csk-history-item:hover { background: #25253A; }
|
|
.csk-dark .csk-history-item__id { color: #E2E8F0; }
|
|
.csk-dark .csk-history-item__meta { color: #6B7280; }
|
|
.csk-dark .csk-history-item--active { background: rgba(var(--csk-primary-rgb), 0.15); }
|
|
.csk-dark .csk-history-item--active:hover { background: rgba(var(--csk-primary-rgb), 0.22); }
|
|
.csk-dark .csk-clear-btn { background: var(--csk-bg-app); border-color: var(--csk-border); color: #9CA3AF; }
|
|
.csk-dark .csk-clear-btn:hover { background: #3B1A1A; border-color: #7F1D1D; color: #FCA5A5; }
|
|
.csk-dark .csk-welcome__title { color: #E2E8F0; }
|
|
.csk-dark .csk-welcome__desc { color: #6B7280; }
|
|
.csk-dark .csk-teaser { background: #2D2D48; color: #E2E8F0; box-shadow: 0 4px 20px rgba(0,0,0,0.35); }
|
|
.csk-dark .csk-teaser::after { border-top-color: #2D2D48; }
|
|
.csk-dark .csk-teaser__close { color: #6B7280; }
|
|
.csk-dark .csk-teaser__close:hover { color: #9CA3AF; }
|
|
.csk-dark .csk-history-panel__search-wrap { background: var(--csk-bg-app); border-color: var(--csk-border); }
|
|
.csk-dark .csk-history-panel__search-wrap:focus-within { border-color: var(--csk-primary); }
|
|
.csk-dark .csk-history-panel__search { color: #E2E8F0; }
|
|
.csk-dark .csk-launcher__badge { box-shadow: 0 0 0 2px #1A1A2E; }
|
|
.csk-dark .csk-welcome__avatar { box-shadow: 0 6px 18px rgba(var(--csk-primary-rgb), 0.25); }
|
|
.csk-dark .csk-header__avatar { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15); background: rgba(255, 255, 255, 0.1); }
|
|
|
|
/* Launcher 拖拽态:微放大 + 阴影加深 */
|
|
.csk-launcher--dragging {
|
|
cursor: grabbing !important;
|
|
transform: scale(1.1) !important;
|
|
box-shadow:
|
|
0 4px 12px rgba(0, 0, 0, 0.14),
|
|
0 12px 32px rgba(0, 0, 0, 0.18),
|
|
0 14px 40px rgba(236, 72, 153, 0.36),
|
|
0 0 56px rgba(236, 72, 153, 0.18) !important;
|
|
}
|
|
/* 拖拽中隐藏未读徽章 */
|
|
.csk-launcher--dragging .csk-launcher__badge { display: none !important; }
|
|
/* 吸附过渡动画(释放时的缓动) */
|
|
.csk-launcher--snap {
|
|
transition: left 0.3s ease-out, right 0.3s ease-out, bottom 0.3s ease-out !important;
|
|
}
|
|
|
|
/* ========== Launcher 未读徽章 ========== */
|
|
.csk-launcher__badge {
|
|
position: absolute;
|
|
top: -2px;
|
|
right: -2px;
|
|
width: 16px;
|
|
height: 16px;
|
|
border-radius: 50%;
|
|
background: #EF4444;
|
|
border: 2px solid #fff;
|
|
box-shadow: 0 0 0 2px #fff;
|
|
animation: csk-badge-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
pointer-events: none;
|
|
}
|
|
.csk-launcher__badge--hidden { display: none; }
|
|
@keyframes csk-badge-in {
|
|
from { transform: scale(0); }
|
|
to { transform: scale(1); }
|
|
}
|
|
|
|
/* ========== Launcher 提示气泡 ========== */
|
|
.csk-teaser {
|
|
position: fixed;
|
|
bottom: 90px;
|
|
z-index: 9997;
|
|
max-width: 240px;
|
|
padding: 10px 14px;
|
|
background: #fff;
|
|
color: #1F2937;
|
|
font-size: 13px;
|
|
line-height: 1.5;
|
|
border-radius: 12px;
|
|
box-shadow: 0 4px 20px rgba(15, 23, 42, 0.15);
|
|
animation: csk-teaser-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
|
|
cursor: pointer;
|
|
user-select: none;
|
|
}
|
|
.csk-teaser--right { right: 24px; }
|
|
.csk-teaser--left { left: 24px; }
|
|
.csk-teaser::after {
|
|
content: '';
|
|
position: absolute;
|
|
bottom: -6px;
|
|
right: 28px;
|
|
width: 12px;
|
|
height: 12px;
|
|
background: inherit;
|
|
border-radius: 2px;
|
|
transform: rotate(45deg);
|
|
box-shadow: 2px 2px 4px rgba(15, 23, 42, 0.08);
|
|
}
|
|
.csk-teaser--left::after { right: auto; left: 28px; }
|
|
.csk-teaser__close {
|
|
position: absolute;
|
|
top: 4px;
|
|
right: 6px;
|
|
background: none;
|
|
border: none;
|
|
font-size: 16px;
|
|
color: #9CA3AF;
|
|
cursor: pointer;
|
|
padding: 2px 4px;
|
|
line-height: 1;
|
|
border-radius: 4px;
|
|
}
|
|
.csk-teaser__close:hover { color: #374151; }
|
|
.csk-teaser--hidden { display: none; }
|
|
@keyframes csk-teaser-in {
|
|
from { opacity: 0; transform: translateY(8px) scale(0.95); }
|
|
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
}
|
|
|
|
/* ========== 点踩原因选择面板 ========== */
|
|
.csk-feedback-reason {
|
|
position: relative;
|
|
margin-top: 6px;
|
|
padding: 10px 12px;
|
|
background: #fff;
|
|
border: 1px solid var(--csk-border);
|
|
border-radius: 8px;
|
|
animation: csk-fade-in 0.15s ease;
|
|
}
|
|
.csk-feedback-reason__title {
|
|
font-size: 12px;
|
|
color: var(--csk-text-muted);
|
|
margin-bottom: 8px;
|
|
}
|
|
.csk-feedback-reason__options {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 6px;
|
|
margin-bottom: 8px;
|
|
}
|
|
.csk-feedback-reason__btn {
|
|
padding: 4px 10px;
|
|
font-size: 12px;
|
|
border: 1px solid var(--csk-border);
|
|
border-radius: 14px;
|
|
background: #fff;
|
|
color: #1F2937;
|
|
cursor: pointer;
|
|
transition: all 0.15s ease;
|
|
}
|
|
.csk-feedback-reason__btn:hover {
|
|
border-color: var(--csk-primary);
|
|
color: var(--csk-primary);
|
|
background: rgba(var(--csk-primary-rgb), 0.08);
|
|
}
|
|
.csk-feedback-reason__comment-row {
|
|
display: flex;
|
|
gap: 6px;
|
|
}
|
|
.csk-feedback-reason__comment {
|
|
flex: 1;
|
|
padding: 4px 8px;
|
|
font-size: 12px;
|
|
border: 1px solid var(--csk-border);
|
|
border-radius: 6px;
|
|
background: #fff;
|
|
color: #1F2937;
|
|
outline: none;
|
|
}
|
|
.csk-feedback-reason__comment:focus { border-color: var(--csk-primary); }
|
|
.csk-feedback-reason__submit {
|
|
padding: 4px 10px;
|
|
font-size: 12px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
background: var(--csk-primary);
|
|
color: #fff;
|
|
cursor: pointer;
|
|
white-space: nowrap;
|
|
}
|
|
.csk-feedback-reason__close {
|
|
position: absolute;
|
|
top: 8px;
|
|
right: 8px;
|
|
width: 18px;
|
|
height: 18px;
|
|
border: none;
|
|
background: none;
|
|
color: var(--csk-text-muted);
|
|
cursor: pointer;
|
|
padding: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border-radius: 4px;
|
|
}
|
|
.csk-feedback-reason__close:hover { color: #1F2937; background: #F3F4F6; }
|
|
.csk-dark .csk-feedback-reason { background: #1A1A2E; border-color: var(--csk-border); }
|
|
.csk-dark .csk-feedback-reason__btn {
|
|
background: rgba(255,255,255,0.06);
|
|
border-color: var(--csk-border);
|
|
color: #E2E8F0;
|
|
}
|
|
.csk-dark .csk-feedback-reason__btn:hover {
|
|
border-color: var(--csk-primary-light);
|
|
color: var(--csk-primary-light);
|
|
background: rgba(var(--csk-primary-rgb), 0.15);
|
|
}
|
|
.csk-dark .csk-feedback-reason__comment {
|
|
background: rgba(255,255,255,0.06);
|
|
border-color: var(--csk-border);
|
|
color: #E2E8F0;
|
|
}
|
|
|
|
/* ========== 历史会话搜索框 ========== */
|
|
.csk-history-panel__search-wrap {
|
|
padding: 8px 10px;
|
|
border-bottom: 1px solid var(--csk-border);
|
|
flex-shrink: 0;
|
|
}
|
|
.csk-history-panel__search-wrap:focus-within {
|
|
border-bottom-color: var(--csk-primary);
|
|
}
|
|
.csk-history-panel__search {
|
|
width: 100%;
|
|
padding: 7px 10px;
|
|
border: 1px solid var(--csk-border);
|
|
border-radius: 8px;
|
|
font-size: 12.5px;
|
|
font-family: inherit;
|
|
color: #1F2937;
|
|
background: var(--csk-bg-app);
|
|
outline: none;
|
|
transition: border-color 0.2s;
|
|
}
|
|
.csk-history-panel__search:focus { border-color: var(--csk-primary); }
|
|
.csk-history-panel__search::placeholder { color: #9CA3AF; }
|
|
|
|
/* ========== a11y 焦点指示 ========== */
|
|
.csk-root :focus-visible {
|
|
outline: 2px solid var(--csk-primary);
|
|
outline-offset: 2px;
|
|
}
|
|
.csk-root button:focus-visible {
|
|
outline: 2px solid var(--csk-primary);
|
|
outline-offset: 2px;
|
|
border-radius: inherit;
|
|
}
|
|
/* 弹窗打开时隐藏 launcher 上的焦点环 */
|
|
.csk-launcher:focus-visible {
|
|
outline: none;
|
|
border-color: rgba(255, 255, 255, 0.75);
|
|
box-shadow:
|
|
0 1px 2px rgba(0, 0, 0, 0.06),
|
|
0 4px 16px rgba(0, 0, 0, 0.10),
|
|
0 6px 24px rgba(var(--csk-primary-rgb), 0.28),
|
|
0 0 48px rgba(var(--csk-primary-rgb), 0.12),
|
|
0 0 0 4px rgba(var(--csk-primary-rgb), 0.3);
|
|
}
|
|
|
|
/* ========== a11y aria-live 播报区(视觉隐藏) ========== */
|
|
.csk-sr-only {
|
|
position: absolute !important;
|
|
width: 1px !important;
|
|
height: 1px !important;
|
|
padding: 0 !important;
|
|
margin: -1px !important;
|
|
overflow: hidden !important;
|
|
clip: rect(0,0,0,0) !important;
|
|
white-space: nowrap !important;
|
|
border: 0 !important;
|
|
}
|
|
|
|
/* ========== 会话分组标题 ========== */
|
|
.csk-history-group {
|
|
margin-bottom: 4px;
|
|
}
|
|
.csk-history-group__label {
|
|
font-size: 11px;
|
|
font-weight: 600;
|
|
color: #9CA3AF;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
padding: 8px 12px 4px;
|
|
user-select: none;
|
|
}
|
|
.csk-dark .csk-history-group__label { color: #6B7280; }
|
|
|
|
/* ========== 移动端适配 ========== */
|
|
@media (max-width: 480px) {
|
|
.csk-window {
|
|
width: 100vw !important;
|
|
height: 100vh !important;
|
|
max-height: 100vh;
|
|
bottom: 0 !important;
|
|
right: 0 !important;
|
|
left: 0 !important;
|
|
border-radius: 0;
|
|
}
|
|
.csk-resize-handle { display: none !important; }
|
|
.csk-window--hidden { transform: translateY(100%); }
|
|
/* 移动端默认位置,仅在未被 JS 拖拽覆盖时生效 */
|
|
.csk-launcher:not([style*="bottom"]) { bottom: 20px; }
|
|
.csk-launcher--right:not([style*="bottom"]) { right: 20px; }
|
|
.csk-launcher--left:not([style*="bottom"]) { left: 20px; }
|
|
}
|
|
`;
|
|
}
|
|
|
|
/**
|
|
* 注入样式到 document.head
|
|
*/
|
|
export function injectStyles(config: ResolvedConfig): void {
|
|
// 避免重复注入
|
|
if (document.querySelector('style[data-csk-sdk]')) {
|
|
return;
|
|
}
|
|
|
|
styleElement = document.createElement('style');
|
|
styleElement.setAttribute('data-csk-sdk', '');
|
|
styleElement.textContent = getStyles(config);
|
|
document.head.appendChild(styleElement);
|
|
}
|
|
|
|
/**
|
|
* 移除注入的样式
|
|
*/
|
|
export function removeStyles(): void {
|
|
if (styleElement && styleElement.parentNode) {
|
|
styleElement.parentNode.removeChild(styleElement);
|
|
styleElement = null;
|
|
}
|
|
document.querySelectorAll('style[data-csk-sdk]').forEach((el) => el.remove());
|
|
}
|