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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vascent/react-waterfall-virtual-list

v0.1.2

Published

A React component for virtualized waterfall list

Readme

# VirtualWaterFall 虚拟瀑布流组件

一个高性能的虚拟化瀑布流布局组件,支持动态高度计算、滚动加载和自定义渲染,适用于图片/卡片类数据的高性能渲染场景。

## 特性
- 🚀 **虚拟滚动** - 仅渲染可视区域内的元素,超大数据量也能流畅运行
- 📐 **自适应布局** - 自动根据容器宽度计算列宽,响应式布局
- 🧮 **动态高度** - 支持同步/异步计算卡片高度
- ♾️ **无限滚动** - 滚动到底部自动触发数据加载
- 🎨 **高度定制** - 可自定义卡片样式、加载状态和渲染逻辑

## 安装
```bash
npm install @vascent/react-waterfall-virtual-list

快速开始

import { VirtualWaterFall } from '@vascent/react-waterfall-virtual-list'

const App = () => {
  const [data, setData] = useState<BaseInfo[]>([])

  // 加载更多数据
  const loadMore = useCallback(() => {
    fetchData().then(newData => setData(prev => [...prev, ...newData]))
  }, [])

  return (
    <VirtualWaterFall
      list={data}
      columns={4}
      gap={8}
      cardClass="custom-card"
      reachBottom={loadMore}
      calcCardHeight={async (width, imgHeight, item) => {
        // 自定义高度计算逻辑
        return await calculateDynamicHeight(item)
      }}
      renderItem={({ item }) => (
        <div style={item.style}>
          <img 
            src={item.imageUrl}
            height={item.style.imageHeight}
          />
          <h3>{item.title}</h3>
        </div>
      )}
      renderLoading={() => <div>Loading...</div>}
    />
  )
}

API 文档

Props

| 属性 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|-----| | list | T[] | 是 | - | 数据源数组,元素需继承 BaseInfo | | columns | number | 否 | 5 | 瀑布流列数 | | gap | number | 否 | 10 | 卡片间距(单位:px) | | scrollSpeedFactor | number | 否 | 0.3 | 滚动速度因子,影响滚动过程中的白屏,默认为 0.3,值越大滚动越快 | | cardClass | string | 否 | - | 卡片容器类名 | | reachBottom | () => void | 否 | - | 滚动到底部回调函数 | | calcCardHeight | (cardWidth: number, imageHeight: number, item: T) => Promise<number> | 否 | - | 异步计算卡片高度函数 | | renderItem | ({ item: T & { style: PositionType } }) => JSX.Element | 否 | - | 自定义卡片渲染函数 | | renderLoading | () => JSX.Element \| null | 否 | - | 自定义加载状态组件 |

类型定义

type BaseInfo = {
  id: string
  width: number   // 原始图片/卡片宽度
  height: number  // 原始图片/卡片高度
}

type PositionType = {
  x: number       // X轴位置
  y: number       // Y轴位置
  width: number   // 实际渲染宽度
  height: number  // 实际渲染高度
  imageHeight: number // 图片显示高度
}

注意事项

  1. 数据项要求:每个数据项必须包含 id, width, height 属性
  2. 图片预处理:建议预先获取图片原始尺寸,或在加载完成后触发重新布局
  3. 性能优化:大数据量时建议配合防抖使用 reachBottom
  4. 高度计算:当使用异步 calcCardHeight 时,请确保返回 Promise
  5. 滚动体验:容器需要具有明确的高度(通过外部 CSS 设置)

工作原理

  1. 布局计算:根据容器宽度和列数计算每列宽度
  2. 位置分配:始终将新元素添加到当前高度最小的列
  3. 滚动优化:自定义滚动处理实现平滑滚动体验

开发建议

// 推荐的数据结构示例
interface CardData extends BaseInfo {
  imageUrl: string
  title: string
  // 其他自定义字段...
}

// 推荐的高度计算模式
const calcHeight = async (width, imgHeight, item) => {
  const textHeight = await measureTextHeight(item.description, width)
  return imgHeight + textHeight + 20 // 总高度 = 图片高度 + 文字高度 + 边距
}

许可证

MIT