{"id":47917355,"url":"https://github.com/bbb0ttle/bb-msg-history","last_synced_at":"2026-04-04T05:45:39.881Z","repository":{"id":340362128,"uuid":"1165705153","full_name":"bbb0ttle/bb-msg-history","owner":"bbb0ttle","description":"\u003cbb-msg-history /\u003e","archived":false,"fork":false,"pushed_at":"2026-03-10T14:33:18.000Z","size":297,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-04T05:45:36.264Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://bbb0ttle.github.io/bb-msg-history/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbb0ttle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-24T13:05:44.000Z","updated_at":"2026-03-10T14:33:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/bbb0ttle/bb-msg-history","commit_stats":null,"previous_names":["bbb0ttle/bb-msg-history"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bbb0ttle/bb-msg-history","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbb0ttle%2Fbb-msg-history","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbb0ttle%2Fbb-msg-history/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbb0ttle%2Fbb-msg-history/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbb0ttle%2Fbb-msg-history/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbb0ttle","download_url":"https://codeload.github.com/bbb0ttle/bb-msg-history/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbb0ttle%2Fbb-msg-history/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31389391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T04:26:24.776Z","status":"ssl_error","status_checked_at":"2026-04-04T04:23:34.147Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-04T05:45:37.083Z","updated_at":"2026-04-04T05:45:39.870Z","avatar_url":"https://github.com/bbb0ttle.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bb-msg-history\n\nChat-style message history web component. Render conversations from plain text, with avatars, bubbles, and smooth animations.\n\n## Install\n\n```bash\nnpm install @bbki.ng/bb-msg-history\n```\n\nCDN:\n\n```html\n\u003cscript type=\"module\" src=\"https://cdn.jsdelivr.net/npm/@bbki.ng/bb-msg-history@latest/dist/index.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\nPlace messages inside the element using the `author: text` format, one per line:\n\n```html\n\u003cbb-msg-history\u003e\n  alice: Hey, are you free this weekend?\n  bob: Sounds good! When?\n  alice: Saturday morning, around 10?\n  bob: Perfect. See you then!\n\u003c/bb-msg-history\u003e\n```\n\n## Message Format\n\nEach message is a line with the author name, a colon, and the message text:\n\n```\n\u003cauthor\u003e: \u003cmessage text\u003e\n```\n\nBlank lines and lines without a colon are ignored.\n\n## Author Avatars\n\nBy default, every author gets a **letter avatar** (first character of their name) and appears on the **left** side.\n\nUse the `setAuthor()` method to customize avatar, side, bubble color, and text color:\n\n```js\nconst el = document.querySelector('bb-msg-history');\n\n// Emoji avatar, right side\nel.setAuthor('me', { avatar: '🐱', side: 'right' });\n\n// Image avatar, custom bubble color\nel.setAuthor('bot', {\n  avatar: '\u003cimg src=\"bot.png\" width=\"28\" height=\"28\" /\u003e',\n  side: 'left',\n  bubbleColor: '#e0f2fe',\n});\n\n// SVG avatar\nel.setAuthor('alice', {\n  avatar: '\u003csvg viewBox=\"0 0 48 48\"\u003e...\u003c/svg\u003e',\n  side: 'left',\n});\n```\n\n### `setAuthor(name, options)`\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `avatar` | `string` | letter avatar | HTML string: emoji, `\u003cimg\u003e`, `\u003csvg\u003e`, or text |\n| `side` | `'left' \\| 'right'` | `'left'` | Which side the bubbles appear on |\n| `bubbleColor` | `string` | `'#f9fafb'` | Bubble background color |\n| `textColor` | `string` | `'#111827'` | Text color inside bubble |\n\nReturns `this` for chaining:\n\n```js\nel.setAuthor('me', { avatar: '🐱', side: 'right' })\n  .setAuthor('you', { avatar: '🐶', side: 'left' });\n```\n\nFuzzy matching: if an author name _contains_ a configured key (e.g. you configured `\"alice\"` and the message is from `\"alice(phone)\"`), the config is reused.\n\nUse `removeAuthor(name)` to remove a custom config.\n\n### `appendMessage(message)`\n\nAppend a message programmatically with smooth scroll to the new message.\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `message.author` | `string` | The author name |\n| `message.text` | `string` | The message text |\n\n```js\nel.appendMessage({ author: 'alice', text: 'Hello!' });\nel.appendMessage({ author: 'bob', text: 'How are you?' });\n```\n\nReturns `this` for chaining. This is ideal for chat applications where messages arrive in real-time.\n\n**Note:** Unlike modifying `textContent` directly, `appendMessage()` scrolls smoothly to the newly added message.\n\n### `setLoading(isLoading)`\n\nShow or hide a loading animation overlay. Useful when fetching messages from an API.\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `isLoading` | `boolean` | `true` to show loading, `false` to hide |\n\n```js\nconst el = document.querySelector('bb-msg-history');\n\n// Show loading\nel.setLoading(true);\n\n// Fetch messages\nfetchMessages().then(messages =\u003e {\n  // Hide loading and display messages\n  el.setLoading(false);\n});\n```\n\nYou can also use the HTML attribute:\n\n```html\n\u003cbb-msg-history loading\u003e\n  alice: Loading previous messages...\n\u003c/bb-msg-history\u003e\n```\n\n### `infinite` Attribute\n\nRemove the height constraint and disable scrolling on the component. The container expands to fit all messages.\n\nUse this when:\n- The parent container handles scrolling\n- You want to display an entire conversation without height limits\n- You need the component to be part of a larger scrollable area\n\n```html\n\u003cbb-msg-history infinite\u003e\n  alice: First message\n  bob: Second message\n  alice: Third message\n  \u003c!-- Container keeps expanding to fit all messages --\u003e\n\u003c/bb-msg-history\u003e\n```\n\nIn infinite mode:\n- No `max-height` constraint is applied\n- No scrollbar appears on the component\n- The scroll-to-bottom button is hidden (not needed)\n\n## Customization\n\n### CSS Custom Properties\n\n| Property | Default | Description |\n|----------|---------|-------------|\n| `--bb-max-height` | `600px` | Maximum height of the message container |\n\n```css\nbb-msg-history {\n  --bb-max-height: 400px;\n}\n```\n\n### Manual Registration\n\nBy default, the component auto-registers as `\u003cbb-msg-history\u003e`. You can also register manually with a custom tag name:\n\n```js\nimport { BBMsgHistory, define } from '@bbki.ng/bb-msg-history';\n\n// Register with default tag name\ndefine();\n\n// Or use a custom tag name\ndefine('my-chat-history');\n```\n\n## Features\n\n- Plain-text message format — no JSON or attributes needed\n- Left/right bubble layout based on author\n- Customizable avatars: emoji, `\u003cimg\u003e`, `\u003csvg\u003e`, or letter avatars\n- Hover tooltip showing the author name\n- Consecutive messages from the same author are grouped (avatar hidden)\n- Auto-scroll to the latest message on render\n- **`appendMessage()` API** — programmatically add messages with smooth scroll\n- **`setLoading()` API** — show loading animation while fetching messages\n- Long text word-wrap and overflow handling\n- Empty state when no messages are provided\n- Dark mode support via `prefers-color-scheme`\n- Mobile responsive layout\n- `prefers-reduced-motion` support\n- Reactive: automatically re-renders when content changes\n- Customizable max-height via `--bb-max-height` CSS custom property\n- **`infinite` attribute** — remove height constraints for parent-controlled scrolling\n- Graceful degradation to `\u003cpre\u003e` when Custom Elements are unsupported\n\n## Examples\n\n### Basic\n\n```html\n\u003cbb-msg-history\u003e\n  alice: Hey, are you free this weekend?\n  bob: Sounds good! When?\n  alice: Saturday morning, around 10?\n  bob: Perfect. See you then!\n\u003c/bb-msg-history\u003e\n```\n\n### Custom avatars\n\n```html\n\u003cbb-msg-history id=\"chat\"\u003e\n  me: Hey there!\n  friend: What's up?\n\u003c/bb-msg-history\u003e\n\n\u003cscript\u003e\n  const el = document.getElementById('chat');\n  el.setAuthor('me', { avatar: '🐱', side: 'right', bubbleColor: '#f3f4f6' });\n  el.setAuthor('friend', { avatar: '🐶', side: 'left', bubbleColor: '#e0f2fe' });\n\u003c/script\u003e\n```\n\n### Consecutive messages — avatar grouping\n\nWhen the same author sends multiple messages in a row, the avatar is only shown on the first one:\n\n```html\n\u003cbb-msg-history\u003e\n  alice: First message\n  alice: Second message, avatar hidden\n  alice: Third, still hidden\n  bob: Got it!\n  bob: I'll send two as well\n\u003c/bb-msg-history\u003e\n```\n\n### Unknown authors — letter avatars\n\nAuthors without custom config receive a letter avatar and appear on the left:\n\n```html\n\u003cbb-msg-history\u003e\n  alice: Hello!\n  bob: Hi there!\n  charlie: Hey everyone!\n\u003c/bb-msg-history\u003e\n```\n\n### Empty state\n\nWhen no messages are provided, a \"No messages\" placeholder is shown:\n\n```html\n\u003cbb-msg-history\u003e\u003c/bb-msg-history\u003e\n```\n\n### Dynamic message appending\n\nUse `appendMessage()` to add messages programmatically with smooth scrolling:\n\n```html\n\u003cbb-msg-history id=\"chat\" style=\"--bb-max-height: 300px;\"\u003e\n  alice: Hey there!\n\u003c/bb-msg-history\u003e\n\n\u003cscript\u003e\n  const el = document.getElementById('chat');\n  el.setAuthor('alice', { avatar: '👩', side: 'right' });\n  el.setAuthor('bob', { avatar: '👨', side: 'left' });\n\n  // Add messages dynamically with smooth scroll\n  el.appendMessage({ author: 'bob', text: 'Hello! How are you?' });\n  el.appendMessage({ author: 'alice', text: 'I\\'m doing great!' });\n  \n  // Simulate receiving a message after 2 seconds\n  setTimeout(() =\u003e {\n    el.appendMessage({ author: 'bob', text: 'Nice to hear that!' });\n  }, 2000);\n\u003c/script\u003e\n```\n\n### Loading state\n\nShow a loading animation while fetching messages from an API:\n\n```html\n\u003cbb-msg-history id=\"chat\" loading\u003e\n  \u003c!-- Messages will be loaded --\u003e\n\u003c/bb-msg-history\u003e\n\n\u003cscript\u003e\n  const el = document.getElementById('chat');\n\n  // Show loading (already set via HTML attribute above)\n  // el.setLoading(true);\n\n  // Fetch messages from API\n  fetch('/api/messages')\n    .then(res =\u003e res.json())\n    .then(messages =\u003e {\n      // Hide loading and populate messages\n      el.setLoading(false);\n      messages.forEach(msg =\u003e {\n        el.appendMessage({ author: msg.author, text: msg.text });\n      });\n    });\n\u003c/script\u003e\n```\n\n### Full page example\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003cscript type=\"module\" src=\"https://cdn.jsdelivr.net/npm/@bbki.ng/bb-msg-history@latest/dist/index.js\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cbb-msg-history id=\"chat\"\u003e\n    alice: Hey, are you free this weekend?\n    bob: Yeah, what's up?\n    alice: Want to grab coffee?\n    bob: Sounds good! Saturday morning?\n    alice: Perfect, see you then!\n  \u003c/bb-msg-history\u003e\n\n  \u003cscript\u003e\n    const el = document.getElementById('chat');\n    el.setAuthor('alice', { avatar: '👩', side: 'right' });\n    el.setAuthor('bob', { avatar: '👨', side: 'left', bubbleColor: '#ecfdf5' });\n  \u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nSee `example/` directory for a full demo.\n\n## Development\n\n```bash\nnpm install\nnpm run prepare\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbb0ttle%2Fbb-msg-history","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbb0ttle%2Fbb-msg-history","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbb0ttle%2Fbb-msg-history/lists"}