@bbki.ng/bb-msg-history 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/dist/component.d.ts +37 -0
- package/dist/component.js +178 -0
- package/dist/const/authors.d.ts +10 -0
- package/dist/const/authors.js +29 -0
- package/dist/const/styles.d.ts +12 -0
- package/dist/const/styles.js +360 -0
- package/dist/const/theme.d.ts +6 -0
- package/dist/const/theme.js +32 -0
- package/dist/index.d.ts +4 -41
- package/dist/index.dev.js +8 -542
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +33 -0
- package/dist/types/index.js +4 -0
- package/dist/utils/author-resolver.d.ts +11 -0
- package/dist/utils/author-resolver.js +71 -0
- package/dist/utils/avatar.d.ts +4 -0
- package/dist/utils/avatar.js +18 -0
- package/dist/utils/html.d.ts +12 -0
- package/dist/utils/html.js +33 -0
- package/dist/utils/message-builder.d.ts +13 -0
- package/dist/utils/message-builder.js +49 -0
- package/dist/utils/message-parser.d.ts +6 -0
- package/dist/utils/message-parser.js +22 -0
- package/dist/utils/registration.d.ts +8 -0
- package/dist/utils/registration.js +29 -0
- package/dist/utils/scroll-button.d.ts +4 -0
- package/dist/utils/scroll-button.js +12 -0
- package/dist/utils/tooltip.d.ts +5 -0
- package/dist/utils/tooltip.js +17 -0
- package/package.json +7 -6
- package/src/component.ts +217 -0
- package/src/const/authors.ts +32 -0
- package/src/const/styles.ts +363 -0
- package/src/const/theme.ts +34 -0
- package/src/index.ts +11 -602
- package/src/types/index.ts +37 -0
- package/src/utils/author-resolver.ts +81 -0
- package/src/utils/avatar.ts +19 -0
- package/src/utils/html.ts +35 -0
- package/src/utils/message-builder.ts +58 -0
- package/src/utils/message-parser.ts +27 -0
- package/src/utils/registration.ts +35 -0
- package/src/utils/scroll-button.ts +12 -0
- package/src/utils/tooltip.ts +16 -0
package/README.md
CHANGED
|
@@ -83,6 +83,24 @@ Fuzzy matching: if an author name _contains_ a configured key (e.g. you configur
|
|
|
83
83
|
|
|
84
84
|
Use `removeAuthor(name)` to remove a custom config.
|
|
85
85
|
|
|
86
|
+
### `appendMessage(message)`
|
|
87
|
+
|
|
88
|
+
Append a message programmatically with smooth scroll to the new message.
|
|
89
|
+
|
|
90
|
+
| Parameter | Type | Description |
|
|
91
|
+
|-----------|------|-------------|
|
|
92
|
+
| `message.author` | `string` | The author name |
|
|
93
|
+
| `message.text` | `string` | The message text |
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
el.appendMessage({ author: 'alice', text: 'Hello!' });
|
|
97
|
+
el.appendMessage({ author: 'bob', text: 'How are you?' });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Returns `this` for chaining. This is ideal for chat applications where messages arrive in real-time.
|
|
101
|
+
|
|
102
|
+
**Note:** Unlike modifying `textContent` directly, `appendMessage()` scrolls smoothly to the newly added message.
|
|
103
|
+
|
|
86
104
|
## Customization
|
|
87
105
|
|
|
88
106
|
### CSS Custom Properties
|
|
@@ -119,6 +137,7 @@ define('my-chat-history');
|
|
|
119
137
|
- Hover tooltip showing the author name
|
|
120
138
|
- Consecutive messages from the same author are grouped (avatar hidden)
|
|
121
139
|
- Auto-scroll to the latest message on render
|
|
140
|
+
- **`appendMessage()` API** — programmatically add messages with smooth scroll
|
|
122
141
|
- Long text word-wrap and overflow handling
|
|
123
142
|
- Empty state when no messages are provided
|
|
124
143
|
- Dark mode support via `prefers-color-scheme`
|
|
@@ -190,6 +209,31 @@ When no messages are provided, a "No messages" placeholder is shown:
|
|
|
190
209
|
<bb-msg-history></bb-msg-history>
|
|
191
210
|
```
|
|
192
211
|
|
|
212
|
+
### Dynamic message appending
|
|
213
|
+
|
|
214
|
+
Use `appendMessage()` to add messages programmatically with smooth scrolling:
|
|
215
|
+
|
|
216
|
+
```html
|
|
217
|
+
<bb-msg-history id="chat" style="--bb-max-height: 300px;">
|
|
218
|
+
alice: Hey there!
|
|
219
|
+
</bb-msg-history>
|
|
220
|
+
|
|
221
|
+
<script>
|
|
222
|
+
const el = document.getElementById('chat');
|
|
223
|
+
el.setAuthor('alice', { avatar: '👩', side: 'right' });
|
|
224
|
+
el.setAuthor('bob', { avatar: '👨', side: 'left' });
|
|
225
|
+
|
|
226
|
+
// Add messages dynamically with smooth scroll
|
|
227
|
+
el.appendMessage({ author: 'bob', text: 'Hello! How are you?' });
|
|
228
|
+
el.appendMessage({ author: 'alice', text: 'I\'m doing great!' });
|
|
229
|
+
|
|
230
|
+
// Simulate receiving a message after 2 seconds
|
|
231
|
+
setTimeout(() => {
|
|
232
|
+
el.appendMessage({ author: 'bob', text: 'Nice to hear that!' });
|
|
233
|
+
}, 2000);
|
|
234
|
+
</script>
|
|
235
|
+
```
|
|
236
|
+
|
|
193
237
|
### Full page example
|
|
194
238
|
|
|
195
239
|
```html
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AuthorOptions, Message } from './types/index.js';
|
|
2
|
+
export declare class BBMsgHistory extends HTMLElement {
|
|
3
|
+
private _mutationObserver?;
|
|
4
|
+
private _userAuthors;
|
|
5
|
+
private _lastAuthor;
|
|
6
|
+
private _scrollButtonVisible;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Configure an author's avatar, side, and colors.
|
|
10
|
+
* Call before or after rendering — the component re-renders automatically.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* el.setAuthor('alice', { avatar: '🐱', side: 'right', bubbleColor: '#e0f2fe' });
|
|
14
|
+
* el.setAuthor('bob', { avatar: '<img src="bob.png" />', side: 'left' });
|
|
15
|
+
*/
|
|
16
|
+
setAuthor(name: string, options: AuthorOptions): this;
|
|
17
|
+
/**
|
|
18
|
+
* Remove a previously set author config.
|
|
19
|
+
*/
|
|
20
|
+
removeAuthor(name: string): this;
|
|
21
|
+
/**
|
|
22
|
+
* Append a message to the history.
|
|
23
|
+
* Automatically scrolls to the new message with smooth animation.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* el.appendMessage({ author: 'alice', text: 'Hello!' });
|
|
27
|
+
* el.appendMessage({ author: 'bob', text: 'How are you?' });
|
|
28
|
+
*/
|
|
29
|
+
appendMessage(message: Message): this;
|
|
30
|
+
private _appendSingleMessage;
|
|
31
|
+
connectedCallback(): void;
|
|
32
|
+
disconnectedCallback(): void;
|
|
33
|
+
private _setupMutationObserver;
|
|
34
|
+
private render;
|
|
35
|
+
private _renderEmpty;
|
|
36
|
+
private _setupScrollTracking;
|
|
37
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { MAIN_STYLES, EMPTY_STYLES } from './const/styles.js';
|
|
2
|
+
import { parseMessages } from './utils/message-parser.js';
|
|
3
|
+
import { resolveAuthorConfig } from './utils/author-resolver.js';
|
|
4
|
+
import { setupTooltips } from './utils/tooltip.js';
|
|
5
|
+
import { buildMessageRowHtml, setupTooltipForElement } from './utils/message-builder.js';
|
|
6
|
+
import { buildScrollButtonHtml } from './utils/scroll-button.js';
|
|
7
|
+
export class BBMsgHistory extends HTMLElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this._userAuthors = new Map();
|
|
11
|
+
this._lastAuthor = '';
|
|
12
|
+
this._scrollButtonVisible = false;
|
|
13
|
+
this.attachShadow({ mode: 'open' });
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Configure an author's avatar, side, and colors.
|
|
17
|
+
* Call before or after rendering — the component re-renders automatically.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* el.setAuthor('alice', { avatar: '🐱', side: 'right', bubbleColor: '#e0f2fe' });
|
|
21
|
+
* el.setAuthor('bob', { avatar: '<img src="bob.png" />', side: 'left' });
|
|
22
|
+
*/
|
|
23
|
+
setAuthor(name, options) {
|
|
24
|
+
this._userAuthors.set(name, options);
|
|
25
|
+
this.render();
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Remove a previously set author config.
|
|
30
|
+
*/
|
|
31
|
+
removeAuthor(name) {
|
|
32
|
+
this._userAuthors.delete(name);
|
|
33
|
+
this.render();
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Append a message to the history.
|
|
38
|
+
* Automatically scrolls to the new message with smooth animation.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* el.appendMessage({ author: 'alice', text: 'Hello!' });
|
|
42
|
+
* el.appendMessage({ author: 'bob', text: 'How are you?' });
|
|
43
|
+
*/
|
|
44
|
+
appendMessage(message) {
|
|
45
|
+
// Update textContent
|
|
46
|
+
const currentText = this.textContent || '';
|
|
47
|
+
const separator = currentText && !currentText.endsWith('\n') ? '\n' : '';
|
|
48
|
+
this.textContent = currentText + separator + `${message.author}: ${message.text}`;
|
|
49
|
+
// Temporarily disconnect observer to prevent recursive render
|
|
50
|
+
this._mutationObserver?.disconnect();
|
|
51
|
+
// Append single message without re-rendering entire list
|
|
52
|
+
this._appendSingleMessage(message);
|
|
53
|
+
// Reconnect observer
|
|
54
|
+
this._setupMutationObserver();
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
_appendSingleMessage(message) {
|
|
58
|
+
const container = this.shadowRoot.querySelector('.history');
|
|
59
|
+
// If empty state or no container, do full render first
|
|
60
|
+
if (!container) {
|
|
61
|
+
this.render();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const author = message.author;
|
|
65
|
+
const text = message.text;
|
|
66
|
+
const config = resolveAuthorConfig(author, this._userAuthors);
|
|
67
|
+
const isFirstFromAuthor = author !== this._lastAuthor;
|
|
68
|
+
this._lastAuthor = author;
|
|
69
|
+
const isSubsequent = !isFirstFromAuthor;
|
|
70
|
+
// Use utility function to build message HTML
|
|
71
|
+
const msgHtml = buildMessageRowHtml(author, text, config, isSubsequent);
|
|
72
|
+
// Append to container
|
|
73
|
+
container.insertAdjacentHTML('beforeend', msgHtml);
|
|
74
|
+
// Setup tooltip for new element using utility function
|
|
75
|
+
const newWrapper = container.lastElementChild?.querySelector('.avatar-wrapper');
|
|
76
|
+
if (newWrapper) {
|
|
77
|
+
setupTooltipForElement(newWrapper);
|
|
78
|
+
}
|
|
79
|
+
// Smooth scroll to bottom
|
|
80
|
+
container.scrollTo({
|
|
81
|
+
top: container.scrollHeight,
|
|
82
|
+
behavior: 'smooth'
|
|
83
|
+
});
|
|
84
|
+
// Hide scroll button since we're scrolling to bottom
|
|
85
|
+
const scrollButton = this.shadowRoot.querySelector('.scroll-to-bottom');
|
|
86
|
+
if (scrollButton && this._scrollButtonVisible) {
|
|
87
|
+
this._scrollButtonVisible = false;
|
|
88
|
+
scrollButton.classList.remove('visible');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
connectedCallback() {
|
|
92
|
+
this.render();
|
|
93
|
+
this._setupMutationObserver();
|
|
94
|
+
}
|
|
95
|
+
disconnectedCallback() {
|
|
96
|
+
this._mutationObserver?.disconnect();
|
|
97
|
+
}
|
|
98
|
+
_setupMutationObserver() {
|
|
99
|
+
let debounceTimer;
|
|
100
|
+
this._mutationObserver = new MutationObserver(() => {
|
|
101
|
+
clearTimeout(debounceTimer);
|
|
102
|
+
debounceTimer = setTimeout(() => this.render(), 50);
|
|
103
|
+
});
|
|
104
|
+
this._mutationObserver.observe(this, {
|
|
105
|
+
childList: true,
|
|
106
|
+
characterData: true,
|
|
107
|
+
subtree: true,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
render() {
|
|
111
|
+
const messages = parseMessages(this.textContent);
|
|
112
|
+
if (messages.length === 0) {
|
|
113
|
+
this._lastAuthor = '';
|
|
114
|
+
this._renderEmpty();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let lastAuthor = '';
|
|
118
|
+
const messagesHtml = messages
|
|
119
|
+
.map(({ author, text }) => {
|
|
120
|
+
const config = resolveAuthorConfig(author, this._userAuthors);
|
|
121
|
+
const isFirstFromAuthor = author !== lastAuthor;
|
|
122
|
+
lastAuthor = author;
|
|
123
|
+
const isSubsequent = !isFirstFromAuthor;
|
|
124
|
+
// Use utility function to build message HTML
|
|
125
|
+
return buildMessageRowHtml(author, text, config, isSubsequent);
|
|
126
|
+
})
|
|
127
|
+
.join('');
|
|
128
|
+
this._lastAuthor = lastAuthor;
|
|
129
|
+
this.shadowRoot.innerHTML = `
|
|
130
|
+
<style>${MAIN_STYLES}</style>
|
|
131
|
+
<div class="history" role="log" aria-live="polite" aria-label="Message history">
|
|
132
|
+
${messagesHtml}
|
|
133
|
+
</div>
|
|
134
|
+
${buildScrollButtonHtml()}
|
|
135
|
+
`;
|
|
136
|
+
requestAnimationFrame(() => {
|
|
137
|
+
const container = this.shadowRoot.querySelector('.history');
|
|
138
|
+
const scrollButton = this.shadowRoot.querySelector('.scroll-to-bottom');
|
|
139
|
+
if (container) {
|
|
140
|
+
container.scrollTop = container.scrollHeight;
|
|
141
|
+
this._setupScrollTracking(container, scrollButton);
|
|
142
|
+
}
|
|
143
|
+
if (scrollButton) {
|
|
144
|
+
scrollButton.addEventListener('click', () => {
|
|
145
|
+
container?.scrollTo({
|
|
146
|
+
top: container.scrollHeight,
|
|
147
|
+
behavior: 'smooth'
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
setupTooltips(this.shadowRoot);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
_renderEmpty() {
|
|
155
|
+
this.shadowRoot.innerHTML = `
|
|
156
|
+
<style>${EMPTY_STYLES}</style>
|
|
157
|
+
<div class="empty-state">No messages</div>
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
_setupScrollTracking(container, button) {
|
|
161
|
+
const checkScrollPosition = () => {
|
|
162
|
+
const threshold = 50; // pixels from bottom
|
|
163
|
+
const isAtBottom = container.scrollHeight - container.scrollTop - container.clientHeight < threshold;
|
|
164
|
+
const hasOverflow = container.scrollHeight > container.clientHeight;
|
|
165
|
+
const shouldShow = !isAtBottom && hasOverflow;
|
|
166
|
+
if (shouldShow !== this._scrollButtonVisible) {
|
|
167
|
+
this._scrollButtonVisible = shouldShow;
|
|
168
|
+
button.classList.toggle('visible', shouldShow);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
// Check initial state
|
|
172
|
+
checkScrollPosition();
|
|
173
|
+
// Listen for scroll events with passive listener for performance
|
|
174
|
+
container.addEventListener('scroll', checkScrollPosition, { passive: true });
|
|
175
|
+
// Also check on resize
|
|
176
|
+
window.addEventListener('resize', checkScrollPosition, { passive: true });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuthorConfig } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Built-in author configurations (secret presets)
|
|
4
|
+
* These are used for specific authors in personal projects
|
|
5
|
+
*/
|
|
6
|
+
export declare const AUTHOR_CONFIG: Record<string, Omit<AuthorConfig, 'isCustomAvatar'>>;
|
|
7
|
+
/**
|
|
8
|
+
* Authors that should use first-character avatar instead of SVG
|
|
9
|
+
*/
|
|
10
|
+
export declare const FIRST_CHAR_AVATAR_AUTHORS: Set<string>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { THEME } from './theme.js';
|
|
2
|
+
/**
|
|
3
|
+
* Built-in author configurations (secret presets)
|
|
4
|
+
* These are used for specific authors in personal projects
|
|
5
|
+
*/
|
|
6
|
+
export const AUTHOR_CONFIG = {
|
|
7
|
+
'bbki.ng': {
|
|
8
|
+
avatar: `<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 48 48" fill="none"><path d="M29.1152 21.3106C32.0605 21.3106 34.4481 18.9101 34.4481 15.9489V24.6457C34.4481 25.7585 33.5508 26.6607 32.444 26.6607H15.1207C14.0138 26.6607 13.1166 25.7585 13.1166 24.6457V15.9489C13.1166 18.9101 15.5042 21.3106 18.4494 21.3106C21.3947 21.3106 23.7823 18.9101 23.7823 15.9489C23.7823 18.9101 26.17 21.3106 29.1152 21.3106Z" fill="${THEME.gray[400]}"/><path d="M23.7823 15.9373L23.7823 15.9489C23.7823 15.9451 23.7823 15.9412 23.7823 15.9373Z" fill="${THEME.gray[400]}"/><path d="M23.1143 28.004C23.1205 30.9598 25.5057 33.3541 28.4472 33.3541C31.3886 33.3541 33.7738 30.9598 33.7801 28.004H23.1143Z" fill="${THEME.gray[400]}"/><path d="M13.7846 28.004C13.7846 28.0079 13.7846 28.0117 13.7846 28.0156C13.7908 30.9714 16.1761 33.3657 19.1175 33.3657C22.0589 33.3657 24.4442 30.9714 24.4504 28.0156H13.7846V28.004Z" fill="${THEME.gray[400]}"/><path d="M14.4527 15.9373C14.4527 16.6792 13.8545 17.2806 13.1166 17.2806C12.3786 17.2806 11.7805 16.6792 11.7805 15.9373C11.7805 15.1954 12.3786 14.594 13.1166 14.594C13.8545 14.594 14.4527 15.1954 14.4527 15.9373Z" fill="${THEME.gray[400]}"/><path d="M25.1184 15.2657C25.1184 16.0076 24.5202 16.609 23.7823 16.609C23.0444 16.609 22.4462 16.0076 22.4462 15.2657C22.4462 14.5238 23.0444 13.9224 23.7823 13.9224C24.5202 13.9224 25.1184 14.5238 25.1184 15.2657Z" fill="${THEME.gray[400]}"/><path d="M35.7842 15.9373C35.7842 16.6792 35.186 17.2806 34.4481 17.2806C33.7102 17.2806 33.112 16.6792 33.112 15.9373C33.112 15.1954 33.7102 14.594 34.4481 14.594C35.186 14.594 35.7842 15.1954 35.7842 15.9373Z" fill="${THEME.gray[400]}"/></svg>`,
|
|
9
|
+
bubbleColor: THEME.gray[100],
|
|
10
|
+
textColor: THEME.gray[900],
|
|
11
|
+
side: 'right'
|
|
12
|
+
},
|
|
13
|
+
'xwy': {
|
|
14
|
+
avatar: `<svg width="28" height="28" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12.821 17.5305C10.709 18.17 9.68345 19.4423 9.22624 20.1359C9.11159 20.3099 9.21615 20.5428 9.42038 20.5839L12.67 21.2381C12.8291 21.2702 12.9328 21.4275 12.9084 21.5879C11.3004 32.1653 21.5275 36.7547 28.6638 33.0597C28.7443 33.018 28.8408 33.0139 28.9245 33.0487C32.8032 34.6598 35.967 34.5662 37.8217 34.3099C38.131 34.2671 38.1505 33.841 37.855 33.7401C29.1343 30.7633 26.0152 24.5245 25.5144 18.8022C25.3835 17.3066 23.8172 13.2016 19.2675 13.0058C15.7934 12.8563 13.6137 15.6103 13.0319 17.325C12.9986 17.4231 12.9201 17.5004 12.821 17.5305Z" fill="${THEME.yyPink[100]}"/><circle cx="17.6178" cy="18.2688" r="0.995689" fill="white"/></svg>`,
|
|
15
|
+
bubbleColor: THEME.yyPink[50],
|
|
16
|
+
textColor: THEME.gray[900],
|
|
17
|
+
side: 'left'
|
|
18
|
+
},
|
|
19
|
+
'小乌鸦': {
|
|
20
|
+
avatar: `<svg width="28" height="28" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12.821 17.5305C10.709 18.17 9.68345 19.4423 9.22624 20.1359C9.11159 20.3099 9.21615 20.5428 9.42038 20.5839L12.67 21.2381C12.8291 21.2702 12.9328 21.4275 12.9084 21.5879C11.3004 32.1653 21.5275 36.7547 28.6638 33.0597C28.7443 33.018 28.8408 33.0139 28.9245 33.0487C32.8032 34.6598 35.967 34.5662 37.8217 34.3099C38.131 34.2671 38.1505 33.841 37.855 33.7401C29.1343 30.7633 26.0152 24.5245 25.5144 18.8022C25.3835 17.3066 23.8172 13.2016 19.2675 13.0058C15.7934 12.8563 13.6137 15.6103 13.0319 17.325C12.9986 17.4231 12.9201 17.5004 12.821 17.5305Z" fill="${THEME.yyPink[100]}"/><circle cx="17.6178" cy="18.2688" r="0.995689" fill="white"/></svg>`,
|
|
21
|
+
bubbleColor: THEME.yyPink[50],
|
|
22
|
+
textColor: THEME.gray[900],
|
|
23
|
+
side: 'left'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Authors that should use first-character avatar instead of SVG
|
|
28
|
+
*/
|
|
29
|
+
export const FIRST_CHAR_AVATAR_AUTHORS = new Set(['小乌鸦']);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main component styles
|
|
3
|
+
*/
|
|
4
|
+
export declare const MAIN_STYLES: string;
|
|
5
|
+
/**
|
|
6
|
+
* Empty state styles
|
|
7
|
+
*/
|
|
8
|
+
export declare const EMPTY_STYLES: string;
|
|
9
|
+
/**
|
|
10
|
+
* Fallback styles for when custom elements are not supported
|
|
11
|
+
*/
|
|
12
|
+
export declare const FALLBACK_STYLES: string;
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { THEME } from './theme.js';
|
|
2
|
+
/**
|
|
3
|
+
* Main component styles
|
|
4
|
+
*/
|
|
5
|
+
export const MAIN_STYLES = `
|
|
6
|
+
:host {
|
|
7
|
+
display: block;
|
|
8
|
+
position: relative;
|
|
9
|
+
font-family: "PT Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
|
|
10
|
+
"Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
|
|
11
|
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
|
|
12
|
+
"Noto Color Emoji";
|
|
13
|
+
--bb-bg-color: ${THEME.gray[50]};
|
|
14
|
+
--bb-max-height: 600px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.history {
|
|
18
|
+
margin: 0 auto;
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
gap: 0.25rem;
|
|
22
|
+
max-height: var(--bb-max-height, 600px);
|
|
23
|
+
overflow-y: auto;
|
|
24
|
+
scroll-behavior: smooth;
|
|
25
|
+
background-color: transparent;
|
|
26
|
+
border-radius: 0.5rem;
|
|
27
|
+
/* Firefox scrollbar */
|
|
28
|
+
scrollbar-width: thin;
|
|
29
|
+
scrollbar-color: ${THEME.gray[400]} transparent;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Custom scrollbar for webkit browsers */
|
|
33
|
+
.history::-webkit-scrollbar {
|
|
34
|
+
width: 6px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.history::-webkit-scrollbar-track {
|
|
38
|
+
background: transparent;
|
|
39
|
+
border-radius: 3px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.history::-webkit-scrollbar-thumb {
|
|
43
|
+
background: ${THEME.gray[400]};
|
|
44
|
+
border-radius: 3px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.history::-webkit-scrollbar-thumb:hover {
|
|
48
|
+
background: ${THEME.gray[500]};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Scroll to bottom button */
|
|
52
|
+
.scroll-to-bottom {
|
|
53
|
+
position: absolute;
|
|
54
|
+
bottom: 16px;
|
|
55
|
+
left: 50%;
|
|
56
|
+
width: 36px;
|
|
57
|
+
height: 36px;
|
|
58
|
+
border-radius: 50%;
|
|
59
|
+
background: transparent;
|
|
60
|
+
border: none;
|
|
61
|
+
color: ${THEME.gray[500]};
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
display: flex;
|
|
64
|
+
align-items: center;
|
|
65
|
+
justify-content: center;
|
|
66
|
+
opacity: 0;
|
|
67
|
+
visibility: hidden;
|
|
68
|
+
transform: translateX(-50%) translateY(10px) scale(0.9);
|
|
69
|
+
transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
|
|
70
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
|
|
71
|
+
z-index: 10;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.scroll-to-bottom.visible {
|
|
75
|
+
opacity: 1;
|
|
76
|
+
visibility: visible;
|
|
77
|
+
transform: translateX(-50%) translateY(0) scale(1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.scroll-to-bottom:hover {
|
|
81
|
+
color: ${THEME.gray[700]};
|
|
82
|
+
transform: translateX(-50%) translateY(-2px);
|
|
83
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.scroll-to-bottom:active {
|
|
87
|
+
transform: translateX(-50%) translateY(0) scale(0.95);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.scroll-to-bottom svg {
|
|
91
|
+
width: 20px;
|
|
92
|
+
height: 20px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Message row layout */
|
|
96
|
+
.msg-row {
|
|
97
|
+
display: flex;
|
|
98
|
+
align-items: flex-end;
|
|
99
|
+
gap: 0.5rem;
|
|
100
|
+
max-width: 80%;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.msg-row--left {
|
|
104
|
+
align-self: flex-start;
|
|
105
|
+
margin-right: auto;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.msg-row--right {
|
|
109
|
+
align-self: flex-end;
|
|
110
|
+
margin-left: auto;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.msg-row--subsequent {
|
|
114
|
+
margin-top: 0.125rem;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.msg-row--new-author {
|
|
118
|
+
margin-top: 0.75rem;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.msg-row--new-author:first-child {
|
|
122
|
+
margin-top: 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Avatar container */
|
|
126
|
+
.avatar-wrapper {
|
|
127
|
+
position: relative;
|
|
128
|
+
flex-shrink: 0;
|
|
129
|
+
width: 1.75rem;
|
|
130
|
+
height: 1.75rem;
|
|
131
|
+
background: #ffffff;
|
|
132
|
+
border-radius: 50%;
|
|
133
|
+
overflow: hidden;
|
|
134
|
+
cursor: help;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.avatar-wrapper--hidden {
|
|
138
|
+
opacity: 0;
|
|
139
|
+
pointer-events: none;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.avatar {
|
|
143
|
+
width: 100%;
|
|
144
|
+
height: 100%;
|
|
145
|
+
display: flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
justify-content: center;
|
|
148
|
+
border-radius: 50%;
|
|
149
|
+
overflow: hidden;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.avatar svg {
|
|
153
|
+
width: 100%;
|
|
154
|
+
height: 100%;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* Hover tooltip */
|
|
158
|
+
.avatar-tooltip {
|
|
159
|
+
position: fixed;
|
|
160
|
+
padding: 0.25rem 0.5rem;
|
|
161
|
+
background: ${THEME.gray[800]};
|
|
162
|
+
color: ${THEME.gray[50]};
|
|
163
|
+
font-size: 0.75rem;
|
|
164
|
+
border-radius: 0.25rem;
|
|
165
|
+
white-space: nowrap;
|
|
166
|
+
opacity: 0;
|
|
167
|
+
visibility: hidden;
|
|
168
|
+
pointer-events: none;
|
|
169
|
+
z-index: 10;
|
|
170
|
+
font-weight: 500;
|
|
171
|
+
letter-spacing: 0.02em;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.avatar-tooltip::after {
|
|
175
|
+
content: '';
|
|
176
|
+
position: absolute;
|
|
177
|
+
top: calc(100% - 1px);
|
|
178
|
+
left: 50%;
|
|
179
|
+
transform: translateX(-50%);
|
|
180
|
+
border: 4px solid transparent;
|
|
181
|
+
border-top-color: ${THEME.gray[800]};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.avatar-wrapper:hover .avatar-tooltip {
|
|
185
|
+
opacity: 1;
|
|
186
|
+
visibility: visible;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/* Message content area */
|
|
190
|
+
.msg-content {
|
|
191
|
+
display: flex;
|
|
192
|
+
flex-direction: column;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.msg-bubble {
|
|
196
|
+
padding: 0.625rem 0.875rem;
|
|
197
|
+
font-size: 0.9375rem;
|
|
198
|
+
line-height: 1.5;
|
|
199
|
+
word-wrap: break-word;
|
|
200
|
+
overflow-wrap: anywhere;
|
|
201
|
+
word-break: break-word;
|
|
202
|
+
border-radius: 1rem;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* Left bubble */
|
|
206
|
+
.msg-bubble--left {
|
|
207
|
+
border-bottom-left-radius: 0.25rem;
|
|
208
|
+
background-color: ${THEME.gray[200]};
|
|
209
|
+
color: ${THEME.gray[900]};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/* Right bubble */
|
|
213
|
+
.msg-bubble--right {
|
|
214
|
+
border-bottom-right-radius: 0.25rem;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/* Empty state */
|
|
218
|
+
.empty-state {
|
|
219
|
+
text-align: center;
|
|
220
|
+
padding: 2rem;
|
|
221
|
+
color: ${THEME.gray[400]};
|
|
222
|
+
font-size: 0.875rem;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* Mobile responsive */
|
|
226
|
+
@media (max-width: 480px) {
|
|
227
|
+
.history {
|
|
228
|
+
max-height: var(--bb-max-height, 70vh);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.msg-row {
|
|
232
|
+
max-width: 85%;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.msg-bubble {
|
|
236
|
+
font-size: 0.9375rem;
|
|
237
|
+
padding: 0.5rem 0.75rem;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.avatar-wrapper {
|
|
241
|
+
width: 1.5rem;
|
|
242
|
+
height: 1.5rem;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.scroll-to-bottom {
|
|
246
|
+
width: 32px;
|
|
247
|
+
height: 32px;
|
|
248
|
+
bottom: 12px;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.scroll-to-bottom svg {
|
|
252
|
+
width: 18px;
|
|
253
|
+
height: 18px;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/* Dark mode */
|
|
258
|
+
@media (prefers-color-scheme: dark) {
|
|
259
|
+
:host {
|
|
260
|
+
--bb-bg-color: ${THEME.gray[900]};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.history {
|
|
264
|
+
background-color: transparent;
|
|
265
|
+
/* Firefox scrollbar dark mode */
|
|
266
|
+
scrollbar-color: ${THEME.gray[600]} transparent;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.history::-webkit-scrollbar-thumb {
|
|
270
|
+
background: ${THEME.gray[600]};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.history::-webkit-scrollbar-thumb:hover {
|
|
274
|
+
background: ${THEME.gray[500]};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.msg-bubble {
|
|
278
|
+
color: ${THEME.gray[100]};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.msg-bubble--left {
|
|
282
|
+
background-color: ${THEME.gray[700]};
|
|
283
|
+
color: ${THEME.gray[100]};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.avatar-wrapper {
|
|
287
|
+
background: ${THEME.gray[800]};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.empty-state {
|
|
291
|
+
color: ${THEME.gray[500]};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
.scroll-to-bottom {
|
|
295
|
+
background: transparent;
|
|
296
|
+
border: none;
|
|
297
|
+
color: ${THEME.gray[400]};
|
|
298
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.scroll-to-bottom:hover {
|
|
302
|
+
color: ${THEME.gray[300]};
|
|
303
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/* Reduced motion */
|
|
308
|
+
@media (prefers-reduced-motion: reduce) {
|
|
309
|
+
.history {
|
|
310
|
+
scroll-behavior: auto;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.scroll-to-bottom {
|
|
314
|
+
transition: opacity 0.15s ease, visibility 0.15s ease;
|
|
315
|
+
transform: translateX(-50%);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.scroll-to-bottom.visible {
|
|
319
|
+
transform: translateX(-50%);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.scroll-to-bottom:hover {
|
|
323
|
+
transform: translateX(-50%);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
.scroll-to-bottom:active {
|
|
327
|
+
transform: translateX(-50%);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
`;
|
|
331
|
+
/**
|
|
332
|
+
* Empty state styles
|
|
333
|
+
*/
|
|
334
|
+
export const EMPTY_STYLES = `
|
|
335
|
+
:host { display: block; }
|
|
336
|
+
.empty-state {
|
|
337
|
+
text-align: center;
|
|
338
|
+
padding: 2rem;
|
|
339
|
+
color: ${THEME.gray[400]};
|
|
340
|
+
font-size: 0.875rem;
|
|
341
|
+
font-family: inherit;
|
|
342
|
+
}
|
|
343
|
+
`;
|
|
344
|
+
/**
|
|
345
|
+
* Fallback styles for when custom elements are not supported
|
|
346
|
+
*/
|
|
347
|
+
export const FALLBACK_STYLES = `
|
|
348
|
+
background: ${THEME.gray[100]};
|
|
349
|
+
padding: 1rem;
|
|
350
|
+
border-radius: 0.5rem;
|
|
351
|
+
overflow-x: auto;
|
|
352
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
|
|
353
|
+
font-size: 0.875rem;
|
|
354
|
+
line-height: 1.5;
|
|
355
|
+
color: ${THEME.gray[900]};
|
|
356
|
+
margin: 0;
|
|
357
|
+
white-space: pre-wrap;
|
|
358
|
+
word-wrap: break-word;
|
|
359
|
+
border: 1px solid ${THEME.gray[200]};
|
|
360
|
+
`;
|