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

open-likes

v1.0.1

Published

Open source web component for reactions with Supabase backend

Readme

Open Likes

A modern web component for content reactions. Perfect for blogs, articles, and any content that deserves some love! 💖

npm version Bundle Size License

✨ Features

  • 🎯 Zero dependencies - Self-contained web component
  • 🎨 Highly customizable - Icons, colors, positioning, and behavior
  • Lightweight - Only 8.4kB gzipped
  • 📱 Mobile-first - Works perfectly on touch devices
  • 🔥 Multitap support - Applause with debounced submissions
  • 💾 Smart persistence - Prevents duplicate reactions in single-tap mode
  • 🎭 Beautiful animations - Particle effects and smooth transitions
  • 🗄️ Supabase ready - Easy backend integration
  • 🧪 Well tested - 97+ unit tests with 100% core coverage

🚀 Quick Start

CDN (Recommended)

<script>
  // Configure your Supabase connection
  window.OPEN_LIKES_SUPABASE_URL = 'https://your-project.supabase.co';
  window.OPEN_LIKES_SUPABASE_ANON_KEY = 'your-anon-key';
</script>

<script
  type="module"
  src="https://unpkg.com/[email protected]/dist/open-likes.js"
></script>

<open-likes id="my-article"></open-likes>

📖 Usage

Basic Usage

<!-- Simple heart button -->
<open-likes id="article-1"></open-likes>

<!-- Custom icon and color -->
<open-likes id="article-2" icon="star" color="#ffd93d"></open-likes>

<!-- Single-tap mode with custom positioning -->
<open-likes
  id="article-3"
  icon="thumbs"
  counter="top"
  multitap="false"
></open-likes>

Configuration

Set up your Supabase connection:

window.OPEN_LIKES_SUPABASE_URL = 'https://your-project.supabase.co';
window.OPEN_LIKES_SUPABASE_ANON_KEY = 'your-anon-key';

// Optional: Set defaults for all components
window.OPEN_LIKES_DEFAULTS = {
  icon: 'heart',
  color: '#ff6b6b',
  counter: 'right',
  multitap: true,
};

Attributes

| Attribute | Type | Default | Description | | ---------- | -------------------------------------------------- | ---------------------- | --------------------------------- | | id | string | window.location.href | Unique identifier for the content | | icon | heart | thumbs | star | heart | Icon style | | color | string | currentColor | Color theme | | counter | left | right | top | bottom | hidden | right | Counter position | | multitap | boolean | true | Enable multiple reactions |

🎨 Customization Examples

Icons and Colors

<!-- Different icons -->
<open-likes icon="heart" color="#e91e63"></open-likes>
<open-likes icon="thumbs" color="#2196f3"></open-likes>
<open-likes icon="star" color="#ff9800"></open-likes>

Counter Positions

<!-- Counter positioning -->
<open-likes counter="top"></open-likes>
<open-likes counter="left"></open-likes>
<open-likes counter="bottom"></open-likes>
<open-likes counter="hidden"></open-likes>

🗄️ Backend Setup (Supabase)

Supabase is recommended for most scenarios because their free tier is quite generous and includes standard PostgreSQL syntax. This means your database schema and queries can be easily moved to another PostgreSQL service or even completely replaced with a different backend implementation if needed.

Quick Setup: All SQL files are included in this repository under /sql/ directory. Run them in order: 01-create-table.sql, 02-security-policies.sql, 03-functions.sql.

1. Create Database Table

-- Create the likes table
CREATE TABLE likes (
  id TEXT PRIMARY KEY,
  likes INTEGER NOT NULL DEFAULT 0,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
  updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Security: Block direct table access
ALTER TABLE likes ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Block all direct access" ON likes FOR ALL USING (false);

2. Create API Functions

-- Function to get likes count
CREATE OR REPLACE FUNCTION get_likes(content_id TEXT)
RETURNS INTEGER
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
  like_count INTEGER;
BEGIN
  SELECT likes INTO like_count FROM likes WHERE id = content_id;
  RETURN COALESCE(like_count, 0);
END;
$$;

-- Function to increment likes
CREATE OR REPLACE FUNCTION increment_likes(content_id TEXT, increment_by INTEGER DEFAULT 1)
RETURNS INTEGER
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
  final_count INTEGER;
BEGIN
  -- Limit increment to prevent abuse
  increment_by := LEAST(increment_by, 100);

  INSERT INTO likes (id, likes)
  VALUES (content_id, increment_by)
  ON CONFLICT (id)
  DO UPDATE SET
    likes = likes.likes + increment_by,
    updated_at = NOW()
  RETURNING likes INTO final_count;

  RETURN final_count;
END;
$$;

3. Configure Permissions

In your Supabase dashboard, ensure anonymous users can execute these functions but cannot access the table directly.

🎭 Advanced Features

Multitap Behavior

<!-- Medium-style applause: users can tap multiple times -->
<open-likes multitap="true"></open-likes>
  • Debounced submissions: Collects taps for 300ms before sending to server
  • Optimistic updates: UI responds immediately
  • Server reconciliation: Updates display with authoritative count after 3 seconds
  • Visual feedback: Particle animations and persistent filled state

Single-tap Mode

<!-- Traditional like button: one reaction per user -->
<open-likes multitap="false"></open-likes>
  • localStorage persistence: Remembers user reactions
  • Duplicate prevention: Blocks multiple reactions per content ID
  • Visual state: Icon stays filled after interaction

Particle Animations

Every tap triggers a beautiful burst of particles that emanate from the icon center, providing satisfying visual feedback.

🧪 Development

Local Development

git clone https://codeberg.org/asci/open-likes
cd open-likes
bun install
bun run dev

Testing

# Unit tests
bun run test

# Integration tests
bun run test:integration

# Build for production
bun run build

Project Structure

src/
├── component.ts     # Main web component
├── state.ts        # Business logic & state management
├── renderer.ts     # DOM rendering & UI updates
├── animation.ts    # Particle effects & animations
├── api.ts          # Supabase API client
├── storage.ts      # localStorage wrapper
├── utils.ts        # Utility functions
├── types.ts        # TypeScript interfaces
├── styles.ts       # CSS styles (inlined)
└── icons.ts        # SVG icons (inlined)

🤝 Contributing

We love contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch: git checkout -b amazing-feature
  3. Make your changes and add tests
  4. Run tests: bun run test
  5. Submit a pull request

📄 License

MIT © Artem R

🙏 Acknowledgments

  • Built with modern web standards
  • Powered by Supabase

Made with ❤️ for the web community

_Have a question or need help? Open an issue