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

@dcg-overseas/equal-split

v2.0.6

Published

Equal split tool

Readme

@dcg-overseas/equal-split

等分图形(Equal Split)分数学习组件。只负责图形区域的渲染:将形状等分成 N 份并给指定分块着色。分数面板、英文读法等周边 UI 由使用方自行实现(可借助包导出的工具函数)。

安装

pnpm add @dcg-overseas/equal-split

使用

import {
  EqualSplit,
  useEqualSplit,
  getFractionWords,
} from '@dcg-overseas/equal-split'

export default function App() {
  const eq = useEqualSplit()

  return (
    <div>
      {/* 使用方自己实现选择器 / 分数面板 / 英文读法等 UI */}
      <EqualSplit
        shape={eq.shape}
        parts={eq.parts}
        coloredParts={eq.coloredParts}
        className="w-[420px] aspect-square"
      />
      <p>{getFractionWords(eq.coloredCount, eq.parts ?? 0)}</p>
    </div>
  )
}

EqualSplit Props

| Prop | 类型 | 说明 | |------|------|------| | shape | ShapeType \| null | 当前形状;null 时显示 "Select shape" 占位 | | parts | number \| null | 等分数;null 时只绘制形状轮廓 | | coloredParts | number[] | 着色分块的索引(从 0 开始) | | className | string? | 外层容器类名,尺寸由使用方控制(组件内 SVG 自适应填满容器) |

useEqualSplit

管理 形状 → 等分数 → 着色数 的三级级联状态(上游变化自动重置下游),返回:

| 字段 | 说明 | |------|------| | shape / parts / coloredParts | 当前状态,直接透传给 <EqualSplit /> | | coloredCount | 已着色块数(分子) | | setShape / setParts / setColoredCount | 状态 setter;setColoredCount(n) 着色前 n 块 | | shapeOptions | 形状选项列表 | | partsOptions | 当前形状支持的等分数选项 | | coloredOptions | 可选着色数(1 ~ parts) | | strokeColor | 当前形状的描边色 |

其他导出

| 名称 | 说明 | |------|------| | SHAPES | 形状列表 { id, label }[] | | SHAPE_PARTS | 各形状支持的等分数白名单 | | SHAPE_STROKES / SHAPE_COLORS | 各形状的描边/填充色 | | getFractionWords(num, den) | 分数英文读法(如 three fourthsone whole) | | useResponsiveScale(w, h?) | 固定设计稿等比缩放 hook,返回 { containerRef, scale } |

支持的等分数

| 形状 | 可选等分数 | |------|-----------| | Circle | 2, 3, 4, 5, 6, 8, 10 | | Triangle | 2, 3, 4, 6 | | Square | 2, 3, 4, 5, 6, 8, 9, 10 | | Rectangle | 2, 3, 4, 5, 6, 7, 8, 10, 12 | | Pentagon | 2, 5, 10 | | Hexagon | 2, 6, 12 |

文件结构

src/
├── constants.ts          # 类型、常量、分数英文转换函数
├── geometry.ts           # SVG 路径计算(各形状等分逻辑)
├── ShapeCanvas.tsx       # SVG 画布渲染
├── useEqualSplit.ts      # 级联状态 hook
├── useResponsiveScale.ts # 等比缩放 hook
└── EqualSplitIndex.tsx   # 主组件(纯展示)