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

vfit-react

v0.0.2

Published

React version of vfit - A simple dashboard adapter

Readme

vfit-react

vfit 的 React 版本 - 一个轻量级的大屏适配与定位解决方案。

特性

  • 全局缩放提供者:自动计算并根据窗口/容器大小提供全局缩放值。
  • 智能适配容器:自动定位并缩放子元素,支持固定像素和百分比定位。
  • 灵活模式:支持基于宽度、高度或自动检测的缩放模式。

安装

npm install vfit-react

使用方法

1. 配置 Provider

使用 FitScaleProvider 包裹你的应用。

// App.tsx
import React from 'react'
import { FitScaleProvider } from 'vfit-react'

const App = () => {
  return (
    <FitScaleProvider options={{ designHeight: 1080, designWidth: 1920, scaleMode: 'auto' }}>
      <MyDashboard />
    </FitScaleProvider>
  )
}

export default App

2. 使用 FitContainer

使用 FitContainer 来定位元素。它会自动应用全局缩放。

import React from 'react'
import { FitContainer } from 'vfit-react'

const MyDashboard = () => {
  return (
    <div style={{ position: 'relative', width: '100vw', height: '100vh', overflow: 'hidden' }}>
      {/* 百分比定位 - 保持居中 */}
      <FitContainer top={50} left={50} unit="%">
        <div style={{ transform: 'translate(-50%, -50%)', border: '1px solid red' }}>
          Centered Content
        </div>
      </FitContainer>

      {/* 像素定位 - 随屏幕缩放 */}
      <FitContainer top={100} left={100} unit="px">
        <div style={{ width: 200, height: 100, background: 'lightblue' }}>
          Scaled Box
        </div>
      </FitContainer>
    </div>
  )
}

3. useFitScale Hook

你也可以直接获取原始缩放值。

import React from 'react'
import { useFitScale } from 'vfit-react'

const ScaleDisplay = () => {
  const scale = useFitScale()
  return <div>Current Scale: {scale}</div>
}

API

FitScaleProvider 属性 (Props)

| 属性 | 类型 | 默认值 | 描述 | |------|------|---------|-------------| | options.target | string \| HTMLElement | document.body | 监听调整大小的容器 | | options.designHeight | number | 1080 | 设计稿高度 | | options.designWidth | number | 1920 | 设计稿宽度 | | options.scaleMode | 'height' \| 'width' \| 'auto' | 'auto' | 缩放模式 |

FitContainer 属性 (Props)

| 属性 | 类型 | 默认值 | 描述 | |------|------|---------|-------------| | top | number | - | 顶部距离 | | bottom | number | - | 底部距离 | | left | number | - | 左侧距离 | | right | number | - | 右侧距离 | | unit | 'px' \| '%' | 'px' | 定位单位 | | z | number | 300 | 层级 (z-index) | | scale | number | - | 覆盖全局缩放值 | | className | string | - | 自定义类名 | | style | CSSProperties | - | 自定义样式 |

License

MIT