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

perfect-corner-dash

v1.0.0

Published

Geometry-aware SVG dashed border generator with rounded-corner support.

Downloads

5

Readme

Perfect Corner Dash

English Version

Perfect Corner Dash 是一个基于几何计算的 SVG 虚线生成器,专门用于在圆角矩形等 UI 场景下绘制“完美对齐”的虚线边框。它既可以在浏览器里直接使用,也可以作为 npm 依赖集成到 React、Vue 或任意前端工程中。

功能特点

  • 按弧长精确分配虚线,圆角处自然衔接,不出现断裂或堆叠。
  • 纯函数 API,默认无副作用,适合 SSR 与客户端渲染。
  • 附带 render / attach 辅助方法,可直接插入或覆盖现有 DOM。
  • 支持自动尺寸、段落拆分(按边统一 dash 数量)以及首尾半段等高级配置。
  • 无额外依赖,可直接通过 CDN 或 npm 获取。

安装

npm / pnpm / yarn

npm install perfect-corner-dash
# 或者
pnpm add perfect-corner-dash
# 或者
yarn add perfect-corner-dash

安装后即可在任何打包工具(Vite、webpack、Next.js 等)里按需引用:

import PerfectDash from "perfect-corner-dash";

const svgMarkup = PerfectDash({
  width: 320,
  height: 200,
  borderRadius: 24,
  dashCount: 6,
});

document.querySelector("#preview").innerHTML = svgMarkup;

React / Vue 等框架同理,只需在组件中调用 PerfectDash 并渲染返回的字符串或节点。

如果希望直接覆盖现有元素,可以使用 attach

const card = document.querySelector(".card");

const handle = PerfectDash.attach(card, {
  borderRadius: 20,
  strokeWidth: 3,
  dashCount: 8,
  strokeColor: "#ff6b6b",
});

// 后续可更新或销毁
handle.update({ strokeColor: "#2563eb" });
handle.destroy();

封装为组件的示例

import { useEffect, useRef } from "react";
import PerfectDash from "perfect-corner-dash";

export function DashedCard({ children }) {
  const ref = useRef(null);

  useEffect(() => {
    if (!ref.current) return;
    const handle = PerfectDash.attach(ref.current, {
      borderRadius: 24,
      strokeWidth: 4,
      dashCount: 6,
      strokeColor: "#0ea5e9",
    });
    return () => handle.destroy();
  }, []);

  return (
    <div ref={ref} style={{ position: "relative", padding: "24px" }}>
      {children}
    </div>
  );
}

CDN 直接引入

<script src="https://unpkg.com/perfect-corner-dash@latest/dist/index.umd.js"></script>

<div id="preview"></div>
<script>
  const svg = PerfectDash({
    width: 280,
    height: 160,
    borderRadius: 18,
    strokeColor: "#2f3538",
  });
  document.getElementById("preview").innerHTML = svg;
</script>

UMD 版本会在全局对象上暴露 window.PerfectDashdist/index.min.js 提供压缩版本,适合通过 CDN 发布。

API 概览

type PerfectDashOptions = {
  width?: number | null;
  height?: number | null;
  borderRadius?: number;
  strokeWidth?: number;
  dashCount?: number;
  holeFactor?: number;
  offset?: number;
  splitSegments?: boolean;
  halfExtreme?: boolean;
  unifySegment?: boolean;
  strokeColor?: string;
  strokeLinecap?: "round" | "butt" | "square";
  strokeLinejoin?: "round" | "miter" | "bevel";
};

declare function PerfectDash(options?: PerfectDashOptions): string;

更多详细类型可在 types/index.d.ts 中查看。

辅助方法

  • PerfectDash.createSVGString(options):生成 SVG 字符串。
  • PerfectDash.createElement(options):返回 SVGSVGElement 元素。
  • PerfectDash.render(target, options):在目标容器中渲染 SVG。
  • PerfectDash.attach(target, options):将虚线覆盖层附着到目标元素,同时监听页面尺寸变化。

示例与构建

  • 运行 npm install 安装依赖。
  • npm run build 生成 dist/types/ 输出。
  • 示例位于 examples/ 目录,可直接使用静态服务器预览。

构建流程会输出 ESM(dist/index.js)、CJS(dist/index.cjs.js)、UMD(dist/index.umd.jsdist/index.min.js)以及类型声明 types/index.d.ts

许可证

MIT License。