npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

hxy-ai-chat-lit

v1.2.7

Published

A mobile-first AI chat component built with Lit

Downloads

20

Readme

AI Chat Lit Component

A mobile-first AI chat component built with Lit, designed for modern web applications. This component provides a clean, responsive chat interface with support for both text and markdown messages.

Features

  • 🎨 Mobile-First Design - Optimized for mobile devices with responsive layout
  • 📝 Text & Markdown Support - Render both plain text and rich markdown content
  • 🌙 Theme Support - Light and dark themes
  • Event-Driven - Full event system for integration with your application
  • 📱 Touch-Friendly - Optimized for touch interactions
  • 🎯 TypeScript - Full TypeScript support with type definitions
  • 🚀 Framework Agnostic - Works with any framework or vanilla JavaScript

Installation

npm install hxy-ai-chat-lit

Usage

Basic Usage

<!DOCTYPE html>
<html>
<head>
    <script type="module">
        import { AiChat } from 'hxy-ai-chat-lit';
        customElements.define('ai-chat', AiChat);
    </script>
</head>
<body>
    <ai-chat></ai-chat>
</body>
</html>

React Integration

import React, { useRef, useEffect } from 'react';
import 'hxy-ai-chat-lit';

function ChatApp() {
  const chatRef = useRef(null);

  useEffect(() => {
    const chat = chatRef.current;
    
    // 设置初始消息
    chat.messages = [
      {
        id: '1',
        type: 'text',
        content: 'Hello! How can I help you?',
        timestamp: Date.now(),
        sender: 'assistant'
      }
    ];

    // 监听消息发送事件
    const handleMessageSent = (event) => {
      console.log('Message sent:', event.detail);
      // 处理用户发送的消息
    };

    chat.addEventListener('message-sent', handleMessageSent);

    return () => {
      chat.removeEventListener('message-sent', handleMessageSent);
    };
  }, []);

  return (
    <ai-chat
      ref={chatRef}
      theme="light"
      placeholder="Type your message here..."
      show-timestamp
      enable-markdown
    />
  );
}

Vue Integration

<template>
  <ai-chat
    ref="chatRef"
    :theme="theme"
    :placeholder="placeholder"
    :show-timestamp="showTimestamp"
    :enable-markdown="enableMarkdown"
  />
</template>

<script setup>
import { ref, onMounted } from 'vue';
import 'hxy-ai-chat-lit';

const chatRef = ref(null);
const theme = ref('light');
const placeholder = ref('Type your message here...');
const showTimestamp = ref(true);
const enableMarkdown = ref(true);

onMounted(() => {
  const chat = chatRef.value;
  
  // 设置初始消息
  chat.messages = [
    {
      id: '1',
      type: 'text',
      content: 'Hello! How can I help you?',
      timestamp: Date.now(),
      sender: 'assistant'
    }
  ];

  // 监听消息发送事件
  const handleMessageSent = (event) => {
    console.log('Message sent:', event.detail);
    // 处理用户发送的消息
  };

  chat.addEventListener('message-sent', handleMessageSent);
});
</script>

With Properties

<ai-chat
    theme="dark"
    placeholder="Type your message here..."
    show-timestamp
    enable-markdown
    max-height="500px"
></ai-chat>

JavaScript Integration

import { AiChat } from 'hxy-ai-chat-lit';

// Create component
const chat = new AiChat();

// Set properties
chat.messages = [
    {
        id: '1',
        type: 'text',
        content: 'Hello! How can I help you?',
        timestamp: Date.now(),
        sender: 'assistant'
    }
];

chat.theme = 'dark';
chat.loading = false;

// Listen for events
chat.addEventListener('message-sent', (event) => {
    console.log('Message sent:', event.detail);
    // Handle the message in your application
});

// Add to DOM
document.body.appendChild(chat);

Properties

| Property | Type | Default | Description | |----------|------|---------|-------------| | messages | Message[] | [] | Array of chat messages | | loading | boolean | false | Shows loading indicator | | placeholder | string | 'Type a message...' | Input placeholder text | | maxHeight | string | '400px' | Maximum height of chat container | | theme | 'light' \| 'dark' | 'light' | Visual theme | | showTimestamp | boolean | true | Show message timestamps | | enableMarkdown | boolean | true | Enable markdown rendering |

Message Format

interface Message {
    id: string;                    // Unique message identifier
    type: 'text' | 'markdown';     // Message content type
    content: string;               // Message content
    timestamp?: number;            // Unix timestamp
    sender?: 'user' | 'assistant'; // Message sender
    metadata?: Record<string, any>; // Additional metadata
}

Events

message-sent

Fired when a user sends a message.

chat.addEventListener('message-sent', (event) => {
    const { type, data, messageId } = event.detail;
    // Handle the sent message
});

Event detail:

{
    type: 'message';
    data: Message;
    messageId: string;
}

Styling

The component uses CSS custom properties for theming:

ai-chat {
    --primary-color: #007AFF;
    --background-color: #FFFFFF;
    --text-color: #000000;
    --border-color: #E5E5E7;
    --user-message-bg: #007AFF;
    --assistant-message-bg: #F2F2F7;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

Mobile Optimization

The component is designed with mobile-first principles:

  • Touch-friendly button sizes (44px minimum)
  • Optimized font sizes for readability
  • Responsive layout that adapts to screen size
  • Smooth scrolling with momentum
  • Prevents zoom on input focus (iOS)

Browser Support

  • Chrome 80+
  • Firefox 78+
  • Safari 13+
  • Edge 80+

Development

# Install dependencies
npm install

# Build the component
npm run build

# Watch for changes
npm run dev

License

MIT

Framework Integration

React

Vue

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.